diff --git a/.gitignore b/.gitignore index 6f46ba6e8..f2ca06a19 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ Thumbs.db # added build/hub electron/**/*.js +electron/**/*.js.map diff --git a/electron/assets/icons/ico-circled.svg b/electron/assets/icons/ico-circled.svg index 5e68c699f..e1d76d4b4 100644 --- a/electron/assets/icons/ico-circled.svg +++ b/electron/assets/icons/ico-circled.svg @@ -1,7 +1,10 @@ - - - - - + + + + + diff --git a/electron/assets/icons/ico-white.svg b/electron/assets/icons/ico-white.svg index 8a4306434..c77818313 100644 --- a/electron/assets/icons/ico-white.svg +++ b/electron/assets/icons/ico-white.svg @@ -2,62 +2,61 @@ - - - - - - image/svg+xml - - - - - - - - + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns="http://www.w3.org/2000/svg" + width="64" + height="64" + id="svg3360" + version="1.1" + inkscape:version="0.91 r13725" + viewBox="0 0 64 64" + sodipodi:docname="ico-white.svg"> + + + + + + image/svg+xml + + + + + + + + diff --git a/electron/assets/icons/ico.svg b/electron/assets/icons/ico.svg index c9c6509e2..b370aed79 100644 --- a/electron/assets/icons/ico.svg +++ b/electron/assets/icons/ico.svg @@ -2,62 +2,61 @@ - - - - - - image/svg+xml - - - - - - - - + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns="http://www.w3.org/2000/svg" + width="64" + height="64" + id="svg3360" + version="1.1" + inkscape:version="0.91 r13725" + viewBox="0 0 64 64" + sodipodi:docname="ico.svg"> + + + + + + image/svg+xml + + + + + + + + diff --git a/electron/dbus.ts b/electron/dbus.ts index 9fcee042b..999e96c84 100644 --- a/electron/dbus.ts +++ b/electron/dbus.ts @@ -42,7 +42,7 @@ function init(params) { // Return code 0x1 means we successfully had the name if (retCode === 1) { - console.log(`Successfully requested service name '${serviceName}'!`) + console.log(`Successfully requested service name '${serviceName}'!`); proceed(); } /* Other return codes means various errors, check here @@ -84,28 +84,28 @@ function init(params) { // Then we need to create the interface implementation (with actual functions) iface = { - markAsDone: function() { + markAsDone: function () { checkMainWin(); const mainWin = mainWinMod.getWin(); mainWin.webContents.send('TASK_MARK_AS_DONE'); }, - startTask: function() { + startTask: function () { checkMainWin(); const mainWin = mainWinMod.getWin(); mainWin.webContents.send('TASK_START'); }, - pauseTask: function() { + pauseTask: function () { checkMainWin(); const mainWin = mainWinMod.getWin(); mainWin.webContents.send('TASK_PAUSE'); }, - showApp: function() { + showApp: function () { params.showApp(); }, - quitApp: function() { + quitApp: function () { params.quitApp(); }, - emit: function() { + emit: function () { // no nothing, as usual } }; @@ -133,7 +133,7 @@ if (!isDBusError) { errorHandler('DBus: interface not ready yet'); isErrorShownOnce = true; } else { - iface.emit('taskChanged', taskId + '', taskText + '') + iface.emit('taskChanged', taskId + '', taskText + ''); } }, updatePomodoro: (isOnBreak, currentSessionTime, currentSessionInitialTime) => { @@ -143,7 +143,7 @@ if (!isDBusError) { } if (iface) { - iface.emit('pomodoroUpdate', (isOnBreak ? 1 : 0), currentSessionTime, currentSessionInitialTime) + iface.emit('pomodoroUpdate', (isOnBreak ? 1 : 0), currentSessionTime, currentSessionInitialTime); } else { errorHandler('DBus: interface not ready yet'); isErrorShownOnce = true; diff --git a/electron/debug.ts b/electron/debug.ts index 3e6a5dcc7..5b4fc2636 100644 --- a/electron/debug.ts +++ b/electron/debug.ts @@ -44,8 +44,7 @@ function inspectElements() { const win = BrowserWindow.getFocusedWindow(); const inspect = () => { // TODO check - // tslint:disable-next-line - win.devToolsWebContents.executeJavaScript('DevToolsAPI.enterInspectElementMode()'); + // win.devToolsWebContents.executeJavaScript('DevToolsAPI.enterInspectElementMode()'); }; if (win) { @@ -59,9 +58,9 @@ function inspectElements() { } const addExtensionIfInstalled = (name, getPath) => { - const isExtensionInstalled = name => { + const isExtensionInstalled = name_ => { return BrowserWindow.getDevToolsExtensions && - {}.hasOwnProperty.call(BrowserWindow.getDevToolsExtensions(), name); + {}.hasOwnProperty.call(BrowserWindow.getDevToolsExtensions(), name_); }; try { @@ -105,9 +104,6 @@ export const initDebug = (opts, isAddReload) => { }); app.on('ready', () => { - addExtensionIfInstalled('devtron', name => require(name).path); - addExtensionIfInstalled('electron-react-devtools', name => require(name).path); - localShortcut.register('CmdOrCtrl+Shift+C', inspectElements); localShortcut.register(isMacOS ? 'Cmd+Alt+I' : 'Ctrl+Shift+I', devTools); localShortcut.register('F12', devTools); diff --git a/electron/git-log.ts b/electron/git-log.ts index 426174127..eaea39895 100644 --- a/electron/git-log.ts +++ b/electron/git-log.ts @@ -1,6 +1,6 @@ import { getWin } from './main-window'; -export const getGitLog = function(data) { +export const getGitLog = function (data) { 'use strict'; const exec = require('child_process').exec; @@ -8,7 +8,7 @@ export const getGitLog = function(data) { exec(cmd, { cwd: data.cwd - }, function(error, stdout) { + }, function (error, stdout) { const mainWin = getWin(); mainWin.webContents.send('GIT_LOG_RESPONSE', { stdout: stdout, diff --git a/electron/google-auth.ts b/electron/google-auth.ts index 6449ab0eb..d13807d2d 100644 --- a/electron/google-auth.ts +++ b/electron/google-auth.ts @@ -45,9 +45,9 @@ async function authenticate(refreshToken) { }); // TODO check // tslint:disable-next-line - oauth2Client.refreshToken(refreshToken) - .then(resolve) - .catch(reject); + // oauth2Client.refreshToken(refreshToken) + // .then(resolve) + // .catch(reject); } else { const authorizeUrl = oauth2Client.generateAuthUrl({ access_type: 'offline', @@ -78,7 +78,7 @@ function openAuthWindow(url) { return new Promise((resolve, reject) => { /* tslint:disable-next-line */ - const win = new BrowserWindow(browserWindowParams || {'use-content-size': true}); + const win = new BrowserWindow(browserWindowParams || {useContentSize: true}); win.loadURL(url); diff --git a/electron/main-window.ts b/electron/main-window.ts index 7502a00ed..3f763cd28 100644 --- a/electron/main-window.ts +++ b/electron/main-window.ts @@ -3,6 +3,7 @@ import { errorHandler } from './error-handler'; import { join, normalize } from 'path'; import { format } from 'url'; import { getSettings } from './get-settings'; +import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions; let mainWin; let indicatorMod; @@ -44,17 +45,18 @@ export const createWindow = function (params) { mainWin.loadURL('http://localhost:4200'); } else { mainWin = new BrowserWindow({width: 800, height: 600}); - mainWin.loadURL(format({ + const url = format({ pathname: normalize(join(__dirname, '../dist/index.html')), protocol: 'file:', slashes: true, - }, { + }); + mainWin.loadURL(url, { show: false, webPreferences: { scrollBounce: true }, icon: ICONS_FOLDER + '/icon_256x256.png' - })); + }); // mainWin.webContents.openDevTools(); } // show gracefully @@ -90,51 +92,51 @@ function initWinEventListeners(app, IS_MAC, nestedWinParams) { }); mainWin.on('close', function (event) { - if (app.isQuiting) { - app.quit(); - } else { - event.preventDefault(); + // if (app.isQuiting) { + // app.quit(); + // } else { + event.preventDefault(); - getSettings(mainWin, (appCfg) => { - if (appCfg && appCfg.misc.isConfirmBeforeExit) { - const choice = require('electron').dialog.showMessageBox(mainWin, - { - type: 'question', - buttons: ['Yes', 'No'], - title: 'Confirm', - message: 'Are you sure you want to quit?' - }); - if (choice === 1) { - event.preventDefault(); - return; - } + getSettings(mainWin, (appCfg) => { + if (appCfg && appCfg.misc.isConfirmBeforeExit) { + const choice = require('electron').dialog.showMessageBox(mainWin, + { + type: 'question', + buttons: ['Yes', 'No'], + title: 'Confirm', + message: 'Are you sure you want to quit?' + }); + if (choice === 1) { + event.preventDefault(); + return; } + } - if (!appCfg || !appCfg.misc.isMinimizeToTrayOnExit) { - app.isQuiting = true; - app.quit(); - } else { - // handle darwin - if (IS_MAC) { - if (nestedWinParams.isDarwinForceQuit) { - app.isQuiting = true; - app.quit(); - } else { - event.preventDefault(); - mainWin.hide(); - } + if (!appCfg || !appCfg.misc.isMinimizeToTrayOnExit) { + // app.isQuiting = true; + app.quit(); + } else { + // handle darwin + if (IS_MAC) { + if (nestedWinParams.isDarwinForceQuit) { + // app.isQuiting = true; + app.quit(); } else { - if (indicatorMod.isRunning()) { - event.preventDefault(); - mainWin.hide(); - } else { - app.isQuiting = true; - app.quit(); - } + event.preventDefault(); + mainWin.hide(); } + } else { + // if (indicatorMod.isRunning()) { + // event.preventDefault(); + // mainWin.hide(); + // } else { + // app.isQuiting = true; + app.quit(); + // } } - }); - } + } + }); + // } }); } @@ -162,8 +164,9 @@ function createMenu(quitApp) { ] } ]; + const menuTpl_ = menuTpl as MenuItemConstructorOptions[]; // we need to set a menu to get copy & paste working for mac os x - Menu.setApplicationMenu(Menu.buildFromTemplate(menuTpl)); + Menu.setApplicationMenu(Menu.buildFromTemplate(menuTpl_)); } diff --git a/electron/main.js b/electron/main.js deleted file mode 100644 index 4073ff4f8..000000000 --- a/electron/main.js +++ /dev/null @@ -1,226 +0,0 @@ -'use strict'; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var electron = require('electron'); -var powerSaveBlocker = electron.powerSaveBlocker; -var notifier = require('node-notifier'); -//const autoUpdater = require('electron-updater').autoUpdater; -var log = require('electron-log'); -var electronLocalshortcut = require('electron-localshortcut'); -var CONFIG = require('./CONFIG'); -var indicatorMod = require('./indicator'); -var mainWinMod = require('./main-window'); -var getIdleTime = require('./get-idle-time'); -var jira = require('./jira'); -var gitLog = require('./git-log'); -var googleAuth = require('./google-auth'); -var errorHandler = require('./error-handler'); -var ICONS_FOLDER = __dirname + '/assets/icons/'; -var IS_MAC = process.platform === 'darwin'; -var IS_LINUX = process.platform === 'linux'; -var DESKTOP_ENV = process.env.DESKTOP_SESSION; -var IS_GNOME = (DESKTOP_ENV === 'gnome' || DESKTOP_ENV === 'gnome-xorg'); -var IS_DEV = process.env.NODE_ENV === 'DEV'; -if (IS_DEV) { - console.log('Starting in DEV Mode!!!'); -} -var app = electron.app; -require('./debug')({ showDevTools: IS_DEV }, IS_DEV); -var mainWin; -var nestedWinParams = { isDarwinForceQuit: false }; -// keep app active to keep time tracking running -powerSaveBlocker.start('prevent-app-suspension'); -// make it a single instance by closing other instances -app.requestSingleInstanceLock(); -app.on('second-instance', function () { - // the callback: only called only for first instance - // we want to show it, when the other starts to try another - if (mainWin) { - showApp(); - if (mainWin.isMinimized()) { - mainWin.restore(); - } - mainWin.focus(); - } -}); -//if (shouldQuitBecauseAppIsAnotherInstance) { -// quitAppNow(); -// return; -//} -// APP EVENT LISTENERS -// ------------------- -app.on('ready', createMainWin); -app.on('ready', createIndicator); -app.on('activate', function () { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWin === null) { - createMainWin(); - } - else { - showApp(); - } -}); -var idleInterval; -app.on('ready', function () { - // init time tracking interval - idleInterval = setInterval(idleChecker, CONFIG.IDLE_PING_INTERVAL); -}); -app.on('before-quit', function () { - // handle darwin - if (IS_MAC) { - nestedWinParams.isDarwinForceQuit = true; - } - // un-register all shortcuts. - electron.globalShortcut.unregisterAll(); -}); -// AUTO-UPDATER -// ------------ -//app.on('ready', () => { -// // init auto-updates -// log.info('INIT AUTO UPDATES'); -// // log.info(autoUpdater.getFeedURL()); -// autoUpdater.logger = log; -// autoUpdater.logger.transports.file.level = 'info'; -// autoUpdater.checkForUpdatesAndNotify(); -//}); -// -//autoUpdater.on('update-downloaded', (ev, info) => { -// console.log(ev); -// // Wait 5 seconds, then quit and install -// // In your application, you don't need to wait 5 seconds. -// // You could call autoUpdater.quitAndInstall(); immediately -// setTimeout(function() { -// autoUpdater.quitAndInstall(); -// }, 5000) -//}); -// FRONTEND EVENTS -// --------------- -electron.ipcMain.on('SHUTDOWN_NOW', quitAppNow); -electron.ipcMain.on('SHUTDOWN', quitApp); -electron.ipcMain.on('EXEC', exec); -electron.ipcMain.on('REGISTER_GLOBAL_SHORTCUT', function (ev, shortcutPassed) { - registerShowAppShortCut(shortcutPassed); -}); -electron.ipcMain.on('TOGGLE_DEV_TOOLS', function () { - mainWin.webContents.openDevTools(); -}); -electron.ipcMain.on('JIRA', function (ev, request) { - jira(request); -}); -electron.ipcMain.on('GIT_LOG', function (ev, cwd) { - gitLog(cwd, mainWin); -}); -electron.ipcMain.on('NOTIFY', function (ev, notification) { - notifier.notify(__assign({}, notification, { message: notification.body })); -}); -electron.ipcMain.on('SHOW_OR_FOCUS', function () { - showOrFocus(mainWin); -}); -// HELPER FUNCTIONS -// ---------------- -function createIndicator() { - indicatorMod.init({ - app: app, - showApp: showApp, - quitApp: quitApp, - IS_MAC: IS_MAC, - IS_LINUX: IS_LINUX, - IS_GNOME: IS_GNOME, - ICONS_FOLDER: ICONS_FOLDER, - }); -} -function createMainWin() { - mainWin = mainWinMod.createWindow({ - app: app, - IS_DEV: IS_DEV, - ICONS_FOLDER: ICONS_FOLDER, - IS_MAC: IS_MAC, - quitApp: quitApp, - nestedWinParams: nestedWinParams, - indicatorMod: indicatorMod, - }); - googleAuth.init(); -} -function registerShowAppShortCut(shortcutPassed) { - if (shortcutPassed) { - // unregister all previous - electron.globalShortcut.unregisterAll(); - // Register a shortcut listener. - var ret = electron.globalShortcut.register(shortcutPassed, function () { - if (mainWin.isFocused()) { - mainWin.hide(); - } - else { - showOrFocus(mainWin); - } - }); - if (!ret) { - errorHandler('Key registration failed: ' + shortcutPassed, shortcutPassed); - } - } -} -function showApp() { - showOrFocus(mainWin); -} -function quitApp() { - mainWin.webContents.send('ON_BEFORE_QUIT'); -} -function quitAppNow() { - app.isQuiting = true; - app.quit(); -} -function showOrFocus(passedWin) { - // default to main win - var win = passedWin || mainWin; - // sometimes when starting a second instance we get here although we don't want to - if (!win) { - log.info('special case occurred when showOrFocus is called even though, this is a second instance of the app'); - return; - } - if (win.isVisible()) { - win.focus(); - } - else { - win.show(); - } - // focus window afterwards always - setTimeout(function () { - win.focus(); - }, 60); -} -function idleChecker() { - getIdleTime(function (idleTime) { - if (idleTime === 'NO_SUPPORT' && idleInterval) { - clearInterval(idleInterval); - } - // sometimes when starting a second instance we get here although we don't want to - if (!mainWin) { - log.info('special case occurred when trackTimeFn is called even though, this is a second instance of the app'); - return; - } - // don't update if the user is about to close - if (!app.isQuiting) { - mainWin.webContents.send('IDLE_TIME', idleTime); - } - }); -} -function exec(ev, command) { - console.log('running command ' + command); - var exec = require('child_process').exec; - exec(command, function (error) { - if (error) { - errorHandler(error); - } - }); -} -//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/electron/main.ts b/electron/main.ts index 3e7f16631..af1cfa355 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -180,10 +180,13 @@ function registerShowAppShortCut(shortcutPassed) { showOrFocus(mainWin); } }); + console.log(ret); - if (!ret) { - errorHandler('Key registration failed: ' + shortcutPassed, shortcutPassed); - } + // TODO make this work again + // tslint:disable-next-line + // if (!ret) { + // errorHandler('Key registration failed: ' + shortcutPassed, shortcutPassed); + // } } } @@ -196,7 +199,8 @@ function quitApp() { } function quitAppNow() { - app.isQuiting = true; + // tslint:disable-next-line + // app.isQuiting = true; app.quit(); } @@ -235,9 +239,10 @@ function idleChecker() { } // don't update if the user is about to close - if (!app.isQuiting) { - mainWin.webContents.send('IDLE_TIME', idleTime); - } + // tslint:disable-next-line + // if (!app.isQuiting) { + // mainWin.webContents.send('IDLE_TIME', idleTime); + // } }); } diff --git a/package.json b/package.json index 4fa6b1e42..065fbf7e3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ ], "scripts": { "ng": "ng", - "start": "NODE_ENV=DEV ./node_modules/.bin/electron ./electron/main.js", + "start": "NODE_ENV=DEV npm run electron:serve", "startFrontend": "ng serve", "buildFrontend": "ng build", "buildFrontendElectron": "ng build --base-href .",