From e1a1d2911a25a7b69314710b2a29ff0e0ded744e Mon Sep 17 00:00:00 2001 From: sidneys Date: Thu, 16 Nov 2017 10:07:35 +0100 Subject: [PATCH] v4.0.4 --- .appveyor.yml | 1 - RELEASENOTES.json | 9 ++ app/scripts/main/components/application.js | 14 +-- app/scripts/main/components/menubar.js | 4 +- .../main/managers/configuration-manager.js | 22 ++++- app/scripts/main/managers/overlay-manager.js | 2 + app/scripts/main/menus/tray-menu.js | 4 +- app/scripts/main/services/updater-service.js | 85 +++++++++++++------ .../main/windows/overlay-configuration.js | 10 +++ app/scripts/main/windows/overlay-window.js | 2 + app/scripts/renderer/preferences.js | 6 +- package-lock.json | 2 +- package.json | 2 +- 13 files changed, 115 insertions(+), 48 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 5f7c30e..d4ef774 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -38,7 +38,6 @@ deploy_script: artifacts: - path: build\output\*.exe - - path: build\output\*.yml notifications: - provider: Webhook diff --git a/RELEASENOTES.json b/RELEASENOTES.json index 97f97d0..5dbeec0 100644 --- a/RELEASENOTES.json +++ b/RELEASENOTES.json @@ -1,4 +1,13 @@ { + "4.0.4": { + "🍾 features": [ + "Adds preference: application auto updates (#26)" + ], + "👷 internals": [ + "Upgrades `node_modules`", + "Upgrades `services`" + ] + }, "4.0.3": { "🍾 features": [ "Per-display enabling and disabling of Desktop Dimmer", diff --git a/app/scripts/main/components/application.js b/app/scripts/main/components/application.js index 9220009..d6cafff 100755 --- a/app/scripts/main/components/application.js +++ b/app/scripts/main/components/application.js @@ -6,7 +6,7 @@ * Node * @constant */ -const EventEmitter = require('events'); +const events = require('events'); const path = require('path'); /** @@ -17,21 +17,12 @@ const path = require('path'); const appRootPath = require('app-root-path'); const platformTools = require('@sidneys/platform-tools'); -/** - * Modules - * Electron - * @constant - */ -/* eslint-disable no-unused-vars */ -const menubar = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'components', 'menubar')); -/* eslint-enable */ - /** * Modules * Configuration */ -EventEmitter.defaultMaxListeners = Infinity; appRootPath['setPath'](path.join(__dirname, '..', '..', '..', '..')); +events.EventEmitter.defaultMaxListeners = Infinity; if (platformTools.isLinux) { process.env.XDG_CURRENT_DESKTOP = 'Unity'; } @@ -43,6 +34,7 @@ if (platformTools.isLinux) { */ /* eslint-disable no-unused-vars */ const globals = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'components', 'globals')); +const menubar = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'components', 'menubar')); const updaterService = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'services', 'updater-service')); const debugService = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'services', 'debug-service')); const configurationManager = require(path.join(appRootPath['path'], 'app', 'scripts', 'main', 'managers', 'configuration-manager')); diff --git a/app/scripts/main/components/menubar.js b/app/scripts/main/components/menubar.js index bed3056..77068ef 100644 --- a/app/scripts/main/components/menubar.js +++ b/app/scripts/main/components/menubar.js @@ -76,9 +76,11 @@ let handleThemeChange = (browserWindow) => { */ class Menubar { /** - * @constructs + * @constructor */ constructor() { + logger.debug('constructor'); + this.menubar = electronMenubar({ alwaysOnTop: isDebug, backgroundColor: platformTools.isMacOS ? void 0 : '#404040', diff --git a/app/scripts/main/managers/configuration-manager.js b/app/scripts/main/managers/configuration-manager.js index 2c966b8..31e965b 100644 --- a/app/scripts/main/managers/configuration-manager.js +++ b/app/scripts/main/managers/configuration-manager.js @@ -63,6 +63,26 @@ electronSettings.setPath(appSettingsFilepath); * Configuration Items */ let configurationItems = { + /** + * appAutoUpdate + */ + appAutoUpdate: { + keypath: 'appAutoUpdate', + default: true, + init() { + logger.debug(this.keypath, 'init'); + }, + get() { + logger.debug(this.keypath, 'get'); + + return electronSettings.get(this.keypath); + }, + set(value) { + logger.debug(this.keypath, 'set'); + + electronSettings.set(this.keypath, value); + } + }, /** * appChangelog */ @@ -137,7 +157,6 @@ let configurationItems = { }, /** * appLogFile - * @type {String} */ appLogFile: { keypath: 'appLogFile', @@ -158,7 +177,6 @@ let configurationItems = { }, /** * overlayConfigurationDatabase - * @type {OverlayConfiguration[]} */ overlayConfigurationDatabase: { keypath: 'overlayConfigurationDatabase', diff --git a/app/scripts/main/managers/overlay-manager.js b/app/scripts/main/managers/overlay-manager.js index a399c3b..2d7813b 100755 --- a/app/scripts/main/managers/overlay-manager.js +++ b/app/scripts/main/managers/overlay-manager.js @@ -73,6 +73,8 @@ class OverlayManager extends events.EventEmitter { * @constructor */ constructor() { + logger.debug('constructor'); + super(); this.init(); } diff --git a/app/scripts/main/menus/tray-menu.js b/app/scripts/main/menus/tray-menu.js index 2c2f00b..8ee8658 100755 --- a/app/scripts/main/menus/tray-menu.js +++ b/app/scripts/main/menus/tray-menu.js @@ -99,9 +99,11 @@ let createTrayMenuTemplate = () => { class TrayMenu { /** * @param {Electron.MenuItemConstructorOptions[]} template - Menu template - * @constructs + * @constructor */ constructor(template) { + logger.debug('constructor'); + this.template = template; this.tray = getTray(); this.menu = Menu.buildFromTemplate(this.template); diff --git a/app/scripts/main/services/updater-service.js b/app/scripts/main/services/updater-service.js index 33c2384..38d025e 100644 --- a/app/scripts/main/services/updater-service.js +++ b/app/scripts/main/services/updater-service.js @@ -15,13 +15,7 @@ const path = require('path'); * @constant */ const electron = require('electron'); -const { BrowserWindow } = electron || electron.remote; - -/** - * Modules - * Configuration - */ -const app = global.menubar.menubar.app; +const { app, BrowserWindow } = electron; /** * Modules @@ -41,7 +35,7 @@ const { autoUpdater } = require('electron-updater'); * @constant */ const dialogProvider = require(path.join(appRootPath, 'app', 'scripts', 'main', 'providers', 'dialog-provider')); -// const notificationProvider = require(path.join(appRootPath, 'app', 'scripts', 'main', 'providers', 'notification-provider')); +//const notificationProvider = require(path.join(appRootPath, 'app', 'scripts', 'main', 'providers', 'notification-provider')); const configurationManager = require(path.join(appRootPath, 'app', 'scripts', 'main', 'managers', 'configuration-manager')); /** @@ -61,26 +55,32 @@ let getMainWindow = () => global.mainWindow; /** - * Retrieve AppChangelog + * Retrieve appAutoUpdate + * @return {Boolean} - Yes / no + */ +let retrieveAppAutoUpdate = () => configurationManager('appAutoUpdate').get(); + +/** + * Retrieve appChangelog * @return {String} - changelog */ let retrieveAppChangelog = () => configurationManager('appChangelog').get(); /** - * Store AppChangelog + * Store appChangelog * @param {String} changelog - Changelog * @return {void} */ let storeAppChangelog = (changelog) => configurationManager('appChangelog').set(changelog); /** - * Retrieve AppLastVersion + * Retrieve appLastVersion * @return {String} - Version */ let retrieveAppLastVersion = () => configurationManager('appLastVersion').get(); /** - * Store AppLastVersion + * Store appLastVersion * @param {String} version - Version * @return {void} */ @@ -94,9 +94,11 @@ let storeAppLastVersion = (version) => configurationManager('appLastVersion').se */ class UpdaterService { /** - * @constructs + * @constructor */ constructor() { + logger.debug('constructor'); + // Do not run with debug Electron application if (process.defaultApp) { return; } @@ -156,8 +158,8 @@ class UpdaterService { this.isUpdating = true; - // const notification = notificationProvider.create({ title: `Update available for ${appProductName}`, subtitle: info.version }); - // notification.show(); + //const notification = notificationProvider.create({ title: `Update available for ${appProductName}`, subtitle: info.version }); + //notification.show(); }); /** @@ -196,8 +198,8 @@ class UpdaterService { this.isUpdating = true; - // const notification = notificationProvider.create({ title: `Update ready to install for ${appProductName}`, subtitle: info.version }); - // notification.show(); + //const notification = notificationProvider.create({ title: `Update ready to install for ${appProductName}`, subtitle: info.version }); + //notification.show(); if (!!info.releaseNotes) { const releaseNotesPlaintext = removeMarkdown(info.releaseNotes); @@ -222,7 +224,7 @@ class UpdaterService { }); }); - this.autoUpdater.checkForUpdates(); + this.checkForUpdates(); } /** @@ -256,10 +258,43 @@ class UpdaterService { dialogProvider.info(`${appProductName} has been updated to ${appCurrentVersion}`, `Update completed successfully.`); } - // const notification = notificationProvider.create({ title: `Update installed for ${appProductName}`, subtitle: appCurrentVersion }); - // notification.show(); + //const notification = notificationProvider.create({ title: `Update installed for ${appProductName}`, subtitle: appCurrentVersion }); + //notification.show(); } + } + /** + * Check if updater is ready + * @return {Boolean} - Yes / no + */ + isAvailable() { + logger.debug('isAvailable'); + + return Boolean(this.autoUpdater); + } + + /** + * Check if currently updating + * @return {Boolean} - Yes / no + */ + isActive() { + logger.debug('isActive'); + + return Boolean(this.isUpdating); + } + + /** + * Check for updates + */ + checkForUpdates() { + logger.debug('checkForUpdates'); + + if (!this.isAvailable()) { return; } + if (this.isActive()) { return; } + + if (!retrieveAppAutoUpdate()) { return; } + + this.autoUpdater.checkForUpdates(); } } @@ -283,15 +318,9 @@ let init = () => { app.on('browser-window-focus', () => { logger.debug('app#browser-window-focus'); - if (!global.updaterService) { init(); } + if (!global.updaterService) { return; } - if (!global.updaterService.autoUpdater) { return; } - - if (Boolean(global.updaterService.isUpdating) === false) { - if (global.updaterService.autoUpdater.checkForUpdates) { - global.updaterService.autoUpdater.checkForUpdates(); - } - } + global.updaterService.checkForUpdates(); }); /** diff --git a/app/scripts/main/windows/overlay-configuration.js b/app/scripts/main/windows/overlay-configuration.js index fbd3aae..ee7d981 100755 --- a/app/scripts/main/windows/overlay-configuration.js +++ b/app/scripts/main/windows/overlay-configuration.js @@ -1,6 +1,14 @@ 'use strict'; +/** + * Modules + * External + * @constant + */ +const logger = require('@sidneys/logger')({ write: true }); + + /** * @typedef {String} OverlayAlpha - Floating-point alpha value * @example '0.23' @@ -53,6 +61,8 @@ class OverlayConfiguration { * @constructor */ constructor(alpha = defaultAlpha, color = defaultColor, visibility = defaultVisibility) { + logger.debug('constructor'); + this.alpha = alpha; this.color = color; this.visibility = visibility; diff --git a/app/scripts/main/windows/overlay-window.js b/app/scripts/main/windows/overlay-window.js index 7713052..c4a55cc 100755 --- a/app/scripts/main/windows/overlay-window.js +++ b/app/scripts/main/windows/overlay-window.js @@ -97,6 +97,8 @@ class OverlayWindow extends BrowserWindow { * @constructor */ constructor(display) { + logger.debug('constructor'); + super({ enableLargerThanScreen: true, frame: false, diff --git a/app/scripts/renderer/preferences.js b/app/scripts/renderer/preferences.js index 419c308..dcf7576 100755 --- a/app/scripts/renderer/preferences.js +++ b/app/scripts/renderer/preferences.js @@ -31,7 +31,6 @@ const logger = require('@sidneys/logger')({ write: true }); * @constant */ const configurationManager = remote.require(path.join(appRootPath, 'app', 'scripts', 'main', 'managers', 'configuration-manager')); -const globals = remote.require(path.join(appRootPath, 'app', 'scripts', 'main', 'components', 'globals')); /** @@ -63,7 +62,10 @@ let setVersion = (version) => versionTextElement.innerText = version.trim(); let renderPreferences = () => { logger.debug('registerPreferences'); - let preferenceKeyList = [ 'appLaunchOnStartup' ]; + let preferenceKeyList = [ + 'appAutoUpdate', + 'appLaunchOnStartup' + ]; preferenceKeyList.forEach((keyName) => { const preferenceInputElement = document.createElement('input'); diff --git a/package-lock.json b/package-lock.json index a5982c0..292c0c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "desktop-dimmer", - "version": "4.0.3", + "version": "4.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 782b0ec..7aef02c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "desktop-dimmer", "productName": "Desktop Dimmer", - "version": "4.0.3", + "version": "4.0.4", "description": "Enables darker-than-dark Desktop dimming for your displays", "license": "MIT", "homepage": "https://sidneys.github.io/desktop-dimmer",