Skip to content

Commit

Permalink
[AMSA-37] Display app windows in dock on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-skakun committed Apr 17, 2019
1 parent 421d8db commit b3412bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/lib/app-menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Menu} from 'electron';
import {showAboutDialog} from 'lib/about';
import {isMacOS} from 'lib/platform';


Expand All @@ -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'}
]
Expand Down
29 changes: 25 additions & 4 deletions src/lib/ui-windows.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,8 +10,13 @@ const OPENED_WINDOWS = new Map<string, BrowserWindow | Promise<BrowserWindow>>()
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) {
Expand All @@ -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);
}
Expand All @@ -50,7 +62,16 @@ export function openAppodealAccountsWindow (): Promise<void> {
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);
}));
});
Expand Down
31 changes: 0 additions & 31 deletions src/lib/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export function openDialogWindow<T = any> (
height,
minWidth: width,
minHeight: height,
// maxWidth: width,
// maxHeight: height,
resizable: false,
frame: true,
fullscreenable: false,
Expand All @@ -96,35 +94,6 @@ export function openDialogWindow<T = any> (
});
}

export function createScript (fn: (...args: Array<any>) => 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<void> {
return new Promise(resolve => {
let resolver = () => {
Expand Down

0 comments on commit b3412bd

Please sign in to comment.