-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
145 lines (124 loc) · 3.74 KB
/
index.js
File metadata and controls
145 lines (124 loc) · 3.74 KB
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
'use strict';
const {
app,
BrowserWindow,
Menu,
shell,
session
} = require('electron');
const tor = require('@deadcanaries/granax')();
const {
autoUpdater
} = require('electron-updater');
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');
const packageJson = require('./package.json');
const URL = require('url').URL;
const BASE_URL = 'https://chessxdsmre65y2ow67yb3sszrekgkd6mcnb43zduhuhbnhc4hqyilqd.onion';
const PARSED_BASE_URL = new URL(BASE_URL);
// Prevent window from being garbage collected
let mainWindow;
unhandled();
debug();
contextMenu();
app.setAppUserModelId(packageJson.build.appId);
// Uncomment this before publishing your first version.
// It's commented out as it throws an error if there are no published versions.
if (!is.development) {
const FOUR_HOURS = 1000 * 60 * 60 * 4;
setInterval(() => {
autoUpdater.checkForUpdates();
}, FOUR_HOURS);
autoUpdater.checkForUpdates();
}
tor.on('error', function(err) {
console.error(err);
});
const createMainWindow = async () => {
const win = new BrowserWindow({
title: app.name,
show: false,
width: 800,
height: 600,
});
tor.on('ready', () => {
tor.getInfo('net/listeners/socks', async (err, result) => {
let port = parseInt(result.split('"').join('').split(':')[1]);
await win.webContents.session.setProxy({
proxyRules: `socks5://127.0.0.1:${port}`
});
console.log(`TorSocks listening on ${port}!`);
await win.loadURL(BASE_URL);
win.on('ready-to-show', () => {
win.maximize();
win.show();
});
});
});
win.on('closed', () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});
return win;
};
// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
app.quit();
}
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', async (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl);
if (parsedUrl.origin !== PARSED_BASE_URL.origin) {
event.preventDefault();
await shell.openExternal(navigationUrl);
}
})
contents.on('new-window', async (event, navigationUrl) => {
// In this example, we'll ask the operating system
// to open this event's url in the default browser.
const parsedUrl = new URL(navigationUrl);
if (parsedUrl.origin !== PARSED_BASE_URL.origin) {
event.preventDefault()
await shell.openExternal(navigationUrl)
}
})
})
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// On certificate error we disable default behaviour (stop loading the page)
// and we then say "it is all fine - true" to the callback
const parsedUrl = new URL(url);
if (parsedUrl.origin == PARSED_BASE_URL.origin) {
event.preventDefault();
callback(true);
}
});
app.on('window-all-closed', () => {
if (!is.macos) {
app.quit();
}
});
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
(async () => {
await app.whenReady();
Menu.setApplicationMenu(menu);
mainWindow = await createMainWindow();
})();