From 14bf883c8f882a5e6c87dd3e57ede0e16e0ef8f2 Mon Sep 17 00:00:00 2001 From: Sential Date: Sat, 28 Sep 2019 23:26:56 +0200 Subject: [PATCH] refactor: move permissions dialog to BrowserView --- src/main/dialogs/find.ts | 4 +-- src/main/dialogs/menu.ts | 8 ++++-- src/main/{windows => dialogs}/permissions.ts | 27 +++++++++---------- src/main/dialogs/search.ts | 11 ++++---- src/main/services/messaging.ts | 2 +- src/main/sessions-manager.ts | 2 +- src/main/windows/app.ts | 5 ++-- src/main/windows/index.ts | 1 - src/renderer/views/permissions/store/index.ts | 4 +-- 9 files changed, 31 insertions(+), 33 deletions(-) rename src/main/{windows => dialogs}/permissions.ts (65%) diff --git a/src/main/dialogs/find.ts b/src/main/dialogs/find.ts index 3612c242f..4634784c2 100644 --- a/src/main/dialogs/find.ts +++ b/src/main/dialogs/find.ts @@ -15,7 +15,6 @@ export class FindDialog extends Dialog { height: HEIGHT, y: TOOLBAR_HEIGHT, }, - devtools: true, }); ipcMain.on(`show-${this.webContents.id}`, () => { @@ -24,8 +23,7 @@ export class FindDialog extends Dialog { } public show() { - const { width } = this.appWindow.getContentBounds(); - super.show({ x: width - WIDTH }); + super.show(); } public find(tabId: number, data: any) { diff --git a/src/main/dialogs/menu.ts b/src/main/dialogs/menu.ts index 4b7374491..31c9dfe97 100644 --- a/src/main/dialogs/menu.ts +++ b/src/main/dialogs/menu.ts @@ -19,9 +19,13 @@ export class MenuDialog extends Dialog { }); } - public show() { + public rearrange() { const { width } = this.appWindow.getContentBounds(); - super.show({ x: width - WIDTH }); + super.rearrange({ x: width - WIDTH }); + } + + public show() { + super.show(); this.webContents.send('visible', true); } diff --git a/src/main/windows/permissions.ts b/src/main/dialogs/permissions.ts similarity index 65% rename from src/main/windows/permissions.ts rename to src/main/dialogs/permissions.ts index 58f2dcb7a..f2d34afcf 100644 --- a/src/main/windows/permissions.ts +++ b/src/main/dialogs/permissions.ts @@ -1,19 +1,22 @@ import { ipcMain } from 'electron'; import { TOOLBAR_HEIGHT } from '~/constants/design'; -import { AppWindow } from '.'; -import { PopupWindow } from './popup'; +import { AppWindow } from '../windows'; +import { Dialog } from '.'; const HEIGHT = 175; const WIDTH = 350; -export class PermissionsWindow extends PopupWindow { +export class PermissionsDialog extends Dialog { public constructor(appWindow: AppWindow) { - super(appWindow, 'permissions'); - - this.setBounds({ - height: HEIGHT, - width: WIDTH, - } as any); + super(appWindow, { + name: 'permissions', + bounds: { + height: HEIGHT, + width: WIDTH, + y: TOOLBAR_HEIGHT, + x: 0, + }, + }); } public async requestPermission( @@ -30,7 +33,6 @@ export class PermissionsWindow extends PopupWindow { return reject('Unknown permission'); } - this.rearrange(); this.show(); this.webContents.send('request-permission', { name, url, details }); @@ -44,9 +46,4 @@ export class PermissionsWindow extends PopupWindow { ); }); } - - public rearrange() { - const cBounds = this.appWindow.getContentBounds(); - this.setBounds({ x: cBounds.x, y: cBounds.y + TOOLBAR_HEIGHT } as any); - } } diff --git a/src/main/dialogs/search.ts b/src/main/dialogs/search.ts index f1895d585..32aee9dda 100644 --- a/src/main/dialogs/search.ts +++ b/src/main/dialogs/search.ts @@ -19,7 +19,7 @@ export class SearchDialog extends Dialog { ipcMain.on(`height-${this.webContents.id}`, (e, height) => { const { width } = this.appWindow.getContentBounds(); - this.rearrange({ + super.rearrange({ height: HEIGHT + height, x: Math.round(width / 2 - WIDTH / 2), }); @@ -31,12 +31,13 @@ export class SearchDialog extends Dialog { else this.hide(); } - public show() { + public rearrange() { const { width } = this.appWindow.getContentBounds(); + super.rearrange({ x: Math.round(width / 2 - WIDTH / 2) }); + } - super.show({ - x: Math.round(width / 2 - WIDTH / 2), - }); + public show() { + super.show(); const selected = this.appWindow.viewManager.selected; diff --git a/src/main/services/messaging.ts b/src/main/services/messaging.ts index d8b556d93..470a5a981 100644 --- a/src/main/services/messaging.ts +++ b/src/main/services/messaging.ts @@ -32,7 +32,7 @@ export const runMessagingService = (appWindow: AppWindow) => { }); ipcMain.on(`permission-dialog-hide-${id}`, () => { - appWindow.permissionWindow.hide(); + appWindow.permissionsDialog.hide(); }); ipcMain.on(`update-find-info-${id}`, (e, tabId, data) => diff --git a/src/main/sessions-manager.ts b/src/main/sessions-manager.ts index 56fcc8ea2..aeee5b84b 100644 --- a/src/main/sessions-manager.ts +++ b/src/main/sessions-manager.ts @@ -47,7 +47,7 @@ export class SessionsManager { const window = windowsManager.findWindowByBrowserView( webContents.id, ); - const response = await window.permissionWindow.requestPermission( + const response = await window.permissionsDialog.requestPermission( permission, webContents.getURL(), details, diff --git a/src/main/windows/app.ts b/src/main/windows/app.ts index fcfa039a3..328531400 100644 --- a/src/main/windows/app.ts +++ b/src/main/windows/app.ts @@ -7,13 +7,13 @@ import { getPath } from '~/utils'; import { runMessagingService, Multrin } from '../services'; import { WindowsManager } from '../windows-manager'; import { MenuDialog, SearchDialog, FindDialog } from '../dialogs'; +import { PermissionsDialog } from '../dialogs/permissions'; export class AppWindow extends BrowserWindow { public viewManager: ViewManager; public multrin = new Multrin(this); // TODO: - // public permissionWindow = new PermissionsWindow(this); // public authWindow = new AuthWindow(this); // public formFillWindow = new FormFillWindow(this); // public credentialsWindow = new CredentialsWindow(this); @@ -21,6 +21,7 @@ export class AppWindow extends BrowserWindow { public menuDialog = new MenuDialog(this); public searchDialog = new SearchDialog(this); public findDialog = new FindDialog(this); + public permissionsDialog = new PermissionsDialog(this); public incognito: boolean; private windowsManager: WindowsManager; @@ -76,12 +77,12 @@ export class AppWindow extends BrowserWindow { const moveAndResize = () => { this.authWindow.rearrange(); - this.permissionWindow.rearrange(); this.formFillWindow.rearrange(); this.credentialsWindow.rearrange(); this.findDialog.rearrange(); this.menuDialog.hide(); + this.permissionsDialog.rearrange(); }; // Update window bounds on resize and on move when window is not maximized. diff --git a/src/main/windows/index.ts b/src/main/windows/index.ts index 8557c26da..a600b2a9c 100644 --- a/src/main/windows/index.ts +++ b/src/main/windows/index.ts @@ -1,5 +1,4 @@ export * from './app'; export * from './auth'; -export * from './permissions'; export * from './form-fill'; export * from './credentials'; diff --git a/src/renderer/views/permissions/store/index.ts b/src/renderer/views/permissions/store/index.ts index c3b954eef..ecd2d94ef 100644 --- a/src/renderer/views/permissions/store/index.ts +++ b/src/renderer/views/permissions/store/index.ts @@ -11,9 +11,7 @@ export class Store { @observable public domain: string; - public windowId: number = ipcRenderer.sendSync( - `get-window-id-${getCurrentWindow().id}`, - ); + public windowId = getCurrentWindow().id; public constructor() { ipcRenderer.on('request-permission', (e, { url, name, details }) => {