aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
blob: 0babcea39a06ad82d9540a5abaedc0291317f9bf (plain)
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
const fs = require("fs");
const path = require("path");
const { app, dialog, ipcMain, BrowserWindow } = require("electron");

function start() {
	win = new BrowserWindow({
		width: 500,
		height: 115,
		show: false,
		title: "Viper",
		webPreferences: {
			nodeIntegration: true,
			contextIsolation: false,
		},
	}); win.openDevTools()

	win.removeMenu();
	win.loadFile(__dirname + "/app/index.html");
	win.webContents.once("dom-ready", () => {win.show()});

	ipcMain.on("setpath", (event) => {
		dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
			fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({path: res.filePaths[0]}))

			win.webContents.send("newpath", res.filePaths[0]);
		}).catch(err => {console.error(err)})
	})
}

app.on("ready", () => {
	process.chdir(app.getPath("appData"));
	app.setPath("userData", path.join(app.getPath("cache"), app.name));
	start();
})