Vesktop/src/main/firstLaunch.ts

74 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-06-21 14:39:41 +02:00
/*
* SPDX-License-Identifier: GPL-3.0
2023-07-13 19:03:13 +02:00
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
2023-06-21 14:39:41 +02:00
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { app } from "electron";
import { BrowserWindow } from "electron/main";
import { copyFileSync, mkdirSync, readdirSync } from "fs";
import { join } from "path";
import { SplashProps } from "shared/browserWinProperties";
import { ICON_PATH, VIEW_DIR } from "shared/paths";
2023-06-21 14:39:41 +02:00
2023-06-21 16:52:28 +02:00
import { autoStart } from "./autoStart";
2023-06-21 14:39:41 +02:00
import { DATA_DIR } from "./constants";
import { createWindows } from "./mainWindow";
import { Settings, State } from "./settings";
2023-06-26 00:41:52 +02:00
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
2023-06-21 14:39:41 +02:00
2023-06-21 16:52:28 +02:00
interface Data {
minimizeToTray: boolean;
discordBranch: "stable" | "canary" | "ptb";
autoStart: boolean;
importSettings: boolean;
richPresence: boolean;
2023-06-21 16:52:28 +02:00
}
2023-06-21 14:39:41 +02:00
export function createFirstLaunchTour() {
const win = new BrowserWindow({
...SplashProps,
frame: true,
autoHideMenuBar: true,
height: 470,
width: 550,
icon: ICON_PATH
2023-06-21 14:39:41 +02:00
});
2023-06-26 00:41:52 +02:00
makeLinksOpenExternally(win);
2023-06-23 17:20:54 +02:00
win.loadFile(join(VIEW_DIR, "first-launch.html"));
2023-06-21 14:39:41 +02:00
win.webContents.addListener("console-message", (_e, _l, msg) => {
if (msg === "cancel") return app.exit();
if (!msg.startsWith("form:")) return;
2023-06-21 16:52:28 +02:00
const data = JSON.parse(msg.slice(5)) as Data;
2023-06-21 14:39:41 +02:00
State.store.firstLaunch = false;
2023-06-21 14:39:41 +02:00
Settings.store.minimizeToTray = data.minimizeToTray;
Settings.store.discordBranch = data.discordBranch;
Settings.store.arRPC = data.richPresence;
2023-06-21 14:39:41 +02:00
2023-06-21 16:52:28 +02:00
if (data.autoStart) autoStart.enable();
2023-06-21 14:39:41 +02:00
if (data.importSettings) {
const from = join(app.getPath("userData"), "..", "Vencord", "settings");
const to = join(DATA_DIR, "settings");
try {
const files = readdirSync(from);
mkdirSync(to, { recursive: true });
for (const file of files) {
copyFileSync(join(from, file), join(to, file));
}
} catch (e) {
console.error("Failed to import settings:", e);
}
}
win.close();
createWindows();
});
}