From 806006316db59b30ca6ef83deb4bb1795a59a926 Mon Sep 17 00:00:00 2001 From: Yuri Vecchi Date: Sun, 18 Jun 2017 14:57:25 -0300 Subject: [PATCH] Fixing initial login screen and window size on exit; fix #14 #23 #25 --- index.js | 201 +++++++++++++++++++++++++++------------------------ package.json | 6 +- 2 files changed, 108 insertions(+), 99 deletions(-) diff --git a/index.js b/index.js index 73758d8..60f3b53 100644 --- a/index.js +++ b/index.js @@ -14,113 +14,122 @@ let mainWindow; let isQuitting = false; function createMainWindow() { - const lastWindowState = config.get('lastWindowState'); - const win = new electron.BrowserWindow({ - title: app.getName(), - show: false, - x: lastWindowState.x, - y: lastWindowState.y, - width: lastWindowState.width, - height: lastWindowState.height, - icon: process.platform === 'linux' && path.join(__dirname, 'static', 'Icon.png'), - minWidth: 400, - minHeight: 200, - titleBarStyle: 'hidden-inset', - autoHideMenuBar: true, - webPreferences: { - nodeIntegration: false, - preload: path.join(__dirname, 'browser.js'), - plugins: true - } - }); - - if (process.platform === 'darwin') { - win.setSheetOffset(40); - } - - win.loadURL('https://trello.com/login'); - win.on('close', e => { - if (!isQuitting) { - e.preventDefault(); - - if (process.platform === 'darwin') { - app.hide(); - } else { - app.quit(); - } - } - }); - - return win; + const lastWindowState = config.get('lastWindowState'); + const win = new electron.BrowserWindow({ + title: app.getName(), + show: false, + x: lastWindowState.x, + y: lastWindowState.y, + width: lastWindowState.width, + height: lastWindowState.height, + icon: process.platform === 'linux' && path.join(__dirname, 'static', 'Icon.png'), + minWidth: 400, + minHeight: 200, + titleBarStyle: 'hidden-inset', + autoHideMenuBar: true, + webPreferences: { + nodeIntegration: false, + preload: path.join(__dirname, 'browser.js'), + plugins: true + } + }); + + if (process.platform === 'darwin') { + win.setSheetOffset(40); + } + + win.loadURL('https://trello.com/'); + + win.on('close', e => { + if (!isQuitting) { + e.preventDefault(); + + if (process.platform === 'darwin') { + app.hide(); + } else { + app.quit(); + } + } else { + if (!mainWindow.isFullScreen()) { + config.set('lastWindowState', mainWindow.getBounds()); + } + } + + }); + + return win; } app.on('ready', () => { - mainWindow = createMainWindow(); - const page = mainWindow.webContents; - - page.on('dom-ready', () => { - page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); - mainWindow.show(); - }); - - page.on('new-window', (e, url) => { - e.preventDefault(); - electron.shell.openExternal(url); - }); - - mainWindow.webContents.session.on('will-download', (event, item) => { - const totalBytes = item.getTotalBytes(); - - item.on('updated', () => { - mainWindow.setProgressBar(item.getReceivedBytes() / totalBytes); - }); - - item.on('done', (e, state) => { - mainWindow.setProgressBar(-1); - - if (state === 'interrupted') { - electron.Dialog.showErrorBox('Download error', 'The download was interrupted'); - } - }); - }); - - const template = [{ - label: 'Application', - submenu: [ - {label: 'About Application', selector: 'orderFrontStandardAboutPanel:'}, - {type: 'separator'}, - {label: 'Quit', accelerator: 'Command+Q', click: () => { - app.quit(); - }} - ]}, { - label: 'Edit', - submenu: [ - {label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:'}, - {label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:'}, - {type: 'separator'}, - {label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:'}, - {label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:'}, - {label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:'}, - {label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:'} - ] - } - ]; - - electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate(template)); + mainWindow = createMainWindow(); + const page = mainWindow.webContents; + + page.on('dom-ready', () => { + page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); + mainWindow.show(); + }); + + page.on('new-window', (e, url) => { + e.preventDefault(); + electron.shell.openExternal(url); + }); + + mainWindow.webContents.session.on('will-download', (event, item) => { + const totalBytes = item.getTotalBytes(); + + item.on('updated', () => { + mainWindow.setProgressBar(item.getReceivedBytes() / totalBytes); + }); + + item.on('done', (e, state) => { + mainWindow.setProgressBar(-1); + + if (state === 'interrupted') { + electron.Dialog.showErrorBox('Download error', 'The download was interrupted'); + } + }); + }); + + const template = [{ + label: 'Application', + submenu: [ + {label: 'About Application', selector: 'orderFrontStandardAboutPanel:'}, + {type: 'separator'}, + { + label: 'Quit', accelerator: 'Command+Q', click: () => { + app.quit(); + } + } + ] + }, { + label: 'Edit', + submenu: [ + {label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:'}, + {label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:'}, + {type: 'separator'}, + {label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:'}, + {label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:'}, + {label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:'}, + {label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:'} + ] + } + ]; + + electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate(template)); }); app.on('window-all-closed', () => { - app.quit(); + app.quit(); }); app.on('activate', () => { - mainWindow.show(); + mainWindow.show(); }); app.on('before-quit', () => { - isQuitting = true; + isQuitting = true; - if (!mainWindow.isFullScreen()) { - config.set('lastWindowState', mainWindow.getBounds()); - } + if (!mainWindow.isFullScreen()) { + config.set('lastWindowState', mainWindow.getBounds()); + } }); diff --git a/package.json b/package.json index 4012652..54cbbb5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "trello-desktop", "productName": "Trello", "desktopName": "Trello", - "version": "0.1.2", + "version": "0.1.3", "description": "Unofficial Trello desktop app", "license": "MIT", "repository": "danielchatfield/trello-desktop", @@ -42,8 +42,8 @@ "electron-dl": "^1.0.0" }, "devDependencies": { - "electron-packager": "^7.0.4", - "electron-prebuilt": "^1.2.3", + "electron-packager": "^8.7.1", + "electron": "^1.7.3", "xo": "*" }, "xo": {