Skip to content

Commit

Permalink
feat(client-electron): add ability to restore default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki committed Oct 22, 2023
1 parent 3bf3efe commit 4dc552a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/electron/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
BreachProtocolCommands,
BreachProtocolKeyBinds,
COMMANDS,
defaultOptions,
DropZoneFileValidationErrors,
KEY_BINDS,
PackageDetails,
Expand Down Expand Up @@ -115,6 +116,15 @@ export class Main {
this.updater.checkForUpdates();
},
},
{ type: 'separator' },
{
label: 'Restore default settings',
id: 'restore-default-settings',
enabled: false,
click: () => {
this.restoreDefaultSettings();
},
},
]);

private trayMenu: MenuItemConstructorOptions[] = [
Expand Down Expand Up @@ -146,6 +156,7 @@ export class Main {
const { worker, renderer } = createBrowserWindows();
this.store = new Store(worker.webContents, renderer.webContents, [
this.toggleKeyBind.bind(this),
this.toggleRestoreDefaultSettings.bind(this),
]);

this.renderer = renderer;
Expand Down Expand Up @@ -533,4 +544,37 @@ export class Main {
}
}
}

private toggleRestoreDefaultSettings(action: Action) {
this.toggleMenuItemOnBootstrap('restore-default-settings', action);
}

private toggleMenuItemOnBootstrap(
menuItemId: string,
{ type, payload }: Action
) {
if (type === ActionTypes.SET_STATUS) {
const menuItem = this.menu.getMenuItemById(menuItemId);

menuItem.enabled = payload !== WorkerStatus.Bootstrap;
}
}

private async restoreDefaultSettings() {
const result = await nativeDialog.confirm({
message: 'Do you want to restore default settings?',
});

if (!result) {
return;
}

const {
settings: { activeDisplayId },
} = this.store.getState();
const defaultSettings = { ...defaultOptions, activeDisplayId };
const action = new UpdateSettingsAction(defaultSettings);

this.store.dispatch(action, true);
}
}
4 changes: 4 additions & 0 deletions src/electron/renderer/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export const Form = <T,>({
const [values, setValues] = useState(initialValues);
const registry = useFieldValueChangeRegistry<T>();

useEffect(() => {
setValues(initialValues);
}, [initialValues]);

function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();

Expand Down

0 comments on commit 4dc552a

Please sign in to comment.