-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
147 lines (129 loc) · 4.45 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
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
const { app, BrowserWindow, ipcMain, nativeTheme,
shell, /*Menu, MenuItem,*/ clipboard, Notification, nativeImage } = require('electron')
const contextMenu = require('electron-context-menu')
const path = require('path')
const fs = require('fs')
var dbus = require('dbus-native')
var sessionBus = dbus.sessionBus()
contextMenu({
prepend: (defaultActions, params, browserWindow) => [
{
label: 'Copy image URL',
// Only show it when right-clicking images
visible: params.mediaType === 'image',
click: () => {
clipboard.writeText(params.srcURL)
}
},
{
label: 'Open image in browser',
// Only show it when right-clicking images
visible: params.mediaType === 'image',
click: () => {
shell.openExternal(params.srcURL);
}
},
{
label: 'Reload',
click: () => {
browserWindow.reload();
}
},
{
label: 'Open DevTools',
click: () => {
browserWindow.webContents.openDevTools()
}
}
]
});
const createWindow = () => {
const win = new BrowserWindow({
width: 1000,
height: 600,
menuBarVisible: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
//webviewTag: true
},
icon: path.join(__dirname, '/images//io.github.whatsapp-enhanced.svg')
})
win.compactMode = true;
win.setMenuBarVisibility(false)
//win.loadFile('index.html')
// We have to fake userAgent because WhatsApp really hates anything but chrome
// and mainstream browsers
win.loadURL('https://web.whatsapp.com/', {userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'})
//win.webContents.openDevTools()
win.webContents.on('did-finish-load', () => {
fs.readFile(path.join(__dirname, 'styles.css'), 'utf-8', (err, data) => {
if (err) {
console.error('An error while trying to read a file occured ', err);
return;
}
console.log('Inserting css')
win.webContents.insertCSS(data)
});
/*
fs.readFile(path.join(__dirname, 'ui_hook.js'), 'utf-8', (err, data) => {
if (err) {
console.error('An error while trying to read a file occured ', err);
return;
}
console.log('Executing UI hook')
win.webContents.executeJavaScript(data)
});*/
if (win.compactMode == true) {
win.setSize(1000, 600)
fs.readFile(path.join(__dirname, 'compact.css'), 'utf-8', (err, data) => {
if (err) {
console.error('An error while trying to read a file occured ', err);
return;
}
console.log('Inserting compact css')
win.webContents.insertCSS(data)
});
}
})
win.webContents.setWindowOpenHandler((details) => {
//console.log('Requested window with details: ', details)
shell.openExternal(details.url);
return { action: 'deny' }
})
}
/*ipcMain.handle('compact-mode:enable', async (event) => {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.compactMode = true
fs.readFile(path.join(__dirname, 'compact.css'), 'utf-8', (err, data) => {
if (err) {
console.error('An error while trying to read a file occured ', err);
return;
}
console.log('Inserting compact css')
win.webContents.insertCSS(data)
});
win.setSize(1000, 600)
})
ipcMain.handle('compact-mode:disable', async (event) => {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.compactMode = false
win.reload()
win.setSize(1200, 700)
})
ipcMain.handle('compact-mode:get', async (event) => {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
return win.compactMode
})
*/
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})