Skip to content

Commit

Permalink
refactor: move permissions dialog to BrowserView
Browse files Browse the repository at this point in the history
  • Loading branch information
sentialx committed Sep 28, 2019
1 parent 615564f commit 14bf883
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 33 deletions.
4 changes: 1 addition & 3 deletions src/main/dialogs/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class FindDialog extends Dialog {
height: HEIGHT,
y: TOOLBAR_HEIGHT,
},
devtools: true,
});

ipcMain.on(`show-${this.webContents.id}`, () => {
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/dialogs/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 12 additions & 15 deletions src/main/windows/permissions.ts → src/main/dialogs/permissions.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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 });
Expand All @@ -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);
}
}
11 changes: 6 additions & 5 deletions src/main/dialogs/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/services/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/sessions-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/main/windows/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ 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);

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;
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/main/windows/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './app';
export * from './auth';
export * from './permissions';
export * from './form-fill';
export * from './credentials';
4 changes: 1 addition & 3 deletions src/renderer/views/permissions/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 14bf883

Please sign in to comment.