Skip to content

Commit

Permalink
update to Electron 10; updated libraries; removal of "electron-window…
Browse files Browse the repository at this point in the history
…-state"
  • Loading branch information
4ch1m committed Aug 31, 2020
1 parent b116b7c commit 47a0db5
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 80 deletions.
63 changes: 53 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,71 @@
const {app, BrowserWindow, nativeImage} = require('electron');
const windowStateKeeper = require('electron-window-state');
const store = new (require('electron-store'))();

let mainWindow;

function createWindow() {
let mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 768
function windowStateKeeper(windowName) {
let window;

// default values
let windowState = {
x: undefined,
y: undefined,
width: 1024,
height: 768
};

function setBounds() {
if (store.has(`windowState.${windowName}`)) {
windowState = store.get(`windowState.${windowName}`);
}
}

function saveState() {
if (!windowState.isMaximized) {
windowState = window.getBounds();
}
windowState.isMaximized = window.isMaximized();

store.set(`windowState.${windowName}`, windowState);
}

function track(win) {
window = win;

['resize', 'move', 'close'].forEach(event => {
win.on(event, saveState);
});
}

setBounds();

return ({
x: windowState.x,
y: windowState.y,
width: windowState.width,
height: windowState.height,
isMaximized: windowState.isMaximized,
track
});
}

function createWindow() {
const mainWindowStateKeeper = windowStateKeeper('main');

mainWindow = new BrowserWindow({
icon: nativeImage.createFromPath(__dirname + '/spritemate/dist/img/favicon/android-chrome-256x256.png'),
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height
x: mainWindowStateKeeper.x,
y: mainWindowStateKeeper.y,
width: mainWindowStateKeeper.width,
height: mainWindowStateKeeper.height
});
mainWindow.loadFile('spritemate/dist/index.html');
mainWindow.setMenu(null);
mainWindow.on('closed', function () {
mainWindow = null
});

mainWindowState.manage(mainWindow);
mainWindowStateKeeper.track(mainWindow);
}

app.on('ready', createWindow);
Expand Down
Loading

0 comments on commit 47a0db5

Please sign in to comment.