Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto minimize on auto start + dbus #282

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/main/autoStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,51 @@ import { join } from "path";

interface AutoStart {
isEnabled(): boolean;
wasAutoStarted(): boolean;
enable(): void;
disable(): void;
}

const isFlatpak = process.env.FLATPAK_ID !== undefined;

function makeAutoStartLinux(): AutoStart {
const configDir = process.env.XDG_CONFIG_HOME || join(process.env.HOME!, ".config");
const dir = join(configDir, "autostart");
const file = join(dir, "vencord.desktop");

return {
isEnabled: () => existsSync(file),
isEnabled: () => existsSync(file), // TODO: flatpak
wasAutoStarted: () => process.argv.includes("--autostart"),
enable() {
const desktopFile = `
if (isFlatpak) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this logic is good. why not unconditionally first try using the portal and if it doesn't work, use the desktop fallback instead? lots of DEs implement the portal so it should work on those even without flatpak, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i havent tested gdbus yet fully so this is just placeholder code

} else {
const desktopFile = `
[Desktop Entry]
Type=Application
Version=1.0
Name=Vencord
Comment=Vencord autostart script
Exec=${process.execPath}
Exec=${process.execPath} --autostart
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this would be slightly more self explanatory

Suggested change
Exec=${process.execPath} --autostart
Exec=${process.execPath} --is-autostart=true

Terminal=false
StartupNotify=false
`.trim();

mkdirSync(dir, { recursive: true });
writeFileSync(file, desktopFile);
mkdirSync(dir, { recursive: true });
writeFileSync(file, desktopFile);
}
},
disable: () => rmSync(file, { force: true })
disable: () => {
if (isFlatpak) {
} else {
rmSync(file, { force: true });
}
}
};
}

const autoStartWindowsMac: AutoStart = {
isEnabled: () => app.getLoginItemSettings().openAtLogin,
wasAutoStarted: () => app.getLoginItemSettings().wasOpenedAtLogin,
enable: () => app.setLoginItemSettings({ openAtLogin: true }),
disable: () => app.setLoginItemSettings({ openAtLogin: false })
};
Expand Down
7 changes: 4 additions & 3 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { SettingsStore } from "shared/utils/SettingsStore";
import { ICON_PATH } from "../shared/paths";
import { createAboutWindow } from "./about";
import { initArRPC } from "./arrpc";
import { autoStart } from "./autoStart";
import {
DATA_DIR,
DEFAULT_HEIGHT,
Expand Down Expand Up @@ -442,8 +443,8 @@ function createMainWindow() {
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));

export async function createWindows() {
const { startMinimized } = Settings.store;
const splash = createSplashWindow(startMinimized);
const shouldStartMinimized = Settings.store.startMinimized && autoStart.wasAutoStarted();
const splash = createSplashWindow(shouldStartMinimized);
// SteamOS letterboxes and scales it terribly, so just full screen it
if (isDeckGameMode) splash.setFullScreen(true);
await ensureVencordFiles();
Expand All @@ -454,7 +455,7 @@ export async function createWindows() {
mainWin.webContents.on("did-finish-load", () => {
splash.destroy();

if (!startMinimized || isDeckGameMode) mainWin!.show();
if (!shouldStartMinimized || isDeckGameMode) mainWin!.show();

if (isDeckGameMode) {
// always use entire display
Expand Down
Loading