forked from mikepruett3/youtube-desktop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
118 lines (105 loc) · 3.32 KB
/
main.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
// main.js
// https://www.electronforge.io/config/makers/squirrel.windows
if (require('electron-squirrel-startup')) return;
const { app, shell, session, BrowserWindow, Menu, Tray, nativeImage, dialog } = require('electron')
const { getHA, setHA } = require('./settings.js');
const path = require('path');
// Disable Hardware Acceleration
// https://www.electronjs.org/docs/latest/tutorial/offscreen-rendering
if (!getHA()) {
app.disableHardwareAcceleration()
}
createWindow = () => {
const win = new BrowserWindow({
width: 1280,
height: 720,
title: 'YouTube Desktop',
icon: './images/icon',
autoHideMenuBar: true,
webPreferences: {
webSecurity: true,
contextIsolation: true,
webviewTag: true,
nodeIntegration: true,
nativeWindowOpen: true
}
});
win.loadURL(`https://www.youtube.com/feed/subscriptions`);
// Create a Cookie, so that Theater Mode is allways enabled.
// https://www.electronjs.org/docs/latest/api/cookies
// http://blog.ercanopak.com/how-to-make-theater-mode-the-default-for-youtube/
// https://medium.com/swlh/building-an-application-with-electron-js-part-2-e62c23e4eb69
const cookie = { url: 'https://www.youtube.com', name: 'wide', value: '1' }
session.defaultSession.cookies.set(cookie)
.then(() => {
// success
}, (error) => {
console.error(error)
})
// Open links with External Browser
// https://stackoverflow.com/a/67409223
win.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
let tray = null
const icon = nativeImage.createFromPath('./images/icon')
tray = new Tray(icon)
const contextMenu = Menu.buildFromTemplate([
{
label: 'Hardware Acceleration',
type: 'checkbox',
checked: getHA(),
click({ checked }) {
setHA(checked)
dialog.showMessageBox(
null,
{
type: 'info',
title: 'info',
message: 'Exiting Applicatiom, as Hardware Acceleration setting has been changed...'
})
.then(result => {
if (result.response === 0) {
app.relaunch();
app.exit()
}
}
)
}
},
{
label: 'Clear Cache',
click: () => {
session.defaultSession.clearStorageData()
app.relaunch();
app.exit();
}
},
{
label: 'Reload',
click: () => win.reload()
},
{
label: 'Quit',
type: 'normal',
role: 'quit'
}
])
tray.setToolTip('YouTube Desktop')
tray.setTitle('YouTube Desktop')
tray.setContextMenu(contextMenu)
};
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})