mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 05:35:09 +00:00
a
This commit is contained in:
parent
d7bc56660b
commit
b0dcfd84da
5 changed files with 68 additions and 6 deletions
|
@ -63,6 +63,11 @@ await Promise.all([
|
||||||
outfile: "dist/js/preload.js",
|
outfile: "dist/js/preload.js",
|
||||||
footer: { js: "//# sourceURL=VCDPreload" }
|
footer: { js: "//# sourceURL=VCDPreload" }
|
||||||
}),
|
}),
|
||||||
|
createContext({
|
||||||
|
...NodeCommonOpts,
|
||||||
|
entryPoints: ["src/preload/splash.ts"],
|
||||||
|
outfile: "dist/js/splash_preload.js"
|
||||||
|
}),
|
||||||
createContext({
|
createContext({
|
||||||
...CommonOpts,
|
...CommonOpts,
|
||||||
globalName: "Vesktop",
|
globalName: "Vesktop",
|
||||||
|
|
|
@ -39,7 +39,7 @@ import {
|
||||||
import { darwinURL } from "./index";
|
import { darwinURL } from "./index";
|
||||||
import { sendRendererCommand } from "./ipcCommands";
|
import { sendRendererCommand } from "./ipcCommands";
|
||||||
import { Settings, State, VencordSettings } from "./settings";
|
import { Settings, State, VencordSettings } from "./settings";
|
||||||
import { createSplashWindow } from "./splash";
|
import { createSplashWindow, updateSplashMessage } 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 { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader";
|
||||||
|
@ -475,17 +475,36 @@ function createMainWindow() {
|
||||||
win.webContents.setUserAgent(BrowserUserAgent);
|
win.webContents.setUserAgent(BrowserUserAgent);
|
||||||
|
|
||||||
// if the open-url event is fired (in index.ts) while starting up, darwinURL will be set. If not fall back to checking the process args (which Windows and Linux use for URI calling.)
|
// if the open-url event is fired (in index.ts) while starting up, darwinURL will be set. If not fall back to checking the process args (which Windows and Linux use for URI calling.)
|
||||||
|
// win.webContents.session.clearCache().then(() => {
|
||||||
loadUrl(darwinURL || process.argv.find(arg => arg.startsWith("discord://")));
|
loadUrl(darwinURL || process.argv.find(arg => arg.startsWith("discord://")));
|
||||||
|
// });
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
|
||||||
|
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
const eventCar = new EventEmitter();
|
||||||
|
|
||||||
export function loadUrl(uri: string | undefined) {
|
export function loadUrl(uri: string | undefined) {
|
||||||
const branch = Settings.store.discordBranch;
|
const branch = Settings.store.discordBranch;
|
||||||
const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
|
const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
|
||||||
mainWin.loadURL(`https://${subdomain}discord.com/${uri ? new URL(uri).pathname.slice(1) || "app" : "app"}`);
|
|
||||||
|
// we do not rely on 'did-finish-load' because it fires even if loadURL fails which triggers early detruction of the splash
|
||||||
|
mainWin
|
||||||
|
.loadURL(`https://${subdomain}discord.com/${uri ? new URL(uri).pathname.slice(1) || "app" : "app"}`)
|
||||||
|
.then(() => eventCar.emit("app-loaded"))
|
||||||
|
.catch(error => retryUrl(error.url, error.code));
|
||||||
|
}
|
||||||
|
|
||||||
|
const retryDelay = 1000;
|
||||||
|
function retryUrl(url: string, description: string) {
|
||||||
|
console.log(`retrying in ${retryDelay}ms`);
|
||||||
|
updateSplashMessage(description);
|
||||||
|
setTimeout(() => {
|
||||||
|
loadUrl(url);
|
||||||
|
}, retryDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createWindows() {
|
export async function createWindows() {
|
||||||
|
@ -504,7 +523,7 @@ export async function createWindows() {
|
||||||
|
|
||||||
mainWin = createMainWindow();
|
mainWin = createMainWindow();
|
||||||
|
|
||||||
mainWin.webContents.on("did-finish-load", () => {
|
eventCar.on("app-loaded", () => {
|
||||||
splash?.destroy();
|
splash?.destroy();
|
||||||
|
|
||||||
if (!startMinimized) {
|
if (!startMinimized) {
|
||||||
|
@ -527,6 +546,8 @@ export async function createWindows() {
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWin.webContents.on("did-navigate", (_, url: string, responseCode: number) => {
|
mainWin.webContents.on("did-navigate", (_, url: string, responseCode: number) => {
|
||||||
|
if (!splash?.isDestroyed()) updateSplashMessage(""); // clear the message
|
||||||
|
|
||||||
// check url to ensure app doesn't loop
|
// check url to ensure app doesn't loop
|
||||||
if (responseCode >= 300 && new URL(url).pathname !== `/app`) {
|
if (responseCode >= 300 && new URL(url).pathname !== `/app`) {
|
||||||
loadUrl(undefined);
|
loadUrl(undefined);
|
||||||
|
|
|
@ -11,11 +11,14 @@ import { ICON_PATH, VIEW_DIR } from "shared/paths";
|
||||||
|
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
|
|
||||||
|
let splash: BrowserWindow | undefined;
|
||||||
|
|
||||||
export function createSplashWindow(startMinimized = false) {
|
export function createSplashWindow(startMinimized = false) {
|
||||||
const splash = new BrowserWindow({
|
splash = new BrowserWindow({
|
||||||
...SplashProps,
|
...SplashProps,
|
||||||
icon: ICON_PATH,
|
icon: ICON_PATH,
|
||||||
show: !startMinimized
|
show: !startMinimized,
|
||||||
|
webPreferences: { preload: join(__dirname, "splash_preload.js") }
|
||||||
});
|
});
|
||||||
|
|
||||||
splash.loadFile(join(VIEW_DIR, "splash.html"));
|
splash.loadFile(join(VIEW_DIR, "splash.html"));
|
||||||
|
@ -37,3 +40,7 @@ export function createSplashWindow(startMinimized = false) {
|
||||||
|
|
||||||
return splash;
|
return splash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateSplashMessage(message: string) {
|
||||||
|
if (splash && !splash.isDestroyed()) splash.webContents.send("update-splash-message", message);
|
||||||
|
}
|
||||||
|
|
11
src/preload/splash.ts
Normal file
11
src/preload/splash.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||||
|
* Copyright (c) 2025 Vendicated and Vesktop contributors
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { contextBridge, ipcRenderer } = require("electron/renderer");
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld("electronAPI", {
|
||||||
|
onUpdateMessage: callback => ipcRenderer.on("update-splash-message", (_event, message: string) => callback(message))
|
||||||
|
});
|
|
@ -20,6 +20,14 @@
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
top: 70%;
|
||||||
|
word-break: break-word;
|
||||||
|
padding: 0 16px;
|
||||||
|
position: absolute;
|
||||||
|
font-size: 14px
|
||||||
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +40,7 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body style="overflow: hidden;">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<img
|
<img
|
||||||
draggable="false"
|
draggable="false"
|
||||||
|
@ -41,5 +49,15 @@
|
||||||
role="presentation"
|
role="presentation"
|
||||||
/>
|
/>
|
||||||
<p>Loading Vesktop...</p>
|
<p>Loading Vesktop...</p>
|
||||||
|
<p class="message"></p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
window.onload = () => {
|
||||||
|
const messageElement = document.querySelector('.message');
|
||||||
|
window.electronAPI.onUpdateMessage((message) => {
|
||||||
|
messageElement.textContent = message;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue