Skip to content

Commit 2ca6047

Browse files
committed
fix: request on get mic access. #238
1 parent a3f2724 commit 2ca6047

5 files changed

Lines changed: 138 additions & 88 deletions

File tree

@types/Common/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ interface Tab {
1111
isInVoiceCall?: boolean;
1212
}
1313

14+
interface TabData {
15+
micAccess: boolean;
16+
view: import("electron").BrowserView;
17+
}
18+
1419
interface SavedTab {
1520
title?: string;
1621
url?: string;

src/main/window/Tabs.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import WindowManager from "./WindowManager";
88
export default class Tabs {
99
public static registeredCancelCallbackMap: Map<number, () => void> = new Map();
1010

11-
private static tabs: Map<number, E.BrowserView> = new Map();
11+
private static tabs: Map<number, TabData> = new Map();
1212

13-
public static newTab = (url: string, rect: E.Rectangle, preloadScript?: string, save = true): E.BrowserView => {
13+
public static newTab = (url: string, rect: E.Rectangle, preloadScript?: string, save = true): TabData => {
1414
const options: E.BrowserViewConstructorOptions = {
1515
webPreferences: {
1616
nodeIntegration: false,
@@ -53,15 +53,20 @@ export default class Tabs {
5353

5454
isDev && tab.webContents.toggleDevTools();
5555

56+
const data = {
57+
micAccess: false,
58+
view: tab,
59+
};
60+
5661
if (save) {
57-
Tabs.tabs.set(tab.webContents.id, tab);
62+
Tabs.tabs.set(tab.webContents.id, data);
5863
}
5964

60-
return tab;
65+
return data;
6166
};
6267

6368
public static closeAll = (): void => {
64-
Tabs.tabs.forEach((value, id) => {
69+
Tabs.tabs.forEach((_, id) => {
6570
if (id !== 1) {
6671
Tabs.tabs.delete(id);
6772
}
@@ -71,10 +76,10 @@ export default class Tabs {
7176
public static close = (tabId: number): void => {
7277
Tabs.tabs.forEach((value, id) => {
7378
if (id === tabId) {
74-
value.webContents.loadURL("about:blank");
79+
value.view.webContents.loadURL("about:blank");
7580

76-
if (value.webContents && !value.webContents.isDestroyed()) {
77-
value.webContents.destroy();
81+
if (value.view.webContents && !value.view.webContents.isDestroyed()) {
82+
value.view.webContents.destroy();
7883
}
7984

8085
Tabs.tabs.delete(id);
@@ -83,11 +88,11 @@ export default class Tabs {
8388
};
8489

8590
public static reloadAll = (): void =>
86-
Tabs.tabs.forEach(t => (!t.webContents.isDestroyed() ? t.webContents.reload() : ""));
91+
Tabs.tabs.forEach(t => (!t.view.webContents.isDestroyed() ? t.view.webContents.reload() : ""));
8792

88-
public static getTabByIndex = (index: number): E.BrowserView | undefined => {
93+
public static getTabByIndex = (index: number): TabData | undefined => {
8994
let i = 0;
90-
let foundTab: E.BrowserView | undefined;
95+
let foundTab: TabData | undefined;
9196

9297
Tabs.tabs.forEach(tab => {
9398
if (index === i) {
@@ -114,10 +119,18 @@ export default class Tabs {
114119
return i;
115120
};
116121

117-
public static getAll = (): Map<number, E.BrowserView> => Tabs.tabs;
122+
public static getAll = (): Map<number, TabData> => Tabs.tabs;
123+
124+
public static setMicAccess = (webContentsId: number, value: boolean): void => {
125+
Tabs.tabs.forEach((tab, id) => {
126+
if (id === webContentsId) {
127+
tab.micAccess = value;
128+
}
129+
});
130+
};
118131

119-
public static getByWebContentId = (webContentsId: number): E.BrowserView | undefined => {
120-
let foundTab: E.BrowserView | undefined;
132+
public static getByWebContentId = (webContentsId: number): TabData | undefined => {
133+
let foundTab: TabData | undefined;
121134

122135
Tabs.tabs.forEach((tab, id) => {
123136
if (id === webContentsId) {

0 commit comments

Comments
 (0)