diff --git a/package-lock.json b/package-lock.json index 8e8e82ab..eb970e94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,9 +37,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" }, @@ -9323,15 +9325,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/find-cache-dir/node_modules/path-exists": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", - "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", - "dev": true, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - } - }, "node_modules/find-cache-dir/node_modules/pkg-dir": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-7.0.0.tgz", @@ -9372,6 +9365,15 @@ "node": ">=8" } }, + "node_modules/find-up/node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/find-versions": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/find-versions/-/find-versions-4.0.0.tgz", @@ -10359,6 +10361,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/husky/node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/husky/node_modules/pkg-dir": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", @@ -15277,12 +15288,11 @@ "dev": true }, "node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", + "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", "engines": { - "node": ">=8" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" } }, "node_modules/path-is-absolute": { @@ -19001,6 +19011,14 @@ "node": ">= 0.8" } }, + "node_modules/untildify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/untildify/-/untildify-5.0.0.tgz", + "integrity": "sha512-bOgQLUnd2G5rhzaTvh1VCI9Fo6bC5cLTpH17T5aFfamyXFYDbbdzN6IXdeoc3jBS7T9hNTmJtYUzJCJ2Xlc9gA==", + "engines": { + "node": ">=16" + } + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -27291,12 +27309,6 @@ "p-limit": "^4.0.0" } }, - "path-exists": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", - "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", - "dev": true - }, "pkg-dir": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-7.0.0.tgz", @@ -27322,6 +27334,14 @@ "requires": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" + }, + "dependencies": { + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + } } }, "find-versions": { @@ -28067,6 +28087,12 @@ "p-limit": "^3.0.2" } }, + "path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true + }, "pkg-dir": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz", @@ -31775,10 +31801,9 @@ } }, "path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", + "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==" }, "path-is-absolute": { "version": "1.0.1", @@ -34620,6 +34645,11 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" }, + "untildify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/untildify/-/untildify-5.0.0.tgz", + "integrity": "sha512-bOgQLUnd2G5rhzaTvh1VCI9Fo6bC5cLTpH17T5aFfamyXFYDbbdzN6IXdeoc3jBS7T9hNTmJtYUzJCJ2Xlc9gA==" + }, "update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", diff --git a/package.json b/package.json index f127c4ad..39b812fb 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/source/main/actions/appMenu.ts b/source/main/actions/appMenu.ts index b569ddda..d1ab3a58 100644 --- a/source/main/actions/appMenu.ts +++ b/source/main/actions/appMenu.ts @@ -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 { diff --git a/source/main/library/build.ts b/source/main/library/build.ts index 96e3f741..a83b73d8 100644 --- a/source/main/library/build.ts +++ b/source/main/library/build.ts @@ -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"; diff --git a/source/main/services/launch.ts b/source/main/services/launch.ts index b3e2243a..d2280aff 100644 --- a/source/main/services/launch.ts +++ b/source/main/services/launch.ts @@ -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 { + if (isLinux()) { + await setStartWithSessionLinux(enable); + } else { + await setStartWithSessionNative(enable); + } +} + +async function setStartWithSessionLinux(enable: boolean): Promise { + 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 { const isEnabled = app.getLoginItemSettings().openAtLogin; if (enable && !isEnabled) { app.setLoginItemSettings({