From 89be729aecdfb357c67613ea30cc1a5d34d4d267 Mon Sep 17 00:00:00 2001 From: anteldan <34574269+anteldan@users.noreply.github.com> Date: Mon, 18 Dec 2017 00:15:15 +0100 Subject: [PATCH 1/3] config.js, index.js Introducing a new "View" menu and its checkbox item "Show card short id". All trello cards have a "short id" in a span element, which is hidden. CSS class is ".card-short-id hide". Checking/unchecking "Show card short id" will page.insertCSS a new class ".card-short-id.hide" definition "display: inline-flex; padding-right: .3em;" or "display: none;" Checkbox state is saved in config. I never developped with electron, so sorry if page.insertCSS is not the right way and please enhance the code ! --- config.js | 1 + index.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 69a5115..d2f7370 100644 --- a/config.js +++ b/config.js @@ -8,5 +8,6 @@ module.exports = new Config({ width: 800, height: 600 } + , showCardShortId: false } }); diff --git a/index.js b/index.js index ba0fbf0..2d22bb1 100644 --- a/index.js +++ b/index.js @@ -12,14 +12,24 @@ require('electron-context-menu')(); let mainWindow; let isQuitting = false; +let showCardShortId = config.get('showCardShortId'); + +function toggleShowCardShortId(page) { + if (!showCardShortId) + page.insertCSS('.card-short-id.hide { display:none; }'); + else + page.insertCSS('.card-short-id.hide { display: inline-flex; padding-right: .3em; }'); +} function createMainWindow() { const lastWindowState = config.get('lastWindowState'); + const lastShowCardShortId = config.get('showCardShortId'); const win = new electron.BrowserWindow({ title: app.getName(), show: false, x: lastWindowState.x, y: lastWindowState.y, + showCardShortId: lastShowCardShortId, width: lastWindowState.width, height: lastWindowState.height, icon: process.platform === 'linux' && path.join(__dirname, 'static', 'Icon.png'), @@ -39,12 +49,13 @@ function createMainWindow() { } win.loadURL('https://trello.com/'); - + win.on('close', e => { if (isQuitting) { if (!mainWindow.isFullScreen()) { config.set('lastWindowState', mainWindow.getBounds()); } + config.set('showCardShortId', mainWindow.showCardShortId); } else { e.preventDefault(); @@ -65,6 +76,7 @@ app.on('ready', () => { page.on('dom-ready', () => { page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); + toggleShowCardShortId(page); mainWindow.show(); }); @@ -111,9 +123,23 @@ app.on('ready', () => { {label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:'}, {label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:'} ] + } , { + label: 'View', + submenu: [ + {label: 'Show card short id', + type: 'checkbox', + checked: showCardShortId, + click: item => { + showCardShortId = !showCardShortId; + item.checked = showCardShortId; + config.set('showCardShortId', showCardShortId); + toggleShowCardShortId(page); + } + } + ] } ]; - + electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate(template)); }); @@ -122,9 +148,10 @@ app.on('window-all-closed', () => { }); app.on('activate', () => { - mainWindow.show(); + mainWindow.show(); }); app.on('before-quit', () => { isQuitting = true; }); + From 2a2d56bdb7ed479fb44c7f81bbd7a5563011ccfb Mon Sep 17 00:00:00 2001 From: anteldan <34574269+anteldan@users.noreply.github.com> Date: Mon, 18 Dec 2017 23:30:59 +0100 Subject: [PATCH 2/3] Cleaned trailing spaces --- index.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 2d22bb1..f9bb45a 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,11 @@ let isQuitting = false; let showCardShortId = config.get('showCardShortId'); function toggleShowCardShortId(page) { - if (!showCardShortId) - page.insertCSS('.card-short-id.hide { display:none; }'); - else + if (showCardShortId) { page.insertCSS('.card-short-id.hide { display: inline-flex; padding-right: .3em; }'); + } else { + page.insertCSS('.card-short-id.hide { display:none; }'); + } } function createMainWindow() { @@ -49,7 +50,7 @@ function createMainWindow() { } win.loadURL('https://trello.com/'); - + win.on('close', e => { if (isQuitting) { if (!mainWindow.isFullScreen()) { @@ -123,23 +124,23 @@ app.on('ready', () => { {label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:'}, {label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:'} ] - } , { + }, { label: 'View', submenu: [ {label: 'Show card short id', type: 'checkbox', checked: showCardShortId, click: item => { - showCardShortId = !showCardShortId; - item.checked = showCardShortId; - config.set('showCardShortId', showCardShortId); - toggleShowCardShortId(page); + showCardShortId = !showCardShortId; + item.checked = showCardShortId; + config.set('showCardShortId', showCardShortId); + toggleShowCardShortId(page); } } ] } ]; - + electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate(template)); }); @@ -148,7 +149,7 @@ app.on('window-all-closed', () => { }); app.on('activate', () => { - mainWindow.show(); + mainWindow.show(); }); app.on('before-quit', () => { From 0557c11f26032b62a57016e2cee49d1e1ea1a4a4 Mon Sep 17 00:00:00 2001 From: anteldan <34574269+anteldan@users.noreply.github.com> Date: Mon, 18 Dec 2017 23:39:08 +0100 Subject: [PATCH 3/3] comma last --- config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index d2f7370..5067b9c 100644 --- a/config.js +++ b/config.js @@ -7,7 +7,7 @@ module.exports = new Config({ lastWindowState: { width: 800, height: 600 - } - , showCardShortId: false + }, + showCardShortId: false } });