mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
feat: Add system preference to open desktop app on startup (#12279)
* feat: Adds toggle to open desktop app on startup * Remove name hardcoding * refactor
This commit is contained in:
@@ -22,6 +22,7 @@ import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import UserDelete from "../UserDelete";
|
||||
import { AutoLaunchSetting } from "./components/AutoLaunchSetting";
|
||||
import SettingRow from "./components/SettingRow";
|
||||
|
||||
function Preferences() {
|
||||
@@ -280,6 +281,7 @@ function Preferences() {
|
||||
onChange={handleEnableSmartTextChange}
|
||||
/>
|
||||
</SettingRow>
|
||||
<AutoLaunchSetting />
|
||||
<SettingRow
|
||||
border={false}
|
||||
name={UserPreference.NotificationBadge}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import Switch from "~/components/Switch";
|
||||
import env from "~/env";
|
||||
import Logger from "~/utils/Logger";
|
||||
import Desktop from "~/utils/Desktop";
|
||||
import SettingRow from "./SettingRow";
|
||||
|
||||
export function AutoLaunchSetting() {
|
||||
const { t } = useTranslation();
|
||||
const bridge = Desktop.bridge;
|
||||
const supported =
|
||||
Desktop.isElectron() && !!bridge?.getAutoLaunch && !!bridge?.setAutoLaunch;
|
||||
|
||||
const [autoLaunch, setAutoLaunch] = React.useState<boolean | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!bridge?.getAutoLaunch) {
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
bridge
|
||||
.getAutoLaunch()
|
||||
.then((value) => {
|
||||
if (!cancelled) {
|
||||
setAutoLaunch(value);
|
||||
}
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
Logger.error("Failed to read auto-launch state", err);
|
||||
if (!cancelled) {
|
||||
toast.error(t("Could not load preference"));
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [bridge, t]);
|
||||
|
||||
const handleChange = React.useCallback(
|
||||
async (checked: boolean) => {
|
||||
if (!bridge?.setAutoLaunch) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await bridge.setAutoLaunch(checked);
|
||||
setAutoLaunch(result);
|
||||
toast.success(t("Preferences saved"));
|
||||
} catch (err) {
|
||||
Logger.error("Failed to update auto-launch state", err as Error);
|
||||
toast.error(t("Could not save preference"));
|
||||
}
|
||||
},
|
||||
[bridge, t]
|
||||
);
|
||||
|
||||
if (!supported) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const isLoading = autoLaunch === undefined;
|
||||
|
||||
return (
|
||||
<SettingRow
|
||||
name="autoLaunch"
|
||||
label={t("Open on startup")}
|
||||
description={t(
|
||||
"Automatically launch {{ appName }} when you sign in to your computer.",
|
||||
{ appName: env.APP_NAME }
|
||||
)}
|
||||
>
|
||||
<Switch
|
||||
id="autoLaunch"
|
||||
name="autoLaunch"
|
||||
checked={!!autoLaunch}
|
||||
disabled={isLoading}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</SettingRow>
|
||||
);
|
||||
}
|
||||
Vendored
+11
@@ -118,6 +118,17 @@ declare global {
|
||||
* Registers a callback to be called when the application wants to open the replace in page dialog.
|
||||
*/
|
||||
onReplaceInPage: (callback: () => void) => void;
|
||||
|
||||
/**
|
||||
* Get whether the app is configured to launch at login.
|
||||
*/
|
||||
getAutoLaunch: () => Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Enable or disable launching the app at login. Resolves with the
|
||||
* resulting state as reported by the OS.
|
||||
*/
|
||||
setAutoLaunch: (enabled: boolean) => Promise<boolean>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1145,6 +1145,11 @@
|
||||
"Created by": "Created by",
|
||||
"Never": "Never",
|
||||
"Expires": "Expires",
|
||||
"Could not load preference": "Could not load preference",
|
||||
"Preferences saved": "Preferences saved",
|
||||
"Could not save preference": "Could not save preference",
|
||||
"Open on startup": "Open on startup",
|
||||
"Automatically launch {{ appName }} when you sign in to your computer.": "Automatically launch {{ appName }} when you sign in to your computer.",
|
||||
"Disconnect integration": "Disconnect integration",
|
||||
"Disconnecting": "Disconnecting",
|
||||
"Are you sure you want to disconnect the <em>{{ service }}</em> integration?": "Are you sure you want to disconnect the <em>{{ service }}</em> integration?",
|
||||
@@ -1331,7 +1336,6 @@
|
||||
"Unsubscription successful. Your notification settings were updated": "Unsubscription successful. Your notification settings were updated",
|
||||
"Manage when and where you receive email notifications.": "Manage when and where you receive email notifications.",
|
||||
"All notifications": "All notifications",
|
||||
"Preferences saved": "Preferences saved",
|
||||
"Unread count": "Unread count",
|
||||
"Unread indicator": "Unread indicator",
|
||||
"Delete account": "Delete account",
|
||||
|
||||
Reference in New Issue
Block a user