Skip to content

Commit

Permalink
Merge pull request #43 from appodeal/develop
Browse files Browse the repository at this point in the history
Release v0.1.10
  • Loading branch information
NaLLiFFuNT authored Apr 25, 2019
2 parents 55f1345 + deb4f3c commit d4049b2
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"repository": "https://github.com/appodeal/admob-sync-app",
"description": "Appodeal AdMob Sync application",
"private": true,
"version": "0.1.9",
"version": "0.1.10",
"scripts": {
"start": "webpack --watch --progress --config=webpack/development.ts",
"test": "jest",
Expand Down
8 changes: 6 additions & 2 deletions src/core/appdeal-api/appodeal-api.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import {AppodealAccount} from 'core/appdeal-api/interfaces/appodeal.account.inte
import {ErrorFactoryService} from 'core/error-factory/error-factory.service';
import {AuthorizationError} from 'core/error-factory/errors/authorization.error';
import {InternalError} from 'core/error-factory/errors/internal-error';
import EventEmitter from 'events';
import {UserAccount} from 'interfaces/common.interfaces';
import PushStream from 'zen-push';


export class AppodealApi {
export class AppodealApi extends EventEmitter {
private readonly DEFAULT_API: AppodealApiService;
private APIs = new Map<string, AppodealApiService>();
private errorSubscriptions = new Map<string, Subscription>();
private _onError = new PushStream<{account: UserAccount, error: Error}>();
private _onError = new PushStream<{ account: UserAccount, error: Error }>();
onError = this._onError.observable;

constructor (
private errorFactory: ErrorFactoryService,
accounts: Array<UserAccount>
) {
super();
this.DEFAULT_API = new AppodealApiService(errorFactory, AppodealSessions.DEFAULT_SESSION);
accounts.forEach(account => {
let api = new AppodealApiService(this.errorFactory, AppodealSessions.get(account));
Expand Down Expand Up @@ -50,6 +52,7 @@ export class AppodealApi {
this.destroyApi(account.id);
this.saveApi(api, account);
sessionInfo.save(account.id);
this.emit('signIn', account)
} else {
api.destroy();
}
Expand All @@ -68,6 +71,7 @@ export class AppodealApi {
});
this.destroyApi(accountId);
await AppodealSessions.remove(accountId);
this.emit('signOut', account)
}

async fetchAllAccounts (): Promise<Map<string, AppodealAccount>> {
Expand Down
8 changes: 7 additions & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ export class Store {
appodealSignIn (email: string, password: string): Promise<AppodealAccount> {
return this.appodealApi.signIn(email, password)
.then(account => this.addAppodealAccount(account))
.then(account => this.selectAppodealAccount(account));
.then(account => this.selectAppodealAccount(account))
.then((account) => {
openSettingsWindow();
return account;
});

}

@action
Expand All @@ -267,6 +272,7 @@ export class Store {
appodealAccounts: updatedAccounts
}
});
set<AppState>(this.state, 'selectedAppodealAccount', null);
return updatedAccounts[accountIndex] || updatedAccounts[accountIndex - 1] || null;
})
.then(accState => this.selectAppodealAccount(accState ? this.appodealAccounts.get(accState.id) : null));
Expand Down
7 changes: 4 additions & 3 deletions src/core/sync-apps/sync-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export class SyncHistory {
private static async loadHistory (adMobAccount: AdmobAccount): Promise<SyncHistoryInfo> {
if (!SyncHistory.cache.has(adMobAccount.id)) {
const data = <SyncHistoryInfo>await getJsonFile(SyncHistory.fileName(adMobAccount));
data.syncs = data.syncs || [];
SyncHistory.cache.set(adMobAccount.id, data || {

SyncHistory.cache.set(adMobAccount.id, {
lastSync: null,
lastSuccessfulSync: null,
admobAuthorizationRequired: true,
syncs: []
syncs: [],
...(data || {})
});
}

Expand Down
23 changes: 18 additions & 5 deletions src/lib/app-tray.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import {UpdatesConnector} from 'core/updates-connector';
import {Menu, Tray} from 'electron';
import {getDefaultTrayIcon, getSyncingTrayIcon, getWarningTrayIcon} from 'lib/icon';
import {openAboutWindow, openSettingsWindow} from 'lib/ui-windows';
import {openAboutWindow, openAppodealSignInWindow, openSettingsWindow} from 'lib/ui-windows';


export class AppTray {
private readonly tray: Tray;
private warningIconInterval;
private menu: Menu;


constructor (private updatesConnector?: UpdatesConnector) {

constructor (private updatesConnector: UpdatesConnector) {
this.tray = new Tray(getDefaultTrayIcon());
this.tray.setContextMenu(Menu.buildFromTemplate([
this.menu = Menu.buildFromTemplate([
{type: 'normal', label: 'Sign in', click: () => openAppodealSignInWindow(), id: 'sign-in', visible: false},
{type: 'separator', id: 'sign-in-sep', visible: false},
{type: 'normal', label: 'Settings', click: () => openSettingsWindow()},
{type: 'normal', label: 'About', click: () => openAboutWindow()},
{type: 'normal', label: 'Check for updates', click: () => this.updatesConnector.checkForUpdates(false, 'modal')},
{type: 'separator'},
{type: 'normal', label: 'Quit', role: 'quit'}
]));
]);
this.tray.setContextMenu(this.menu);
this.tray.on('click', () => this.tray.popUpContextMenu());
}

Expand Down Expand Up @@ -52,6 +55,16 @@ export class AppTray {
console.log('setDefaultIcon');
}

showSignIn () {
this.menu.getMenuItemById('sign-in').visible = true;
this.menu.getMenuItemById('sign-in-sep').visible = true;
}

hideSignIn () {
this.menu.getMenuItemById('sign-in').visible = false;
this.menu.getMenuItemById('sign-in-sep').visible = false;
}


async destroy () {
// unsubscribe
Expand Down
12 changes: 9 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AboutConnector} from "core/about-connector";

require('source-map-support').install();

import {AboutConnector} from 'core/about-connector';
import {AccountsConnector} from 'core/accounts-connector';
import {AdMobSessions} from 'core/admob-api/admob-sessions.helper';
import {AppodealApi} from 'core/appdeal-api/appodeal-api.factory';
Expand Down Expand Up @@ -44,6 +44,7 @@ if (app.dock) {
app.on('window-all-closed', () => {});
app.on('ready', async () => {

// APP INITIALIZERS
let [preferences] = await Promise.all([
Preferences.load(),
AppodealSessions.init(),
Expand All @@ -61,15 +62,16 @@ app.on('ready', async () => {
updates = new UpdatesService(preferences.updates.lastCheck),
updatesConnector = new UpdatesConnector(store, updates),
syncService = new SyncService(store, appodealApi, onlineService),
accountsConnector = new AccountsConnector(store),
tray = new AppTray(updatesConnector),
trayIcon = new TrayIcon(store, tray),
accountsConnector = new AccountsConnector(store),
aboutConnector = new AboutConnector(),
logsConnector = new LogsConnector(store, appodealApi),
onlineConnector = new OnlineConnector(store),
syncScheduler = new SyncScheduler(syncService, store, onlineService),
syncConnector = new SyncConnector(store, syncService);

// EVENTS
appodealApi.onError.subscribe(async ({account, error}) => {
if (error instanceof AuthorizationError && !error.isHandled) {
await store.patchPreferences({
Expand All @@ -90,6 +92,9 @@ app.on('ready', async () => {
}
});

appodealApi.on('signIn', () => tray.hideSignIn());
appodealApi.on('signOut', () => tray.showSignIn());

onlineService.once('online', () => {
store.validateAppVersion()
.then(async versionValid => {
Expand All @@ -100,6 +105,7 @@ app.on('ready', async () => {
await store.fetchAllAppodealUsers();
let accounts = store.state.preferences.accounts.appodealAccounts;
if (accounts.length === 0) {
tray.showSignIn();
openAppodealSignInWindow();
} else {
let problemAccount = accounts.find(acc => !acc.active);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/admob-account/AdmobAccountComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class AdmobAccountComponent extends Component<AdmobAccountComponentProps,
</button>

{!this.isSetupFormVisible(account) &&
<button type="button" onClick={() => this.displaySetupForm(true)}>Set credentials</button>}
<button type="button" onClick={() => this.displaySetupForm(true)}>Update credentials</button>}
</>}
{!this.signedIn && <>
<button onClick={singleEvent(this.signInAdMob, this)}
Expand Down

0 comments on commit d4049b2

Please sign in to comment.