forked from yannhodiesne/Discord-M1
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
170 lines (139 loc) · 4.22 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const { app, BrowserWindow, dialog, shell, ipcMain } = require('electron');
const windowStateKeeper = require('electron-window-state');
const { hasScreenCapturePermission, openSystemPreferences } = require('mac-screen-capture-permissions');
const { autoUpdater } = require('electron-updater');
const fs = require('fs');
const path = require('path');
// https://discuss.atom.io/t/how-to-catch-the-event-of-clicking-the-app-windows-close-button-in-electron-app/21425
let win;
let willQuitApp;
// Create window
function createWindow() {
// Window state
let mainWindowState = windowStateKeeper({
defaultWidth: 1000,
defaultHeight: 800
});
// Create the browser window.
win = new BrowserWindow({
icon: path.join(__dirname, 'icon.icns'),
'x': mainWindowState.x,
'y': mainWindowState.y,
'width': mainWindowState.width,
'height': mainWindowState.height,
minWidth: 350,
minHeight: 100,
titleBarStyle: 'hiddenInset',
// hide until ready
show: false,
// Enables DRM
webPreferences: {
plugins: true,
nodeIntegration: false,
contextIsolation: false,
sandbox: true
}
});
// Load the preloads scripts
win.webContents.session.setPreloads([
path.join(__dirname, 'preload-get-display-media-polyfill.js'),
]);
// Bypass browser permission checks
win.webContents.session.setPermissionCheckHandler(async () => {
return true;
});
win.webContents.session.setPermissionRequestHandler(async (webContents, permission, callback) => {
callback(true);
});
// Let us register listeners on the window, so we can update the state
// automatically (the listeners will be removed when the window is closed)
// and restore the maximized or full screen state
mainWindowState.manage(win);
// hides toolbar
win.setMenuBarVisibility(false);
// allows you to open toolbar by pressing alt
win.setAutoHideMenuBar(true);
win.loadURL('https://web.skype.com', {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
});
// Inject custom JavaScript into Skype
const filesToInject = [
'skype-platform-osx.js'
];
filesToInject.forEach((file) => {
let injectFilePath = path.join(process.resourcesPath, file);
if (!fs.existsSync(injectFilePath))
injectFilePath = `./${file}`;
fs.readFile(injectFilePath, 'utf-8', (_, data) => {
win.webContents.executeJavaScript(data);
});
});
win.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return {
action: 'deny',
};
});
// shows when ready
win.once('ready-to-show', () => {
win.show();
});
// Mirror behaviour of real app by only hiding the window
win.on('close', (e) => {
if (willQuitApp) {
/* the user tried to quit the app */
win = null;
} else {
/* the user only tried to close the window */
e.preventDefault();
win.hide();
}
});
}
let checkedForUpdate = false;
autoUpdater.on('update-available', ({ version }) => {
if (checkedForUpdate)
return;
checkedForUpdate = true;
setTimeout(() => {
// Remind in 24 hours
checkedForUpdate = false;
}, 24 * 60 * 60 * 1000);
dialog.showMessageBox(win, {
type: 'info',
buttons: ['Yes', 'Later'],
defaultId: 0,
cancelId: 1,
title: 'Update available',
detail: `A new version of Skype-M1 is available, would you like to check it out on GitHub ?\n\nCurrent version: ${app.getVersion()}\nLatest version: ${version}`,
}).then(({ response }) => {
if (response === 0)
shell.openExternal('https://github.com/dyanakiev/Skype-M1/releases');
});
});
app.whenReady().then(() => {
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.checkForUpdates();
setInterval(() => {
if (checkedForUpdate)
return;
autoUpdater.checkForUpdates();
}, 60 * 60 * 1000);
createWindow();
});
// Show the window again once user clicks on dock icon
app.on('activate', () => {
win.show();
});
/* 'before-quit' is emitted when Electron receives
* the signal to exit and wants to start closing windows */
app.on('before-quit', () => willQuitApp = true);
ipcMain.on('checkScreenPermission', async () => {
if (!hasScreenCapturePermission()) {
await openSystemPreferences();
}
});
ipcMain.on('updateBadgeCount', (e, args) => {
app.dock.setBadge(String(args.count));
});