-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
130 lines (112 loc) · 2.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"use strict";
const path = require("path");
const os = require("os");
const {
app,
BrowserWindow,
Menu,
systemPreferences,
globalShortcut
} = require("electron");
require("electron-reload")(__dirname);
const { is } = require("electron-util");
const unhandled = require("electron-unhandled");
const debug = require("electron-debug");
const contextMenu = require("electron-context-menu");
const config = require('./config');
const menu = require("./menu");
if (os.platform() == "darwin") {
systemPreferences.askForMediaAccess("microphone").then(isAllowed => {
console.log("isAllowed", isAllowed);
});
}
unhandled();
debug();
contextMenu();
// Note: Must match `build.appId` in package.json
app.setAppUserModelId("com.company.ClubHouse");
app.commandLine.appendSwitch("ignore-certificate-errors");
let mainWindow;
const createMainWindow = async () => {
const ws = config.get('windowstate', {});
const win = new BrowserWindow({
title: "Clubhouse Desktop Client",
show: false,
width: ws.width || 1020,
height: ws.height || 800,
minWidth: 965,
minHeight: 500,
autoHideMenuBar: true, // Hides menubar on Top
titleBarStyle: os.platform() == "darwin" ? "hidden" : '',
fullscreenable: false,
isMaximized: ws.isMaximized,
frame: os.platform() == "darwin" ? false : true,
resizable: true,
icon: path.join(__dirname, "static/icon.png"),
webPreferences: {
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
nodeIntegrationInWorker: true
// devTools: false
}
});
app.on("ready", () => {
// Register a shortcut listener for Ctrl + Shift + I
globalShortcut.register("Control+Shift+I", () => {
// When the user presses Ctrl + Shift + I, this function will get called
// You can modify this function to do other things, but if you just want
// to disable the shortcut, you can just return false
return false;
});
});
win.on("ready-to-show", () => {
win.show();
});
win.on("closed", () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});
win.on("close", () => {
const isMaximized = win.isMaximized();
const bounds = win.getBounds();
config.set('windowstate', {
height: bounds.height,
width: bounds.width,
isMaximized: isMaximized
});
});
await win.loadFile(path.join(__dirname, "index.html"));
return win;
};
// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on("second-instance", () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
app.on("window-all-closed", () => {
if (!is.macos) {
app.quit();
}
});
app.on("activate", async () => {
if (!mainWindow) {
mainWindow = await createMainWindow();
}
});
(async () => {
await app.whenReady();
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();
mainWindow.webContents.on("new-window", function(e, url) {
e.preventDefault();
require("electron").shell.openExternal(url);
});
})();