Skip to content

Commit

Permalink
update all electron dependencies. Electron 8.
Browse files Browse the repository at this point in the history
Add electron logger back. There was issue when passing sequalize object to log.
  • Loading branch information
MayGo committed Feb 7, 2020
1 parent b1ab1c7 commit 2c7def0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 58 deletions.
4 changes: 1 addition & 3 deletions electron/app/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down
6 changes: 3 additions & 3 deletions electron/app/jobs/status-track-item-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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),
);
Expand Down
2 changes: 1 addition & 1 deletion electron/app/log-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class LogManager {
}

getLogger(name) {
return console;
return electronLog.create(name);
}
}

Expand Down
6 changes: 3 additions & 3 deletions electron/app/services/app-setting-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down
27 changes: 12 additions & 15 deletions electron/app/services/settings-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
}
Expand All @@ -58,25 +60,20 @@ 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 [];
}
return item.jsonData;
}

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() {
Expand Down
26 changes: 4 additions & 22 deletions electron/app/services/track-item-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,8 @@ export class TrackItemService {
return trackItem;
}

async updateTrackItemByName(
name: string,
trackItemAttributes: any,
): Promise<[number, Array<TrackItem>]> {
// 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,
Expand All @@ -46,7 +28,7 @@ export class TrackItemService {
where: { id: id },
},
);
return item;
return items;
}

findAllItems(from, to, taskName, searchStr, paging) {
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "GPL-2.0",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 2c7def0

Please sign in to comment.