-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.old.js
129 lines (102 loc) · 3.49 KB
/
index.old.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
/*const { app, BrowserWindow, shell } = require('electron')
const { spawn } = require("child_process")
const path = require("path")
require("ansicolor").nice*/
import fs from "fs";
import { app, BrowserWindow, shell } from 'electron';
import { spawn } from "child_process";
import * as path from "path";
import * as ansicolor from "ansicolor";
ansicolor.nice
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
if (!fs.existsSync(path.join(__dirname, "main/cache/raw_guests"))){
fs.mkdirSync(path.join(__dirname, "main/cache/raw_guests"), { recursive: true });
}
function runServer() {
return new Promise((resolve, reject) => {
let child = spawn("node", [path.join(__dirname, "/main/server.js")])
let resolved = false
child.stdout.once("data", (data) => {
data = data.toString()
if (data.startsWith("listening")) {
let port = data.split("|")[1]
resolved = true
resolve({ server: child, port })
} else {
if (!resolved) {
resolved = true
reject(data)
} else {
console.log(`INFO: `.blue + data.trim())
}
}
})
child.stderr.on("data", (data) => {
data = data.toString()
console.log(`ERROR: `.red + data)
})
child.on('close', (code, signal) => {
process.exit(0)
});
})
}
runServer().then((srv_data) => {
let { server, port } = srv_data
server.stdout.on("data", (data) => {
data = data.toString().split("\n")
let navigated = false;
for(let dataLine of data){
dataLine = dataLine.trim()
if(dataLine.length == 0) continue;
if (dataLine.startsWith("navigate|")) {
if(navigated) continue;
let url = dataLine.split("|")[1]
shell.openExternal(url);
navigated = true;
} else {
console.log(`INFO: `.blue + dataLine.trim())
}
}
})
const createWindow = () => {
const win = new BrowserWindow({
title: "Youtube-View-Bot",
autoHideMenuBar: true,
//icon: path.join(__dirname, "/main/static/favicon.ico"),
webPreferences: {
nodeIntegration: false,
nodeIntegrationInWorker: false,
}
})
win.webContents.on('will-navigate', function (e, url) {
if (url.includes("patreon") || url.includes("github") || url.includes("paypal") || url.includes("bloxxy.net") || url.includes("iproyal.com") || url.includes("discord.")) {
e.preventDefault();
shell.openExternal(url);
}
});
win.maximize();
win.loadURL(`http://localhost:${port}`).then(() => {
win.reload()
})
}
app.on('window-all-closed', async () => {
await server.kill("SIGINT")
process.exit(0)
/*if (process.platform !== 'darwin') {
await app.quit()
console.time("start")
await server.kill("SIGINT")
console.timeEnd("start")
process.exit(0)
}*/
})
app.whenReady().then(() => {
createWindow()
})
})
process.stdin.on("data", (data) => {
data = data.toString()
//console.log(data.toString())
})