Skip to content

Commit

Permalink
Merge pull request #1263 from buttercup/fix/auto-launch
Browse files Browse the repository at this point in the history
Fix auto launch for linux
  • Loading branch information
perry-mitchell authored Dec 14, 2023
2 parents 6bc4046 + 85ac971 commit c2f168e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 26 deletions.
78 changes: 54 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@
"ms": "^2.1.3",
"nested-property": "^4.0.0",
"os-locale": "^5.0.0",
"path-exists": "^5.0.0",
"pify": "^5.0.0",
"stacktracey": "^2.1.7",
"statuses": "^2.0.1",
"untildify": "^5.0.0",
"webdav": "^5.3.0",
"zod": "^3.22.4"
},
Expand Down
1 change: 0 additions & 1 deletion source/main/actions/appMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { handleConfigUpdate } from "./config";
import { t } from "../../shared/i18n/trans";
import { isOSX } from "../../shared/library/platform";
import { getIconForProvider, getNativeImageMenuIcon } from "../library/icons";
import { Preferences } from "../types";
import { logErr } from "../library/log";

async function getContextMenu(): Promise<Menu> {
Expand Down
2 changes: 1 addition & 1 deletion source/main/library/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file updated automatically: changes made here will be overwritten!

export const VERSION = "2.23.1";
export const VERSION = "2.24.0";
38 changes: 38 additions & 0 deletions source/main/services/launch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
import path from "node:path";
import fs from "node:fs/promises";
import { app } from "electron";
import untildify from "untildify";
import { pathExists } from "path-exists";
import { isLinux } from "../../shared/library/platform";

const LINUX_AUTOSTART_DIR = "~/.config/autostart";
const LINUX_DESKTOP = `
[Desktop Entry]
Type=Application
Version=1.0
Name={{APP_NAME}}
Comment={{APP_NAME}} startup script
Exec={{APP_PATH}} --autostart
StartupNotify=false
Terminal=false
`;

export async function setStartWithSession(enable: boolean): Promise<void> {
if (isLinux()) {
await setStartWithSessionLinux(enable);
} else {
await setStartWithSessionNative(enable);
}
}

async function setStartWithSessionLinux(enable: boolean): Promise<void> {
const autostartPath = path.join(untildify(LINUX_AUTOSTART_DIR), "buttercup.desktop");
const isEnabled = await pathExists(autostartPath);
if (enable && !isEnabled) {
const desktop = LINUX_DESKTOP.trim()
.replace(/{{APP_NAME}}/g, "Buttercup")
.replace(/{{APP_PATH}}/g, process.execPath);
await fs.writeFile(autostartPath, desktop);
} else if (!enable && isEnabled) {
await fs.unlink(autostartPath);
}
}

async function setStartWithSessionNative(enable: boolean): Promise<void> {
const isEnabled = app.getLoginItemSettings().openAtLogin;
if (enable && !isEnabled) {
app.setLoginItemSettings({
Expand Down

0 comments on commit c2f168e

Please sign in to comment.