Skip to content

Commit

Permalink
Remember Electron window state
Browse files Browse the repository at this point in the history
  • Loading branch information
6c65726f79 committed Jun 13, 2021
1 parent 5e9367c commit d14db26
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 11 deletions.
69 changes: 62 additions & 7 deletions electron/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion electron/package.json
Expand Up @@ -16,8 +16,10 @@
},
"dependencies": {
"@capacitor-community/electron": "1.4.2",
"@electron/remote": "^1.1.0",
"custom-electron-titlebar": "^3.2.7",
"electron-updater": "^4.3.9"
"electron-updater": "^4.3.9",
"electron-window-state": "^5.0.3"
},
"devDependencies": {
"electron": "~13.1.2",
Expand Down
13 changes: 11 additions & 2 deletions electron/src/index.ts
@@ -1,7 +1,9 @@
import { app, shell } from "electron";
import fs from "fs";
import { createCapacitorElectronApp } from "@capacitor-community/electron";
import { autoUpdater } from "electron-updater"
import { autoUpdater } from "electron-updater";
import windowStateKeeper from "electron-window-state";
require('@electron/remote/main').initialize();

// The MainWindow object can be accessed via myCapacitorApp.getMainWindow()
const myCapacitorApp = createCapacitorElectronApp({
Expand Down Expand Up @@ -48,9 +50,16 @@ if (!gotTheLock) {
// initialization and is ready to create browser windows.
// Some Electron APIs can only be used after this event occurs.
app.on("ready", () => {
let mainWindowState = windowStateKeeper({
defaultWidth: 990,
defaultHeight: 700
});
myCapacitorApp.init();
autoUpdater.checkForUpdatesAndNotify();
const mainWindow = myCapacitorApp.getMainWindow();
mainWindow.setPosition(mainWindowState.x,mainWindowState.y);
mainWindow.setSize(mainWindowState.width,mainWindowState.height);
autoUpdater.checkForUpdatesAndNotify();
mainWindowState.manage(mainWindow);
if (mainWindow && openFiles.length>0) {
mainWindow.webContents.on('did-finish-load', function() {
mainWindow.webContents.send('file-open', openFiles)
Expand Down
2 changes: 1 addition & 1 deletion electron/user-preload-script.js
@@ -1,5 +1,5 @@
const { contextBridge,ipcRenderer,shell } = require('electron');
const { app, net, Menu, MenuItem } = require('electron').remote
const { app, net, Menu, MenuItem } = require('@electron/remote');
const { Titlebar, Color } = require('custom-electron-titlebar');
const path = require('path');
let titleBar;
Expand Down

0 comments on commit d14db26

Please sign in to comment.