Skip to content
This repository was archived by the owner on Jun 4, 2023. It is now read-only.

Commit 23b884a

Browse files
committed
fix: revive auth dialog
1 parent faa9975 commit 23b884a

File tree

5 files changed

+53
-50
lines changed

5 files changed

+53
-50
lines changed

src/main/application.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { StorageService } from './services/storage';
1010
import { getMainMenu } from './menus/main';
1111
import { runAutoUpdaterService } from './services';
1212
import { DialogsService } from './services/dialogs-service';
13+
import { requestAuth } from './dialogs/auth';
1314

1415
export class Application {
1516
public static instance = new Application();
@@ -63,7 +64,8 @@ export class Application {
6364
e.preventDefault();
6465

6566
const window = this.windows.findByBrowserView(webContents.id);
66-
const credentials = await window.dialogs.authDialog.requestAuth(
67+
const credentials = await requestAuth(
68+
window.win,
6769
request.url,
6870
webContents.id,
6971
);

src/main/dialogs/auth.ts

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
1-
import { ipcMain } from 'electron';
2-
import { AppWindow } from '../windows';
3-
import {
4-
TOOLBAR_HEIGHT,
5-
VIEW_Y_OFFSET,
6-
DIALOG_MARGIN_TOP,
7-
} from '~/constants/design';
8-
import { Dialog } from '.';
1+
import { VIEW_Y_OFFSET } from '~/constants/design';
2+
import { BrowserWindow } from 'electron';
3+
import { Application } from '../application';
94

10-
const WIDTH = 400;
11-
const HEIGHT = 500;
5+
export const requestAuth = (
6+
browserWindow: BrowserWindow,
7+
url: string,
8+
tabId: number,
9+
): Promise<boolean> => {
10+
return new Promise((resolve, reject) => {
11+
const appWindow = Application.instance.windows.fromBrowserWindow(
12+
browserWindow,
13+
);
1214

13-
export class AuthDialog extends Dialog {
14-
public constructor(appWindow: AppWindow) {
15-
super(appWindow, {
15+
const tab = appWindow.viewManager.views.get(tabId);
16+
tab.requestedAuth = { url };
17+
18+
const dialog = Application.instance.dialogs.show({
1619
name: 'auth',
17-
bounds: {
18-
width: WIDTH,
19-
height: HEIGHT,
20-
y: VIEW_Y_OFFSET - DIALOG_MARGIN_TOP - 8,
20+
browserWindow,
21+
getBounds: () => {
22+
const { width } = browserWindow.getContentBounds();
23+
return {
24+
width: 400,
25+
height: 500,
26+
x: width / 2 - 400 / 2,
27+
y: VIEW_Y_OFFSET,
28+
};
29+
},
30+
tabAssociation: {
31+
tabId,
32+
getTabInfo: (tabId) => {
33+
const tab = appWindow.viewManager.views.get(tabId);
34+
return tab.requestedAuth;
35+
},
36+
},
37+
onWindowBoundsUpdate: (disposition) => {
38+
if (disposition === 'resize') dialog.rearrange();
2139
},
2240
});
23-
}
24-
25-
public requestAuth(
26-
url: string,
27-
tabId: number,
28-
): Promise<{ username: string; password: string }> {
29-
return new Promise((resolve) => {
30-
this.show();
31-
this.tabIds.push(tabId);
32-
33-
this.send('request-auth', url);
34-
35-
ipcMain.once(`request-auth-result-${this.appWindow.id}`, (e, result) => {
36-
this.tabIds = this.tabIds.filter((x) => x !== tabId);
37-
this.hide();
38-
resolve(result);
39-
});
40-
});
41-
}
4241

43-
public rearrange() {
44-
const { width } = this.appWindow.win.getContentBounds();
42+
if (!dialog) return;
4543

46-
super.rearrange({
47-
x: Math.round(width / 2 - WIDTH / 2),
48-
y: TOOLBAR_HEIGHT,
44+
dialog.on('result', (e, result) => {
45+
resolve(result);
46+
dialog.hide();
4947
});
50-
}
51-
}
48+
});
49+
};

src/main/view.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import { TabEvent } from '~/interfaces/tabs';
1414
import { Queue } from '~/utils/queue';
1515
import { Application } from './application';
1616

17+
interface IAuthInfo {
18+
url: string;
19+
}
20+
1721
export class View {
1822
public browserView: BrowserView;
1923

@@ -37,6 +41,7 @@ export class View {
3741
text: '',
3842
};
3943

44+
public requestedAuth: IAuthInfo;
4045
public requestedPermission: any;
4146

4247
private historyQueue = new Queue();

src/renderer/views/auth/components/App/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ipcRenderer } from 'electron';
21
import * as React from 'react';
32
import { observer } from 'mobx-react-lite';
43
import { ThemeProvider } from 'styled-components';
@@ -15,7 +14,7 @@ const ref1 = React.createRef<Textfield>();
1514
const ref2 = React.createRef<PasswordInput>();
1615

1716
const sendResponse = (credentials: any) => {
18-
ipcRenderer.send(`request-auth-result-${store.windowId}`, credentials);
17+
store.send('result', credentials);
1918
};
2019

2120
const onClick = () => {

src/renderer/views/auth/store/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { observable } from 'mobx';
2-
import { ipcRenderer } from 'electron';
32
import { DialogStore } from '~/models/dialog-store';
43

54
export class Store extends DialogStore {
@@ -9,9 +8,9 @@ export class Store extends DialogStore {
98
public constructor() {
109
super({ hideOnBlur: false, visibilityWrapper: false });
1110

12-
ipcRenderer.on('request-auth', (e, url) => {
13-
this.url = url;
14-
});
11+
this.onUpdateTabInfo = (tabId, auth) => {
12+
this.url = auth.url;
13+
};
1514
}
1615
}
1716

0 commit comments

Comments
 (0)