Skip to content

Commit

Permalink
fix: request on get mic access. #238
Browse files Browse the repository at this point in the history
  • Loading branch information
ChugunovRoman committed Oct 16, 2021
1 parent a3f2724 commit 2ca6047
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 88 deletions.
5 changes: 5 additions & 0 deletions @types/Common/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ interface Tab {
isInVoiceCall?: boolean;
}

interface TabData {
micAccess: boolean;
view: import("electron").BrowserView;
}

interface SavedTab {
title?: string;
url?: string;
Expand Down
41 changes: 27 additions & 14 deletions src/main/window/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import WindowManager from "./WindowManager";
export default class Tabs {
public static registeredCancelCallbackMap: Map<number, () => void> = new Map();

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

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

isDev && tab.webContents.toggleDevTools();

const data = {
micAccess: false,
view: tab,
};

if (save) {
Tabs.tabs.set(tab.webContents.id, tab);
Tabs.tabs.set(tab.webContents.id, data);
}

return tab;
return data;
};

public static closeAll = (): void => {
Tabs.tabs.forEach((value, id) => {
Tabs.tabs.forEach((_, id) => {
if (id !== 1) {
Tabs.tabs.delete(id);
}
Expand All @@ -71,10 +76,10 @@ export default class Tabs {
public static close = (tabId: number): void => {
Tabs.tabs.forEach((value, id) => {
if (id === tabId) {
value.webContents.loadURL("about:blank");
value.view.webContents.loadURL("about:blank");

if (value.webContents && !value.webContents.isDestroyed()) {
value.webContents.destroy();
if (value.view.webContents && !value.view.webContents.isDestroyed()) {
value.view.webContents.destroy();
}

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

public static reloadAll = (): void =>
Tabs.tabs.forEach(t => (!t.webContents.isDestroyed() ? t.webContents.reload() : ""));
Tabs.tabs.forEach(t => (!t.view.webContents.isDestroyed() ? t.view.webContents.reload() : ""));

public static getTabByIndex = (index: number): E.BrowserView | undefined => {
public static getTabByIndex = (index: number): TabData | undefined => {
let i = 0;
let foundTab: E.BrowserView | undefined;
let foundTab: TabData | undefined;

Tabs.tabs.forEach(tab => {
if (index === i) {
Expand All @@ -114,10 +119,18 @@ export default class Tabs {
return i;
};

public static getAll = (): Map<number, E.BrowserView> => Tabs.tabs;
public static getAll = (): Map<number, TabData> => Tabs.tabs;

public static setMicAccess = (webContentsId: number, value: boolean): void => {
Tabs.tabs.forEach((tab, id) => {
if (id === webContentsId) {
tab.micAccess = value;
}
});
};

public static getByWebContentId = (webContentsId: number): E.BrowserView | undefined => {
let foundTab: E.BrowserView | undefined;
public static getByWebContentId = (webContentsId: number): TabData | undefined => {
let foundTab: TabData | undefined;

Tabs.tabs.forEach((tab, id) => {
if (id === webContentsId) {
Expand Down

0 comments on commit 2ca6047

Please sign in to comment.