From 2c7def054093462325c54ac42fdb07d7f8bc4c3e Mon Sep 17 00:00:00 2001 From: d Date: Sat, 8 Feb 2020 00:46:59 +0200 Subject: [PATCH] update all electron dependencies. Electron 8. Add electron logger back. There was issue when passing sequalize object to log. --- electron/app/Database.ts | 4 +-- electron/app/jobs/status-track-item-job.ts | 6 ++--- electron/app/log-manager.ts | 2 +- electron/app/services/app-setting-service.ts | 6 ++--- electron/app/services/settings-service.ts | 27 +++++++++----------- electron/app/services/track-item-service.ts | 26 +++---------------- electron/package.json | 22 ++++++++-------- 7 files changed, 35 insertions(+), 58 deletions(-) diff --git a/electron/app/Database.ts b/electron/app/Database.ts index 16ac2ae9..454ffbf2 100755 --- a/electron/app/Database.ts +++ b/electron/app/Database.ts @@ -26,9 +26,7 @@ class Database { }); this._sequelize.addModels([AppSetting, Settings, TrackItem]); - logger.info('Models AppSetting', AppSetting); - logger.info('Models Settings', Settings); - logger.info('Models TrackItem', TrackItem); + logger.debug('Added Models AppSetting, Settings, TrackItem'); } } diff --git a/electron/app/jobs/status-track-item-job.ts b/electron/app/jobs/status-track-item-job.ts index d47dfca0..fecd84b4 100755 --- a/electron/app/jobs/status-track-item-job.ts +++ b/electron/app/jobs/status-track-item-job.ts @@ -9,7 +9,7 @@ import { execFile } from 'child_process'; import { State } from '../enums/state'; import { appConstants } from '../app-constants'; import { sendToTrayWindow } from '../window-manager'; -let logger = logManager.getLogger('LogTrackItemJob'); +let logger = logManager.getLogger('StatusTrackItemJob'); export class StatusTrackItemJob { run() { @@ -40,13 +40,13 @@ export class StatusTrackItemJob { // logger.debug('Script saveUserIdleTime file: ' + script) let handleSuccess = stdout => { - // logger.debug('Idle time: ' + stdout); + // logger.debug('Idle time: ' + stdout); let seconds = stdout; this.saveIdleTrackItem(seconds).then( () => { - //logger.debug(`Idle saved ${seconds}` + // logger.debug(`Idle saved ${seconds}`); }, e => logger.error('Idle error', e), ); diff --git a/electron/app/log-manager.ts b/electron/app/log-manager.ts index 0e5e05c1..cbc04fac 100755 --- a/electron/app/log-manager.ts +++ b/electron/app/log-manager.ts @@ -11,7 +11,7 @@ export class LogManager { } getLogger(name) { - return console; + return electronLog.create(name); } } diff --git a/electron/app/services/app-setting-service.ts b/electron/app/services/app-setting-service.ts index 5e5750d5..374e6f8f 100755 --- a/electron/app/services/app-setting-service.ts +++ b/electron/app/services/app-setting-service.ts @@ -42,7 +42,7 @@ export class AppSettingService { } else { let color = randomcolor(); let item = await this.createAppSetting({ name: appName, color: color }); - this.logger.info('Created color item to DB:', item); + this.logger.debug('Created color item to DB:', item.toJSON()); return color; } @@ -56,12 +56,12 @@ export class AppSettingService { if (appSetting) { appSetting.color = color; appSetting.save(); - this.logger.info('Saved color item to DB:', appSetting); + this.logger.debug('Saved color item to DB:', appSetting.toJSON()); return appSetting; } else { const item = await this.createAppSetting({ name: appName, color: color }); - this.logger.info('Created color item to DB:', item); + this.logger.debug('Created color item to DB:', item.toJSON()); return item; } } diff --git a/electron/app/services/settings-service.ts b/electron/app/services/settings-service.ts index 83663380..71636463 100755 --- a/electron/app/services/settings-service.ts +++ b/electron/app/services/settings-service.ts @@ -9,26 +9,28 @@ export class SettingsService { async findByName(name: string) { if (this.cache[name]) { + // this.logger.debug(`Returning ${name} from cache:`, this.cache[name]); return this.cache[name]; } - let items = await Settings.findCreateFind({ + const [item] = await Settings.findCreateFind({ where: { name: name, }, }); - let item = items[0]; + + this.logger.debug(`Setting ${name} to cache:`, item.toJSON()); this.cache[name] = item; return item; } - updateByName(name: string, jsonDataStr: any) { + async updateByName(name: string, jsonDataStr: any) { this.logger.info('Updating Setting:', name, jsonDataStr); try { const jsonData = JSON.parse(jsonDataStr); - const item = Settings.update( + const [count, items] = await Settings.update( { jsonData }, { where: { @@ -37,7 +39,7 @@ export class SettingsService { }, ); - this.cache[name] = item; + this.cache[name] = items[0]; } catch (e) { this.logger.error('Parsing jsonData failed:', e, jsonDataStr); } @@ -58,9 +60,10 @@ export class SettingsService { } async fetchAnalyserSettings() { + // this.logger.debug('Fetching ANALYSER_SETTINGS:'); let item = await this.findByName('ANALYSER_SETTINGS'); - this.logger.info(item.jsonData); - if (!item || this.isObject(item.jsonData)) { + // this.logger.debug('Fetched ANALYSER_SETTINGS:', item.toJSON()); + if (!item || !Array.isArray(item.jsonData)) { // db default is object but this is initialized with array (when is initialized) return []; } @@ -68,15 +71,9 @@ export class SettingsService { } async fetchAnalyserSettingsJsonString() { - this.logger.debug('Fetching ANALYSER_SETTINGS:'); - let item = await this.findByName('ANALYSER_SETTINGS'); - this.logger.debug('Fetched ANALYSER_SETTINGS:', item); - if (!item || !Array.isArray(item.jsonData)) { - // db default is object but this is initialized with array (when is initialized) - return JSON.stringify([]); - } + const data = await this.fetchAnalyserSettings(); - return JSON.stringify(item.jsonData); + return JSON.stringify(data); } async getRunningLogItemAsJson() { diff --git a/electron/app/services/track-item-service.ts b/electron/app/services/track-item-service.ts index 90ce9ed2..10c0ff85 100755 --- a/electron/app/services/track-item-service.ts +++ b/electron/app/services/track-item-service.ts @@ -14,26 +14,8 @@ export class TrackItemService { return trackItem; } - async updateTrackItemByName( - name: string, - trackItemAttributes: any, - ): Promise<[number, Array]> { - // TODO: not used - let results = await TrackItem.update(trackItemAttributes, { - where: { name: name }, - }); - - if (results.length > 0) { - this.logger.info(`Updated trackItem with name ${name}.`); - } else { - this.logger.info(`TrackItem with name ${name} does not exist.`); - } - - return results; - } - - async updateTrackItem(itemData: TrackItem, id: number): Promise<[number, TrackItem[]]> { - let item = await TrackItem.update( + async updateTrackItem(itemData: TrackItem, id: number) { + let [count, items] = await TrackItem.update( { app: itemData.app, title: itemData.title, @@ -46,7 +28,7 @@ export class TrackItemService { where: { id: id }, }, ); - return item; + return items; } findAllItems(from, to, taskName, searchStr, paging) { @@ -194,7 +176,7 @@ export class TrackItemService { return null; } - // this.logger.debug('Found RUNNING_LOG_ITEM config: ', item.toJSON()); + this.logger.debug('Found RUNNING_LOG_ITEM config: ', item.toJSON()); let logTrackItemId = item.jsonData.id; if (!logTrackItemId) { diff --git a/electron/package.json b/electron/package.json index 3031ba2e..e6d41ace 100644 --- a/electron/package.json +++ b/electron/package.json @@ -1,6 +1,6 @@ { "name": "tockler", - "version": "3.6.6", + "version": "3.8.0", "description": "Automatically track applications usage and working time", "author": "Maigo Erit ", "license": "GPL-2.0", @@ -30,12 +30,12 @@ "sqlite3": "4.1.1", "hazardous": "^0.3.0", "eiphop": "^1.0.12", - "electron-context-menu": "0.15.2", + "electron-context-menu": "0.16.0", "electron-devtools-installer": "^2.2.4", "electron-store": "5.1.0", "electron-updater": "4.2.0", "electron-is-dev": "^1.1.0", - "electron-log": "^4.0.4", + "electron-log": "^4.0.6", "lodash": "^4.17.15", "menubar": "7.2.0", "moment": "2.24.0", @@ -46,27 +46,27 @@ "peerDependencies": {}, "devDependencies": { "@babel/register": "^7.8.3", - "@types/jest": "^24.9.1", + "@types/jest": "^25.1.2", "@types/lodash": "^4.14.149", - "@types/node": "^13.5.0", + "@types/node": "^13.7.0", "@types/sequelize": "^4.28.8", "@types/webdriverio": "^5.0.0", - "@types/webpack": "^4.41.3", + "@types/webpack": "^4.41.5", "awesome-typescript-loader": "5.2.1", "copy-webpack-plugin": "5.1.1", "cpx": "^1.5.0", - "cross-env": "^6.0.3", + "cross-env": "^7.0.0", "cucumber": "^6.0.5", "cucumber-pretty": "^6.0.0", - "electron": "7.1.10", - "electron-builder": "22.2.0", + "electron": "8.0.0", + "electron-builder": "22.3.2", "electron-connect": "0.6.3", "electron-reload": "1.5.0", "friendly-errors-webpack-plugin": "^1.7.0", "jest": "25.1.0", "jest-cli": "25.1.0", - "spectron": "^9.0.0", - "ts-jest": "^25.0.0", + "spectron": "^10.0.1", + "ts-jest": "^25.2.0", "tslint": "^6.0.0", "typescript": "^3.7.5", "webpack": "^4.41.5",