summaryrefslogtreecommitdiff
path: root/launcher/client/main.js
blob: 61c6a340d0a8670f7a46a20a29405355c815e37f (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
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
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
const path = require('path');
const fs = require("fs");
const os = require("os");

let localchatDataRoot = (os.platform() === "win32" ? os.homedir() + "/AppData/Roaming" : (os.platform() === "darwin" ? os.homedir() + "/Library/Application Support" : os.homedir())) + "/.localchat";

if (!fs.existsSync(localchatDataRoot)) fs.mkdirSync(localchatDataRoot);
if (!fs.existsSync(localchatDataRoot + "/client")) fs.mkdirSync(localchatDataRoot + "/client");
if (!fs.existsSync(localchatDataRoot + "/client/session")) fs.mkdirSync(localchatDataRoot + "/client/session");
if (!fs.existsSync(localchatDataRoot + "/client/data")) fs.mkdirSync(localchatDataRoot + "/client/data");
if (!fs.existsSync(localchatDataRoot + "/client/logs")) fs.mkdirSync(localchatDataRoot + "/client/logs");

if (fs.existsSync(localchatDataRoot + "/client/launcher")) {
    process.chdir(localchatDataRoot + "/client/launcher");
    require(localchatDataRoot + "/client/launcher/main.js");
}

app.setPath("userData", localchatDataRoot + "/client/data");
app.setPath("sessionData", localchatDataRoot + "/client/session");
app.setAppLogsPath(localchatDataRoot + "/client/logs");

require('@electron/remote/main').initialize();

process.argv = process.argv.filter(i => !i.endsWith("main.js") && i !== ".");

const createWindow = () => {
    global.loaderWindow = new BrowserWindow({
        width: 256,
        height: 300,
        icon: require('os').platform() ? "./icon.icns" : "./icon.ico",
        resizable: false,
        maximizable: false,
        show: false,
        minimizable: false,
        disableAutoHideCursor: true,
        backgroundColor: "#111111",
        darkTheme: true,
        fullscreenable: false,
        frame: false,
        autoHideMenuBar: true,
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false
        }
    });

    require("@electron/remote/main").enable(loaderWindow.webContents);
    loaderWindow.loadFile('./index.html');
    loaderWindow.setContentProtection(true);

    ipcMain.on('start', (_, path) => {
        process.chdir(path);
        global._localchatPath = path;
        global._localchatLauncherVersion = app.getVersion();
        require(path + "/main.js");
    });

    loaderWindow.once("ready-to-show", () => {
        loaderWindow.show();

        if (process.argv[1]) {
            loaderWindow.send("local", process.argv[1]);
        } else {
            loaderWindow.send("download", require('fs').existsSync(app.getPath("userData") + "/LocalchatBetaChannel"));
        }
    });
}

app.whenReady().then(() => {
    createWindow();
});

global.restart = () => {
    app.relaunch();
    app.exit();
}