-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
100 lines (89 loc) · 3.53 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
94
95
96
97
98
99
100
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('node:path')
const fs = require('fs')
const vanillajscream = require('vanillajscream')
const test = new vanillajscream.render.component()
const test2 = new vanillajscream.render.webpage()
test.setHtml("<h1>Hello World</h1>")
test2.setBody(test.render())
console.log(test2.render())
/**
* Creates a folder if it does not exist.
*
* @param {string} path - The path of the folder to create
* @returns {void}
*/
function createFolder(path) {
if (!fs.existsSync(path)) {
fs.mkdirSync(path)
}
}
/**
* Copies a file from one location to another.
*
* @param {string} path - The path to the source file
* @param {string} dist - The path to the destination file
* @returns {void}
*/
function copyFile(path, dist) {
fs.copyFileSync(path, dist)
}
/**
* When the app is ready, create a new browser window, load the index.html and
* create the directories if they do not exist.
*/
app.on('ready', () => {
/**
* The preload script is loaded before the renderer (index.html) is loaded.
* The preload script exposes an API in the "electronAPI" object that can be
* accessed in the renderer.
*/
let win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } })
let erun = false
/**
* The home directory is where the files will be downloaded.
* Check if the directories exist, if not, create them.
*/
const os = require('os')
const homeDirectory = os.homedir()
createFolder(path.join(homeDirectory, './eaglergrab'))
createFolder(path.join(homeDirectory, './eaglergrab', 'versions'))
copyFile(path.join(__dirname, 'binaries', "latest.html"), path.join(homeDirectory, './eaglergrab', 'versions', 'latest.html'))
copyFile(path.join(__dirname, 'binaries', "dev.html"), path.join(homeDirectory, './eaglergrab', 'versions', 'dev.html'))
copyFile(path.join(__dirname, 'binaries', "arch.html"), path.join(homeDirectory, './eaglergrab', 'versions', 'arch.html'))
copyFile(path.join(__dirname, 'binaries', "settings.js"), path.join(homeDirectory, './eaglergrab', 'versions', 'settings.js'))
ipcMain.handle("start", () => {
win.loadFile(path.join(homeDirectory, "./eaglergrab", "versions", "latest.html"))
erun = true
win.on("close", (e) => {
e.preventDefault()
let copy = win
win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } })
copy.destroy()
win.loadFile("index.html")
})
})
ipcMain.handle("devbuild", () => {
win.loadFile(path.join(homeDirectory, "./eaglergrab", "versions", "dev.html"))
erun = true
win.on("close", (e) => {
e.preventDefault()
let copy = win
win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } })
copy.destroy()
win.loadFile("index.html")
})
})
ipcMain.handle("arch", () => {
win.loadFile(path.join(homeDirectory, "./eaglergrab", "versions", "arch.html"))
erun = true
win.on("close", (e) => {
e.preventDefault()
let copy = win
win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } })
copy.destroy()
win.loadFile("index.html")
})
})
win.loadFile('index.html')
})