11import './style.scss' ;
22import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query' ;
3- import { disable , enable , isEnabled } from '@tauri-apps/plugin-autostart' ;
43import { openUrl } from '@tauri-apps/plugin-opener' ;
54import clsx from 'clsx' ;
65import { type ReactNode , useMemo , useState } from 'react' ;
6+ import { getAutostartStatus , setAutostartEnabled } from '../../../shared/autostart' ;
77import { Divider } from '../../../shared/components/Divider/Divider' ;
88import { FullPageTitle } from '../../../shared/components/FullPageTitle/FullPageTitle' ;
99import { Icon , IconKind } from '../../../shared/components/Icon' ;
@@ -38,12 +38,12 @@ export const SettingsPage = () => {
3838 const queryClient = useQueryClient ( ) ;
3939 const { data : appConfig } = useQuery ( getAppConfigQueryOptions ) ;
4040 const {
41- data : autostartEnabled ,
41+ data : autostartStatus ,
4242 isError : isAutostartStatusError ,
4343 isPending : isAutostartStatusPending ,
4444 } = useQuery ( {
4545 queryKey : AUTOSTART_QUERY_KEY ,
46- queryFn : isEnabled ,
46+ queryFn : getAutostartStatus ,
4747 } ) ;
4848
4949 const { mutate : patchConfig } = useMutation ( {
@@ -56,15 +56,13 @@ export const SettingsPage = () => {
5656 } ,
5757 } ) ;
5858
59- const { mutate : setAutostart , isPending : isAutostartUpdating } = useMutation ( {
60- mutationFn : async ( enabled : boolean ) => {
61- if ( enabled ) {
62- await enable ( ) ;
63- } else {
64- await disable ( ) ;
65- }
66- } ,
67- onSuccess : ( ) => queryClient . invalidateQueries ( { queryKey : AUTOSTART_QUERY_KEY } ) ,
59+ const {
60+ mutate : setAutostart ,
61+ isPending : isAutostartUpdating ,
62+ isError : isAutostartUpdateError ,
63+ } = useMutation ( {
64+ mutationFn : setAutostartEnabled ,
65+ onSettled : ( ) => queryClient . invalidateQueries ( { queryKey : AUTOSTART_QUERY_KEY } ) ,
6866 onError : ( error ) => {
6967 console . error ( error ) ;
7068 } ,
@@ -172,14 +170,28 @@ export const SettingsPage = () => {
172170 < div className = "sections startup-settings" >
173171 < SettingRow
174172 title = "Start Defguard automatically when your operating system starts"
173+ description = {
174+ autostartStatus === 'requiresApproval'
175+ ? 'Approve Defguard in System Settings > General > Login Items to start it at login.'
176+ : isAutostartStatusError ||
177+ isAutostartUpdateError ||
178+ autostartStatus === 'notFound'
179+ ? 'Could not update or check login startup. Please try again.'
180+ : undefined
181+ }
175182 inline
176183 >
177184 < Toggle
178- active = { autostartEnabled ?? false }
185+ active = {
186+ autostartStatus === 'enabled' || autostartStatus === 'requiresApproval'
187+ }
179188 disabled = {
180- isAutostartStatusPending || isAutostartStatusError || isAutostartUpdating
189+ isAutostartStatusPending ||
190+ isAutostartStatusError ||
191+ isAutostartUpdating ||
192+ autostartStatus === 'notFound'
181193 }
182- onClick = { ( ) => setAutostart ( ! autostartEnabled ) }
194+ onClick = { ( ) => setAutostart ( autostartStatus === 'disabled' ) }
183195 />
184196 </ SettingRow >
185197 < SettingRow title = "Start the app minimized to the system tray" inline >
0 commit comments