Skip to content

Commit

Permalink
fix(startup): can no disable run on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Aug 19, 2024
1 parent 57e967f commit 7ec598b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
### enhancements
- avoid recreate already existing folders.

### fix
- can no disable run on startup.

## [1.9.7]
### enhancements
- made all invoke handlers async
Expand Down
7 changes: 6 additions & 1 deletion src/apps/settings/modules/general/main/infra/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Colors } from './Colors';
import { Themes } from './Themes';
import { Wallpaper } from './Wallpaper';
import { Select, Switch } from 'antd';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

Expand All @@ -14,18 +15,22 @@ import { RootActions } from '../../../shared/store/app/reducer';
import { RootSelectors } from '../../../shared/store/app/selectors';

export function General() {
const [changingAutostart, setChangingAutostart] = useState(false);

const autostartStatus = useSelector(RootSelectors.autostart);
const language = useSelector(RootSelectors.language);

const { t } = useTranslation();
const dispatch = useAppDispatch();

const onAutoStart = async (value: boolean) => {
setChangingAutostart(true);
if (value) {
await startup.enable();
} else {
await startup.disable();
}
setChangingAutostart(false);
dispatch(RootActions.setAutostart(value));
};

Expand All @@ -34,7 +39,7 @@ export function General() {
<SettingsGroup>
<SettingsOption>
<span style={{ fontWeight: 600 }}>{t('general.startup')}</span>
<Switch onChange={onAutoStart} value={autostartStatus} />
<Switch onChange={onAutoStart} value={!!autostartStatus} loading={changingAutostart || autostartStatus === null} />
</SettingsOption>
<SettingsOption>
<b>{t('general.language')}:</b>
Expand Down
13 changes: 7 additions & 6 deletions src/apps/settings/modules/shared/store/app/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StateBuilder } from '../../../../../shared/StateBuilder';
import { Route } from '../../../../components/navigation/routes';
import i18n from '../../../../i18n';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { cloneDeep } from 'lodash';
import { cloneDeep, pick } from 'lodash';

import { AppsConfigSlice } from '../../../appsConfigurations/app/reducer';
import { FancyToolbarSlice } from '../../../fancyToolbar/app';
Expand All @@ -16,7 +16,7 @@ import { RootState } from '../domain';

const initialState: RootState = {
lastLoaded: null,
autostart: false,
autostart: null,
route: Route.GENERAL,
fancyToolbar: FancyToolbarSlice.getInitialState(),
seelenweg: SeelenWegSlice.getInitialState(),
Expand Down Expand Up @@ -63,10 +63,11 @@ export const RootSlice = createSlice({
},
restoreToLastLoaded: (state) => {
if (state.lastLoaded) {
const newState = cloneDeep(state.lastLoaded);
newState.lastLoaded = cloneDeep(state.lastLoaded);
newState.route = state.route;
newState.colors = state.colors;
const toMaintain = pick(state, ['autostart', 'colors', 'lastLoaded']);
const newState = {
...cloneDeep(state.lastLoaded),
...toMaintain,
};
i18n.changeLanguage(newState.language);
return newState;
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/settings/modules/shared/store/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface RootState extends ISettings {
availableThemes: Theme[];
availableLayouts: Layout[];
availablePlaceholders: Placeholder[];
autostart: boolean;
autostart: boolean | null;
colors: UIColors;
wallpaper: string | null;
}
5 changes: 3 additions & 2 deletions src/background/schedule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ if (-not $isAdmin) {
Exit
}

$taskName = "\Seelen\Seelen-UI"
$taskName = "Seelen-UI"
$taskPath = "\Seelen\$taskName"

if ($Enabled -eq "true") {
$action = New-ScheduledTaskAction -Execute "$ExeRoute" -Argument "--silent"
$trigger = New-ScheduledTaskTrigger -AtLogon
$settings = New-ScheduledTaskSettingsSet -Priority 2 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -Hidden

Register-ScheduledTask -Force -Action $action -Trigger $trigger -Settings $settings -TaskName $taskName -User $env:USERNAME -RunLevel Highest
Register-ScheduledTask -Force -Action $action -Trigger $trigger -Settings $settings -TaskName $taskPath -User $env:USERNAME -RunLevel Highest
}
else {
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
Expand Down

0 comments on commit 7ec598b

Please sign in to comment.