-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
93 lines (84 loc) · 2.7 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
const {
app,
ipcMain,
BrowserWindow,
nativeTheme,
shell,
} = require('electron');
const fetch = require("node-fetch")
const fs = require('fs');
const path = require('path');
let argv = process.argv
let ip_info;
(async function() {
if (!argv[2] || argv[2].trim() == "") return app.quit();
let req = await fetch("https://ipwho.is/" + argv[2].trim());
ip_info = await req.json();
if (!ip_info.success) {
//console.log(ip_info);
shell.openExternal("https://whatismyipaddress.com/ip/" + argv[2]).then(() => {
app.quit();
});
//process.exit(1);
}
let cc = ip_info.country_code.toLowerCase();
if (!fs.existsSync(path.join(__dirname, 'cache', `${cc}.svg`))) {
const response = await fetch(`https://countryflagsapi.com/svg/${cc}`);
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
fs.createWriteStream(path.join(__dirname, 'cache', `${cc}.svg`)).write(buffer);
}
})();
const createMainWindow = () => {
nativeTheme.themeSource = 'dark' // force light mode titlebar
var mainWindow;
mainWindow = new BrowserWindow({
width: 500, //521
height: 365, //365
show: false,
backgroundColor: "#363737",
webPreferences: {
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
devTools: true, //isDev
contextIsolation: false,
enableRemoteModule: true,
preload: path.join(__dirname, "preload.js"),
},
closable: true,
maximizable: false,
resizable: false
});
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: Object.fromEntries(Object.entries(details.responseHeaders).filter(header => !/x-frame-options/i.test(header[0])))
});
});
const startURL = `file://${path.join(__dirname, 'template.html')}`;
mainWindow.loadURL(startURL);
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('close', (e) => {
app.exit();
});
mainWindow.on('closed', () => {
mainWindow = null;
app.exit();
});
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
require('electron').shell.openExternal(url);
});
};
ipcMain.handle('getIPInfo', () => {
return ip_info;
});
app.whenReady().then(() => {
createMainWindow();
app.on('activate', () => {
if (!BrowserWindow.getAllWindows().length) {
createMainWindow();
}
});
});