From 93db28f0ec6571ba86570f27d34c0766e456d432 Mon Sep 17 00:00:00 2001 From: alex-skakun Date: Wed, 17 Apr 2019 13:38:05 +0300 Subject: [PATCH 1/4] [AMSA-35] remove extra character in logging of sync params --- src/core/sync-apps/sync.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/sync-apps/sync.ts b/src/core/sync-apps/sync.ts index ff06cf5..976c269 100644 --- a/src/core/sync-apps/sync.ts +++ b/src/core/sync-apps/sync.ts @@ -134,8 +134,11 @@ export class Sync { this.emit(SyncEventsTypes.Started); this.logger.info(`Sync Params uuid: ${this.id} - AppodealAccount: '${this.appodealAccountId}}' - AdmobAccount: '${this.adMobAccount.id}}': '${this.adMobAccount.email}}' + AppodealAccount: + id: ${this.appodealAccountId} + AdmobAccount: + id: ${this.adMobAccount.id} + email: ${this.adMobAccount.email} `); await this.appodealApi.reportSyncStart(this.id, this.adMobAccount.id); try { From 421d8db9c91eaba194ab3b4f50b82f219437b14a Mon Sep 17 00:00:00 2001 From: alex-skakun Date: Wed, 17 Apr 2019 13:41:31 +0300 Subject: [PATCH 2/4] [AMSA-36] Frequent auto signout from appodeal account --- src/core/appdeal-api/appodeal-api.factory.ts | 19 +++++++++++++++---- src/core/appdeal-api/appodeal-api.service.ts | 8 ++++---- src/core/appdeal-api/auth-context.ts | 8 +++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/core/appdeal-api/appodeal-api.factory.ts b/src/core/appdeal-api/appodeal-api.factory.ts index 1c2db37..453c472 100644 --- a/src/core/appdeal-api/appodeal-api.factory.ts +++ b/src/core/appdeal-api/appodeal-api.factory.ts @@ -47,8 +47,11 @@ export class AppodealApi { throw err; }); if (account) { + this.destroyApi(account.id); this.saveApi(api, account); sessionInfo.save(account.id); + } else { + api.destroy(); } return account; } @@ -63,10 +66,7 @@ export class AppodealApi { error.isHandled = true; } }); - api.destroy(); - this.APIs.delete(accountId); - this.errorSubscriptions.get(accountId).unsubscribe(); - this.errorSubscriptions.delete(accountId); + this.destroyApi(accountId); await AppodealSessions.remove(accountId); } @@ -81,6 +81,17 @@ export class AppodealApi { )); } + private destroyApi (accountId: string) { + if (this.APIs.has(accountId)) { + this.APIs.get(accountId).destroy(); + this.APIs.delete(accountId); + } + if (this.errorSubscriptions.has(accountId)) { + this.errorSubscriptions.get(accountId).unsubscribe(); + this.errorSubscriptions.delete(accountId); + } + } + private saveApi (api: AppodealApiService, account: UserAccount) { api.init(account.id); this.APIs.set(account.id, api); diff --git a/src/core/appdeal-api/appodeal-api.service.ts b/src/core/appdeal-api/appodeal-api.service.ts index f708c09..7f6db0a 100644 --- a/src/core/appdeal-api/appodeal-api.service.ts +++ b/src/core/appdeal-api/appodeal-api.service.ts @@ -6,7 +6,7 @@ import {ErrorResponse, onError} from 'apollo-link-error'; import {AuthContext, TokensInfo} from 'core/appdeal-api/auth-context'; import {AppodealAccount} from 'core/appdeal-api/interfaces/appodeal.account.interface'; import {AuthorizationError} from 'core/error-factory/errors/authorization.error'; -import {session, Session} from 'electron'; +import {Session} from 'electron'; import {ExtractedAdmobAccount} from 'interfaces/common.interfaces'; import {createFetcher, Fetcher} from 'lib/fetch'; import {AdMobApp} from 'lib/translators/interfaces/admob-app.interface'; @@ -15,9 +15,9 @@ import {ErrorFactoryService} from '../error-factory/error-factory.service'; import {InternalError} from '../error-factory/errors/internal-error'; import addAdMobAccountMutation from './graphql/add-admob-account.mutation.graphql'; import adMobAccountQuery from './graphql/admob-account-details.graphql'; -import minimalAppVersionQuery from './graphql/minimal-app-version.query.graphql'; import currentUserQuery from './graphql/current-user.query.graphql'; import endSync from './graphql/end-sync.mutation.graphql'; +import minimalAppVersionQuery from './graphql/minimal-app-version.query.graphql'; import pingQuery from './graphql/ping.query.graphql'; import refreshTokenMutation from './graphql/refresh-token-mutation.graphql'; @@ -133,7 +133,7 @@ export class AppodealApiService { } destroy () { - this.authContext.removeAllListeners(); + this.authContext.destroy(); } handleError (e: InternalError) { @@ -197,7 +197,7 @@ export class AppodealApiService { fetchCurrentUser (): Promise { return this.query<{ currentUser: AppodealAccount }>({ - query: currentUserQuery, + query: currentUserQuery }) .then(result => { return result.currentUser; diff --git a/src/core/appdeal-api/auth-context.ts b/src/core/appdeal-api/auth-context.ts index 40ab184..d666508 100644 --- a/src/core/appdeal-api/auth-context.ts +++ b/src/core/appdeal-api/auth-context.ts @@ -39,6 +39,7 @@ export class AuthContext extends EventEmitter { private accessToken: string = null; private refreshToken: string = null; private accountId: string = null; + private refreshInterval = null; init (accountId: string) { this.setAccountId(accountId); @@ -50,7 +51,7 @@ export class AuthContext extends EventEmitter { console.log(`NO auth tokens for ${accountId}`); } // check should we update refresh token each 1 minute - setInterval(() => this.emitRefresh(), 60000); + this.refreshInterval = setInterval(() => this.emitRefresh(), 60000); this.emitRefresh(); } @@ -110,4 +111,9 @@ export class AuthContext extends EventEmitter { }; }); } + + destroy () { + clearInterval(this.refreshInterval); + this.removeAllListeners(); + } } From b3412bd3a032eea5f757bdfc4639db628e2891ab Mon Sep 17 00:00:00 2001 From: alex-skakun Date: Wed, 17 Apr 2019 13:42:21 +0300 Subject: [PATCH 3/4] [AMSA-37] Display app windows in dock on macOS --- src/lib/app-menu.ts | 3 ++- src/lib/ui-windows.ts | 29 +++++++++++++++++++++++++---- src/lib/window.ts | 31 ------------------------------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/lib/app-menu.ts b/src/lib/app-menu.ts index 06e1195..4ca9e4a 100644 --- a/src/lib/app-menu.ts +++ b/src/lib/app-menu.ts @@ -1,4 +1,5 @@ import {Menu} from 'electron'; +import {showAboutDialog} from 'lib/about'; import {isMacOS} from 'lib/platform'; @@ -17,7 +18,7 @@ class AppMenu { { label: 'Application', submenu: [ - {label: 'About Application', role: 'about:'}, + {label: 'About Application', click: () => showAboutDialog()}, {type: 'separator'}, {label: 'Quit', accelerator: 'Command+Q', role: 'quit'} ] diff --git a/src/lib/ui-windows.ts b/src/lib/ui-windows.ts index 7c89c2f..8972be0 100644 --- a/src/lib/ui-windows.ts +++ b/src/lib/ui-windows.ts @@ -1,5 +1,5 @@ import {AppodealAccount} from 'core/appdeal-api/interfaces/appodeal.account.interface'; -import {BrowserWindow} from 'electron'; +import {app, BrowserWindow} from 'electron'; import {AppodealAccountState} from 'interfaces/common.interfaces'; import {getMapItem} from 'lib/core'; import {openDialogWindow, openWindow} from 'lib/window'; @@ -10,8 +10,13 @@ const OPENED_WINDOWS = new Map>() export async function openSettingsWindow () { return openOrFocus('settings', async () => { let window = await openWindow('./settings.html', { - fullscreenable: false - }, () => window.removeAllListeners()); + fullscreenable: false, + skipTaskbar: false + }, () => { + app.dock.hide(); + window.removeAllListeners(); + }); + app.dock.show(); window.on('focus', async event => { let topWindow = getMapItem(OPENED_WINDOWS, OPENED_WINDOWS.size - 1); if (topWindow) { @@ -36,6 +41,13 @@ export function openAppodealSignInWindow (account: AppodealAccountState = null): './sign-in.html', {width: 450, height: 270, parent: await OPENED_WINDOWS.get('settings')}, window => { + let parent = window.getParentWindow(); + app.dock.show(); + window.once('closed', () => { + if (!parent) { + app.dock.hide(); + } + }); window.webContents.send('existingAccount', JSON.stringify(account)); res(window); } @@ -50,7 +62,16 @@ export function openAppodealAccountsWindow (): Promise { openDialogWindow( './manage-accounts.html', {width: 450, height: 350, parent: await OPENED_WINDOWS.get('settings')}, - res + window => { + let parent = window.getParentWindow(); + app.dock.show(); + window.once('closed', () => { + if (!parent) { + app.dock.hide(); + } + }); + res(window); + } ).then(resolve, reject); })); }); diff --git a/src/lib/window.ts b/src/lib/window.ts index aceb9d9..4f1753a 100644 --- a/src/lib/window.ts +++ b/src/lib/window.ts @@ -69,8 +69,6 @@ export function openDialogWindow ( height, minWidth: width, minHeight: height, - // maxWidth: width, - // maxHeight: height, resizable: false, frame: true, fullscreenable: false, @@ -96,35 +94,6 @@ export function openDialogWindow ( }); } -export function createScript (fn: (...args: Array) => void, ...args) { - return `(async function (...args) { - let safeJsonParse = json => { - let result; - try { - result = JSON.parse(json); - } catch (e) { - result = json; - } - return result; - }; - return (${fn.toString()})(...args.map(arg => { - if (typeof arg === 'function') { - return arg; - } else { - return safeJsonParse(arg); - } - })); - })(${args.map(arg => { - if (typeof arg === 'function') { - return arg.toString(); - } else if (typeof arg === 'string') { - return `'${arg}'`; - } else { - return `'${JSON.stringify(arg)}'`; - } - }).join(', ')})`; -} - export function waitForNavigation (window: BrowserWindow, urlFragment: RegExp = null): Promise { return new Promise(resolve => { let resolver = () => { From 67e33fb07249dc6184ef8d05e8f0aaa278d01918 Mon Sep 17 00:00:00 2001 From: alex-skakun Date: Wed, 17 Apr 2019 13:42:59 +0300 Subject: [PATCH 4/4] updated package-lock.json --- package-lock.json | 84 +++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 61 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3be1785..89ed23d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "admob-sync-app", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -5538,8 +5538,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -5560,14 +5559,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5582,20 +5579,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -5712,8 +5706,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -5725,7 +5718,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5740,7 +5732,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5748,14 +5739,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5774,7 +5763,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -5855,8 +5843,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -5868,7 +5855,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -5954,8 +5940,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -5991,7 +5976,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6011,7 +5995,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6055,14 +6038,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -6818,8 +6799,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -6840,14 +6820,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6862,20 +6840,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -6992,8 +6967,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -7005,7 +6979,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7020,7 +6993,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7028,14 +7000,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7054,7 +7024,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7135,8 +7104,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -7148,7 +7116,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7234,8 +7201,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -7271,7 +7237,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7291,7 +7256,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7335,14 +7299,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } },