Compare commits
4 commits
main
...
vencord-as
Author | SHA1 | Date | |
---|---|---|---|
|
358206a1c5 | ||
|
ac28db6c4d | ||
|
94a0c4dc10 | ||
|
02f386db2d |
6 changed files with 26 additions and 47 deletions
|
@ -22,7 +22,7 @@ const NodeCommonOpts: BuildOptions = {
|
||||||
...CommonOpts,
|
...CommonOpts,
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
platform: "node",
|
platform: "node",
|
||||||
external: ["electron"],
|
external: ["electron", "original-fs"],
|
||||||
target: ["esnext"],
|
target: ["esnext"],
|
||||||
define: {
|
define: {
|
||||||
IS_DEV: JSON.stringify(isDev)
|
IS_DEV: JSON.stringify(isDev)
|
||||||
|
|
|
@ -47,9 +47,10 @@ export const VENCORD_THEMES_DIR = join(DATA_DIR, "themes");
|
||||||
|
|
||||||
// needs to be inline require because of circular dependency
|
// needs to be inline require because of circular dependency
|
||||||
// as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised
|
// as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised
|
||||||
export const VENCORD_FILES_DIR =
|
export const VENCORD_DIR = (() => {
|
||||||
(require("./settings") as typeof import("./settings")).State.store.vencordDir ||
|
const { State } = require("./settings") as typeof import("./settings");
|
||||||
join(SESSION_DATA_DIR, "vencordFiles");
|
return State.store.vencordDir ? join(State.store.vencordDir, "vesktop") : join(SESSION_DATA_DIR, "vencord.asar");
|
||||||
|
})();
|
||||||
|
|
||||||
export const USER_AGENT = `Vesktop/${app.getVersion()} (https://github.com/Vencord/Vesktop)`;
|
export const USER_AGENT = `Vesktop/${app.getVersion()} (https://github.com/Vencord/Vesktop)`;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { debounce } from "shared/utils/debounce";
|
||||||
import { IpcEvents } from "../shared/IpcEvents";
|
import { IpcEvents } from "../shared/IpcEvents";
|
||||||
import { setBadgeCount } from "./appBadge";
|
import { setBadgeCount } from "./appBadge";
|
||||||
import { autoStart } from "./autoStart";
|
import { autoStart } from "./autoStart";
|
||||||
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
|
import { VENCORD_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
|
||||||
import { mainWin } from "./mainWindow";
|
import { mainWin } from "./mainWindow";
|
||||||
import { Settings, State } from "./settings";
|
import { Settings, State } from "./settings";
|
||||||
import { handle, handleSync } from "./utils/ipcWrappers";
|
import { handle, handleSync } from "./utils/ipcWrappers";
|
||||||
|
@ -25,10 +25,8 @@ import { PopoutWindows } from "./utils/popout";
|
||||||
import { isDeckGameMode, showGamePage } from "./utils/steamOS";
|
import { isDeckGameMode, showGamePage } from "./utils/steamOS";
|
||||||
import { isValidVencordInstall } from "./utils/vencordLoader";
|
import { isValidVencordInstall } from "./utils/vencordLoader";
|
||||||
|
|
||||||
handleSync(IpcEvents.GET_VENCORD_PRELOAD_FILE, () => join(VENCORD_FILES_DIR, "vencordDesktopPreload.js"));
|
handleSync(IpcEvents.GET_VENCORD_PRELOAD_FILE, () => join(VENCORD_DIR, "preload.js"));
|
||||||
handleSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT, () =>
|
handleSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT, () => readFileSync(join(VENCORD_DIR, "renderer.js"), "utf-8"));
|
||||||
readFileSync(join(VENCORD_FILES_DIR, "vencordDesktopRenderer.js"), "utf-8")
|
|
||||||
);
|
|
||||||
|
|
||||||
handleSync(IpcEvents.GET_RENDERER_SCRIPT, () => readFileSync(join(__dirname, "renderer.js"), "utf-8"));
|
handleSync(IpcEvents.GET_RENDERER_SCRIPT, () => readFileSync(join(__dirname, "renderer.js"), "utf-8"));
|
||||||
handleSync(IpcEvents.GET_RENDERER_CSS_FILE, () => join(__dirname, "renderer.css"));
|
handleSync(IpcEvents.GET_RENDERER_CSS_FILE, () => join(__dirname, "renderer.css"));
|
||||||
|
|
|
@ -34,13 +34,13 @@ import {
|
||||||
MessageBoxChoice,
|
MessageBoxChoice,
|
||||||
MIN_HEIGHT,
|
MIN_HEIGHT,
|
||||||
MIN_WIDTH,
|
MIN_WIDTH,
|
||||||
VENCORD_FILES_DIR
|
VENCORD_DIR
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import { Settings, State, VencordSettings } from "./settings";
|
import { Settings, State, VencordSettings } from "./settings";
|
||||||
import { createSplashWindow } from "./splash";
|
import { createSplashWindow } from "./splash";
|
||||||
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||||
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
||||||
import { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader";
|
import { downloadVencordAsar, ensureVencordFiles } from "./utils/vencordLoader";
|
||||||
|
|
||||||
let isQuitting = false;
|
let isQuitting = false;
|
||||||
let tray: Tray;
|
let tray: Tray;
|
||||||
|
@ -93,7 +93,7 @@ function initTray(win: BrowserWindow) {
|
||||||
{
|
{
|
||||||
label: "Repair Vencord",
|
label: "Repair Vencord",
|
||||||
async click() {
|
async click() {
|
||||||
await downloadVencordFiles();
|
await downloadVencordAsar();
|
||||||
app.relaunch();
|
app.relaunch();
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ function initMenuBar(win: BrowserWindow) {
|
||||||
{
|
{
|
||||||
label: "Force Update Vencord",
|
label: "Force Update Vencord",
|
||||||
async click() {
|
async click() {
|
||||||
await downloadVencordFiles();
|
await downloadVencordAsar();
|
||||||
app.relaunch();
|
app.relaunch();
|
||||||
app.quit();
|
app.quit();
|
||||||
},
|
},
|
||||||
|
@ -465,7 +465,7 @@ function createMainWindow() {
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
const runVencordMain = once(() => require(VENCORD_DIR));
|
||||||
|
|
||||||
export async function createWindows() {
|
export async function createWindows() {
|
||||||
const startMinimized = process.argv.includes("--start-minimized");
|
const startMinimized = process.argv.includes("--start-minimized");
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createWriteStream } from "fs";
|
import { createWriteStream } from "original-fs";
|
||||||
import { Readable } from "stream";
|
import { Readable } from "stream";
|
||||||
import { pipeline } from "stream/promises";
|
import { pipeline } from "stream/promises";
|
||||||
import { setTimeout } from "timers/promises";
|
import { setTimeout } from "timers/promises";
|
||||||
|
|
|
@ -4,22 +4,14 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { mkdirSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import { access, constants as FsConstants } from "fs/promises";
|
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
import { USER_AGENT, VENCORD_FILES_DIR } from "../constants";
|
import { USER_AGENT, VENCORD_DIR } from "../constants";
|
||||||
import { downloadFile, fetchie } from "./http";
|
import { downloadFile, fetchie } from "./http";
|
||||||
|
|
||||||
const API_BASE = "https://api.github.com";
|
const API_BASE = "https://api.github.com";
|
||||||
|
|
||||||
export const FILES_TO_DOWNLOAD = [
|
|
||||||
"vencordDesktopMain.js",
|
|
||||||
"vencordDesktopPreload.js",
|
|
||||||
"vencordDesktopRenderer.js",
|
|
||||||
"vencordDesktopRenderer.css"
|
|
||||||
];
|
|
||||||
|
|
||||||
export interface ReleaseData {
|
export interface ReleaseData {
|
||||||
name: string;
|
name: string;
|
||||||
tag_name: string;
|
tag_name: string;
|
||||||
|
@ -43,33 +35,21 @@ export async function githubGet(endpoint: string) {
|
||||||
return fetchie(API_BASE + endpoint, opts, { retryOnNetworkError: true });
|
return fetchie(API_BASE + endpoint, opts, { retryOnNetworkError: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadVencordFiles() {
|
export async function downloadVencordAsar() {
|
||||||
const release = await githubGet("/repos/Vendicated/Vencord/releases/latest");
|
await downloadFile(
|
||||||
|
"https://github.com/Vendicated/Vencord/releases/latest/download/vesktop.asar",
|
||||||
const { assets }: ReleaseData = await release.json();
|
VENCORD_DIR,
|
||||||
|
{},
|
||||||
await Promise.all(
|
{ retryOnNetworkError: true }
|
||||||
assets
|
|
||||||
.filter(({ name }) => FILES_TO_DOWNLOAD.some(f => name.startsWith(f)))
|
|
||||||
.map(({ name, browser_download_url }) =>
|
|
||||||
downloadFile(browser_download_url, join(VENCORD_FILES_DIR, name), {}, { retryOnNetworkError: true })
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const existsAsync = (path: string) =>
|
export function isValidVencordInstall(dir: string) {
|
||||||
access(path, FsConstants.F_OK)
|
return existsSync(join(dir, "vesktop/main.js"));
|
||||||
.then(() => true)
|
|
||||||
.catch(() => false);
|
|
||||||
|
|
||||||
export async function isValidVencordInstall(dir: string) {
|
|
||||||
return Promise.all(FILES_TO_DOWNLOAD.map(f => existsAsync(join(dir, f)))).then(arr => !arr.includes(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensureVencordFiles() {
|
export async function ensureVencordFiles() {
|
||||||
if (await isValidVencordInstall(VENCORD_FILES_DIR)) return;
|
if (existsSync(VENCORD_DIR)) return;
|
||||||
|
|
||||||
mkdirSync(VENCORD_FILES_DIR, { recursive: true });
|
await downloadVencordAsar();
|
||||||
|
|
||||||
await downloadVencordFiles();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue