mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
refactor: preference calls
This commit is contained in:
parent
52e45e4239
commit
be1ed47b13
11 changed files with 127 additions and 129 deletions
|
|
@ -366,7 +366,7 @@ const Preferences = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
const debouncedRequestShowRequireRestartDialog = useCallback(
|
const debouncedRequestShowRequireRestartDialog = useCallback(
|
||||||
debounce(() => requestShowRequireRestartDialog(), 2500),
|
debounce(async () => await window.service.window.requestShowRequireRestartDialog(), 2500),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -420,8 +420,8 @@ const Preferences = ({
|
||||||
<TextField
|
<TextField
|
||||||
helperText={t('Preference.UserNameDetail')}
|
helperText={t('Preference.UserNameDetail')}
|
||||||
fullWidth
|
fullWidth
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('userName', event.target.value);
|
await window.service.preference.set('userName', event.target.value);
|
||||||
}}
|
}}
|
||||||
label={t('Preference.UserName')}
|
label={t('Preference.UserName')}
|
||||||
value={userName}
|
value={userName}
|
||||||
|
|
@ -455,14 +455,15 @@ const Preferences = ({
|
||||||
inputFormat="HH:mm:ss"
|
inputFormat="HH:mm:ss"
|
||||||
renderInput={(timeProps) => <TextField {...timeProps} />}
|
renderInput={(timeProps) => <TextField {...timeProps} />}
|
||||||
value={fromUnixTime(syncDebounceInterval / 1000 + new Date().getTimezoneOffset() * 60)}
|
value={fromUnixTime(syncDebounceInterval / 1000 + new Date().getTimezoneOffset() * 60)}
|
||||||
onChange={(date) => {
|
onChange={async (date) => {
|
||||||
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'Date | null' is not assignable t... Remove this comment to see the full error message
|
if (date === null) throw new Error(`date is null`);
|
||||||
const timeWithoutDate = setDate(setMonth(setYear(date, 1970), 0), 1);
|
const timeWithoutDate = setDate(setMonth(setYear(date, 1970), 0), 1);
|
||||||
const utcTime = (timeWithoutDate.getTime() / 1000 - new Date().getTimezoneOffset() * 60) * 1000;
|
const utcTime = (timeWithoutDate.getTime() / 1000 - new Date().getTimezoneOffset() * 60) * 1000;
|
||||||
void window.service.preference.set('syncDebounceInterval', utcTime);
|
await window.service.preference.set('syncDebounceInterval', utcTime);
|
||||||
debouncedRequestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
// FIXME: no global assign
|
||||||
window.preventClosingWindow = false;
|
window.preventClosingWindow = false;
|
||||||
}}
|
}}
|
||||||
onOpen={() => {
|
onOpen={() => {
|
||||||
|
|
@ -488,13 +489,13 @@ const Preferences = ({
|
||||||
<ChevronRightIcon color="action" />
|
<ChevronRightIcon color="action" />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
}>
|
}>
|
||||||
<MenuItem dense onClick={() => void window.service.preference.set('themeSource', 'system')}>
|
<MenuItem dense onClick={async () => await window.service.preference.set('themeSource', 'system')}>
|
||||||
{t('Preference.SystemDefalutTheme')}
|
{t('Preference.SystemDefalutTheme')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem dense onClick={() => void window.service.preference.set('themeSource', 'light')}>
|
<MenuItem dense onClick={async () => await window.service.preference.set('themeSource', 'light')}>
|
||||||
{t('Preference.LightTheme')}
|
{t('Preference.LightTheme')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem dense onClick={() => void window.service.preference.set('themeSource', 'dark')}>
|
<MenuItem dense onClick={async () => await window.service.preference.set('themeSource', 'dark')}>
|
||||||
{t('Preference.DarkTheme')}
|
{t('Preference.DarkTheme')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</StatedMenu>
|
</StatedMenu>
|
||||||
|
|
@ -506,8 +507,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={sidebar}
|
checked={sidebar}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('sidebar', event.target.checked);
|
await window.service.preference.set('sidebar', event.target.checked);
|
||||||
requestRealignActiveWorkspace();
|
requestRealignActiveWorkspace();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -521,8 +522,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={sidebarShortcutHints}
|
checked={sidebarShortcutHints}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('sidebarShortcutHints', event.target.checked);
|
await window.service.preference.set('sidebarShortcutHints', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -539,8 +540,8 @@ const Preferences = ({
|
||||||
// they can't access preferences or notifications
|
// they can't access preferences or notifications
|
||||||
checked={(window.remote.getPlatform() === 'linux' && attachToMenubar && !sidebar) || navigationBar}
|
checked={(window.remote.getPlatform() === 'linux' && attachToMenubar && !sidebar) || navigationBar}
|
||||||
disabled={window.remote.getPlatform() === 'linux' && attachToMenubar && !sidebar}
|
disabled={window.remote.getPlatform() === 'linux' && attachToMenubar && !sidebar}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('navigationBar', event.target.checked);
|
await window.service.preference.set('navigationBar', event.target.checked);
|
||||||
requestRealignActiveWorkspace();
|
requestRealignActiveWorkspace();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -556,8 +557,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={titleBar}
|
checked={titleBar}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('titleBar', event.target.checked);
|
await window.service.preference.set('titleBar', event.target.checked);
|
||||||
requestRealignActiveWorkspace();
|
requestRealignActiveWorkspace();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -575,9 +576,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={hideMenuBar}
|
checked={hideMenuBar}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('hideMenuBar', event.target.checked);
|
await window.service.preference.set('hideMenuBar', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -595,9 +596,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={attachToMenubar}
|
checked={attachToMenubar}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('attachToMenubar', event.target.checked);
|
await window.service.preference.set('attachToMenubar', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -639,9 +640,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={blockAds}
|
checked={blockAds}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('blockAds', event.target.checked);
|
await window.service.preference.set('blockAds', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -678,8 +679,8 @@ const Preferences = ({
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={themeSource !== 'light' && darkReader}
|
checked={themeSource !== 'light' && darkReader}
|
||||||
disabled={themeSource === 'light'}
|
disabled={themeSource === 'light'}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('darkReader', event.target.checked);
|
await window.service.preference.set('darkReader', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -714,7 +715,7 @@ const Preferences = ({
|
||||||
max={50}
|
max={50}
|
||||||
onChange={(_, value) => {
|
onChange={(_, value) => {
|
||||||
// @ts-expect-error ts-migrate(2365) FIXME: Operator '+' cannot be applied to types 'number | ... Remove this comment to see the full error message
|
// @ts-expect-error ts-migrate(2365) FIXME: Operator '+' cannot be applied to types 'number | ... Remove this comment to see the full error message
|
||||||
void window.service.preference.set('darkReaderBrightness', value + 100);
|
await window.service.preference.set('darkReaderBrightness', value + 100);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -747,7 +748,7 @@ const Preferences = ({
|
||||||
max={50}
|
max={50}
|
||||||
onChange={(_, value) => {
|
onChange={(_, value) => {
|
||||||
// @ts-expect-error ts-migrate(2365) FIXME: Operator '+' cannot be applied to types 'number | ... Remove this comment to see the full error message
|
// @ts-expect-error ts-migrate(2365) FIXME: Operator '+' cannot be applied to types 'number | ... Remove this comment to see the full error message
|
||||||
void window.service.preference.set('darkReaderContrast', value + 100);
|
await window.service.preference.set('darkReaderContrast', value + 100);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -774,8 +775,8 @@ const Preferences = ({
|
||||||
]}
|
]}
|
||||||
min={0}
|
min={0}
|
||||||
max={100}
|
max={100}
|
||||||
onChange={(_, value) => {
|
onChange={async (_, value) => {
|
||||||
void window.service.preference.set('darkReaderSepia', value);
|
await window.service.preference.set('darkReaderSepia', value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -802,8 +803,8 @@ const Preferences = ({
|
||||||
]}
|
]}
|
||||||
min={0}
|
min={0}
|
||||||
max={100}
|
max={100}
|
||||||
onChange={(_, value) => {
|
onChange={async (_, value) => {
|
||||||
void window.service.preference.set('darkReaderGrayscale', value);
|
await window.service.preference.set('darkReaderGrayscale', value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -835,7 +836,7 @@ const Preferences = ({
|
||||||
renderInput={(timeProps) => <TextField {...timeProps} />}
|
renderInput={(timeProps) => <TextField {...timeProps} />}
|
||||||
value={new Date(pauseNotificationsByScheduleFrom)}
|
value={new Date(pauseNotificationsByScheduleFrom)}
|
||||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||||
onChange={(d) => void window.service.preference.set('pauseNotificationsByScheduleFrom', d.toString())}
|
onChange={(d) => await window.service.preference.set('pauseNotificationsByScheduleFrom', d.toString())}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
window.preventClosingWindow = false;
|
window.preventClosingWindow = false;
|
||||||
}}
|
}}
|
||||||
|
|
@ -851,7 +852,7 @@ const Preferences = ({
|
||||||
renderInput={(timeProps) => <TextField {...timeProps} />}
|
renderInput={(timeProps) => <TextField {...timeProps} />}
|
||||||
value={new Date(pauseNotificationsByScheduleTo)}
|
value={new Date(pauseNotificationsByScheduleTo)}
|
||||||
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
||||||
onChange={(d) => void window.service.preference.set('pauseNotificationsByScheduleTo', d.toString())}
|
onChange={(d) => await window.service.preference.set('pauseNotificationsByScheduleTo', d.toString())}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
window.preventClosingWindow = false;
|
window.preventClosingWindow = false;
|
||||||
}}
|
}}
|
||||||
|
|
@ -868,8 +869,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={pauseNotificationsBySchedule}
|
checked={pauseNotificationsBySchedule}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('pauseNotificationsBySchedule', event.target.checked);
|
await window.service.preference.set('pauseNotificationsBySchedule', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -882,8 +883,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={pauseNotificationsMuteAudio}
|
checked={pauseNotificationsMuteAudio}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('pauseNotificationsMuteAudio', event.target.checked);
|
await window.service.preference.set('pauseNotificationsMuteAudio', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -896,9 +897,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={unreadCountBadge}
|
checked={unreadCountBadge}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('unreadCountBadge', event.target.checked);
|
await window.service.preference.set('unreadCountBadge', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -975,9 +976,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={spellcheck}
|
checked={spellcheck}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('spellcheck', event.target.checked);
|
await window.service.preference.set('spellcheck', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1011,10 +1012,10 @@ const Preferences = ({
|
||||||
.showOpenDialog({
|
.showOpenDialog({
|
||||||
properties: ['openDirectory'],
|
properties: ['openDirectory'],
|
||||||
})
|
})
|
||||||
.then((result: any) => {
|
.then(async (result: any) => {
|
||||||
// eslint-disable-next-line promise/always-return
|
// eslint-disable-next-line promise/always-return
|
||||||
if (!result.canceled && result.filePaths) {
|
if (!result.canceled && result.filePaths) {
|
||||||
void window.service.preference.set('downloadPath', result.filePaths[0]);
|
await window.service.preference.set('downloadPath', result.filePaths[0]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
|
|
@ -1032,8 +1033,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={askForDownloadPath}
|
checked={askForDownloadPath}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('askForDownloadPath', event.target.checked);
|
await window.service.preference.set('askForDownloadPath', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1067,9 +1068,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={blockAds}
|
checked={blockAds}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('blockAds', event.target.checked);
|
await window.service.preference.set('blockAds', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1082,9 +1083,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={rememberLastPageVisited}
|
checked={rememberLastPageVisited}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('rememberLastPageVisited', event.target.checked);
|
await window.service.preference.set('rememberLastPageVisited', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1097,9 +1098,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={shareWorkspaceBrowsingData}
|
checked={shareWorkspaceBrowsingData}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('shareWorkspaceBrowsingData', event.target.checked);
|
await window.service.preference.set('shareWorkspaceBrowsingData', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1133,9 +1134,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={ignoreCertificateErrors}
|
checked={ignoreCertificateErrors}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('ignoreCertificateErrors', event.target.checked);
|
await window.service.preference.set('ignoreCertificateErrors', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1231,8 +1232,8 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={hibernateUnusedWorkspacesAtLaunch}
|
checked={hibernateUnusedWorkspacesAtLaunch}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('hibernateUnusedWorkspacesAtLaunch', event.target.checked);
|
await window.service.preference.set('hibernateUnusedWorkspacesAtLaunch', event.target.checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1262,9 +1263,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={swipeToNavigate}
|
checked={swipeToNavigate}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('swipeToNavigate', event.target.checked);
|
await window.service.preference.set('swipeToNavigate', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1279,9 +1280,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={useHardwareAcceleration}
|
checked={useHardwareAcceleration}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('useHardwareAcceleration', event.target.checked);
|
await window.service.preference.set('useHardwareAcceleration', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1318,9 +1319,9 @@ const Preferences = ({
|
||||||
edge="end"
|
edge="end"
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={allowPrerelease}
|
checked={allowPrerelease}
|
||||||
onChange={(event) => {
|
onChange={async (event) => {
|
||||||
void window.service.preference.set('allowPrerelease', event.target.checked);
|
await window.service.preference.set('allowPrerelease', event.target.checked);
|
||||||
requestShowRequireRestartDialog();
|
await debouncedRequestShowRequireRestartDialog();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ListItemSecondaryAction>
|
</ListItemSecondaryAction>
|
||||||
|
|
@ -1334,7 +1335,7 @@ const Preferences = ({
|
||||||
</Typography>
|
</Typography>
|
||||||
<Paper elevation={0} className={classes.paper}>
|
<Paper elevation={0} className={classes.paper}>
|
||||||
<List dense disablePadding>
|
<List dense disablePadding>
|
||||||
<ListItem button onClick={requestResetPreferences}>
|
<ListItem button onClick={window.service.preference.resetWithConfirm}>
|
||||||
<ListItemText primary="Restore preferences to their original defaults" />
|
<ListItemText primary="Restore preferences to their original defaults" />
|
||||||
<ChevronRightIcon color="action" />
|
<ChevronRightIcon color="action" />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,6 @@ export enum WorkspaceViewChannel {
|
||||||
export enum PreferenceChannel {
|
export enum PreferenceChannel {
|
||||||
name = 'PreferenceChannel',
|
name = 'PreferenceChannel',
|
||||||
update = 'update',
|
update = 'update',
|
||||||
requestResetPreferences = 'request-reset-preferences',
|
|
||||||
requestShowRequireRestartDialog = 'request-show-require-restart-dialog',
|
|
||||||
getPreference = 'get-preference',
|
getPreference = 'get-preference',
|
||||||
getPreferences = 'get-preferences',
|
getPreferences = 'get-preferences',
|
||||||
requestClearBrowsingData = 'request-clear-browsing-data',
|
requestClearBrowsingData = 'request-clear-browsing-data',
|
||||||
|
|
@ -58,7 +56,6 @@ export enum PreferenceChannel {
|
||||||
|
|
||||||
export enum WindowChannel {
|
export enum WindowChannel {
|
||||||
name = 'WindowChannel',
|
name = 'WindowChannel',
|
||||||
requestShowRequireRestartDialog = 'request-show-require-restart-dialog',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ThemeChannel {
|
export enum ThemeChannel {
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,6 @@ export const getShouldUseDarkColors = async (): Promise<void> => {
|
||||||
await ipcRenderer.invoke('get-should-use-dark-colors');
|
await ipcRenderer.invoke('get-should-use-dark-colors');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Preferences
|
|
||||||
export const requestResetPreferences = async () => await ipcRenderer.invoke('request-reset-preferences');
|
|
||||||
export const requestShowRequireRestartDialog = async () => await ipcRenderer.invoke('request-show-require-restart-dialog');
|
|
||||||
|
|
||||||
// System Preferences
|
// System Preferences
|
||||||
export const getSystemPreference = (name: string): JsonValue => ipcRenderer.invokeSync('get-system-preference', name);
|
export const getSystemPreference = (name: string): JsonValue => ipcRenderer.invokeSync('get-system-preference', name);
|
||||||
export const getSystemPreferences = (): JsonObject => ipcRenderer.invokeSync('get-system-preferences');
|
export const getSystemPreferences = (): JsonObject => ipcRenderer.invokeSync('get-system-preferences');
|
||||||
|
|
|
||||||
|
|
@ -97,25 +97,6 @@ export class Preference implements IPreferenceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
init(): void {
|
init(): void {
|
||||||
ipcMain.handle(PreferenceChannel.requestResetPreferences, () => {
|
|
||||||
const preferenceWindow = this.windowService.get(WindowNames.preferences);
|
|
||||||
if (preferenceWindow !== undefined) {
|
|
||||||
dialog
|
|
||||||
.showMessageBox(preferenceWindow, {
|
|
||||||
type: 'question',
|
|
||||||
buttons: [i18n.t('Preference.ResetNow'), i18n.t('Cancel')],
|
|
||||||
message: i18n.t('Preference.Reset'),
|
|
||||||
cancelId: 1,
|
|
||||||
})
|
|
||||||
.then(async ({ response }) => {
|
|
||||||
if (response === 0) {
|
|
||||||
await this.reset();
|
|
||||||
ipcMain.emit(PreferenceChannel.requestShowRequireRestartDialog);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ipcMain.handle(PreferenceChannel.requestClearBrowsingData, () => {
|
ipcMain.handle(PreferenceChannel.requestClearBrowsingData, () => {
|
||||||
const availableWindowToShowDialog = this.windowService.get(WindowNames.preferences) ?? this.windowService.get(WindowNames.main);
|
const availableWindowToShowDialog = this.windowService.get(WindowNames.preferences) ?? this.windowService.get(WindowNames.main);
|
||||||
if (availableWindowToShowDialog !== undefined) {
|
if (availableWindowToShowDialog !== undefined) {
|
||||||
|
|
@ -143,6 +124,26 @@ export class Preference implements IPreferenceService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async resetWithConfirm(): Promise<void> {
|
||||||
|
const preferenceWindow = this.windowService.get(WindowNames.preferences);
|
||||||
|
if (preferenceWindow !== undefined) {
|
||||||
|
await dialog
|
||||||
|
.showMessageBox(preferenceWindow, {
|
||||||
|
type: 'question',
|
||||||
|
buttons: [i18n.t('Preference.ResetNow'), i18n.t('Cancel')],
|
||||||
|
message: i18n.t('Preference.Reset'),
|
||||||
|
cancelId: 1,
|
||||||
|
})
|
||||||
|
.then(async ({ response }) => {
|
||||||
|
if (response === 0) {
|
||||||
|
await this.reset();
|
||||||
|
await this.windowService.requestShowRequireRestartDialog();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load preferences in sync, and ensure it is an Object
|
* load preferences in sync, and ensure it is an Object
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ export interface IPreferenceService {
|
||||||
getPreferences: () => IPreferences;
|
getPreferences: () => IPreferences;
|
||||||
get<K extends keyof IPreferences>(key: K): IPreferences[K];
|
get<K extends keyof IPreferences>(key: K): IPreferences[K];
|
||||||
reset(): Promise<void>;
|
reset(): Promise<void>;
|
||||||
|
resetWithConfirm(): Promise<void>;
|
||||||
}
|
}
|
||||||
export const PreferenceServiceIPCDescriptor = {
|
export const PreferenceServiceIPCDescriptor = {
|
||||||
channel: PreferenceChannel.name,
|
channel: PreferenceChannel.name,
|
||||||
|
|
@ -61,5 +62,6 @@ export const PreferenceServiceIPCDescriptor = {
|
||||||
getPreferences: ProxyPropertyType.Function,
|
getPreferences: ProxyPropertyType.Function,
|
||||||
get: ProxyPropertyType.Function,
|
get: ProxyPropertyType.Function,
|
||||||
reset: ProxyPropertyType.Function,
|
reset: ProxyPropertyType.Function,
|
||||||
|
resetWithConfirm: ProxyPropertyType.Function,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -39,27 +39,6 @@ export class Window implements IWindowService {
|
||||||
}
|
}
|
||||||
|
|
||||||
initIPCHandlers(): void {
|
initIPCHandlers(): void {
|
||||||
ipcMain.handle(WindowChannel.requestShowRequireRestartDialog, () => {
|
|
||||||
const availableWindowToShowDialog = this.get(WindowNames.preferences) ?? this.get(WindowNames.main);
|
|
||||||
if (availableWindowToShowDialog !== undefined) {
|
|
||||||
dialog
|
|
||||||
.showMessageBox(availableWindowToShowDialog, {
|
|
||||||
type: 'question',
|
|
||||||
buttons: [i18n.t('Dialog.RestartNow'), i18n.t('Dialog.Later')],
|
|
||||||
message: i18n.t('Dialog.RestartMessage'),
|
|
||||||
cancelId: 1,
|
|
||||||
})
|
|
||||||
.then(({ response }) => {
|
|
||||||
if (response === 0) {
|
|
||||||
const availableApp = (app as App | undefined) === undefined ? remote.app : app;
|
|
||||||
availableApp.relaunch();
|
|
||||||
availableApp.quit();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipcMain.handle('request-find-in-page', (_event, text: string, forward?: boolean, windowName: WindowNames = WindowNames.main) => {
|
ipcMain.handle('request-find-in-page', (_event, text: string, forward?: boolean, windowName: WindowNames = WindowNames.main) => {
|
||||||
const mainWindow = this.get(windowName);
|
const mainWindow = this.get(windowName);
|
||||||
const contents = mainWindow?.getBrowserView()?.webContents;
|
const contents = mainWindow?.getBrowserView()?.webContents;
|
||||||
|
|
@ -97,6 +76,26 @@ export class Window implements IWindowService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async requestShowRequireRestartDialog(): Promise<void> {
|
||||||
|
const availableWindowToShowDialog = this.get(WindowNames.preferences) ?? this.get(WindowNames.main);
|
||||||
|
if (availableWindowToShowDialog !== undefined) {
|
||||||
|
await dialog
|
||||||
|
.showMessageBox(availableWindowToShowDialog, {
|
||||||
|
type: 'question',
|
||||||
|
buttons: [i18n.t('Dialog.RestartNow'), i18n.t('Dialog.Later')],
|
||||||
|
message: i18n.t('Dialog.RestartMessage'),
|
||||||
|
cancelId: 1,
|
||||||
|
})
|
||||||
|
.then(({ response }) => {
|
||||||
|
if (response === 0) {
|
||||||
|
app.relaunch();
|
||||||
|
app.quit();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public get(windowName: WindowNames = WindowNames.main): BrowserWindow | undefined {
|
public get(windowName: WindowNames = WindowNames.main): BrowserWindow | undefined {
|
||||||
return this.windows[windowName];
|
return this.windows[windowName];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export interface IWindowService {
|
||||||
updateWindowMeta<N extends WindowNames>(windowName: N, meta?: WindowMeta[N]): void;
|
updateWindowMeta<N extends WindowNames>(windowName: N, meta?: WindowMeta[N]): void;
|
||||||
getWindowMeta<N extends WindowNames>(windowName: N): WindowMeta[N] | undefined;
|
getWindowMeta<N extends WindowNames>(windowName: N): WindowMeta[N] | undefined;
|
||||||
sendToAllWindows: (channel: Channels, ...arguments_: unknown[]) => void;
|
sendToAllWindows: (channel: Channels, ...arguments_: unknown[]) => void;
|
||||||
|
requestShowRequireRestartDialog(): Promise<void>;
|
||||||
goHome(windowName: WindowNames): Promise<void>;
|
goHome(windowName: WindowNames): Promise<void>;
|
||||||
goBack(windowName: WindowNames): void;
|
goBack(windowName: WindowNames): void;
|
||||||
goForward(windowName: WindowNames): void;
|
goForward(windowName: WindowNames): void;
|
||||||
|
|
@ -29,6 +30,7 @@ export const WindowServiceIPCDescriptor = {
|
||||||
setWindowMeta: ProxyPropertyType.Function,
|
setWindowMeta: ProxyPropertyType.Function,
|
||||||
updateWindowMeta: ProxyPropertyType.Function,
|
updateWindowMeta: ProxyPropertyType.Function,
|
||||||
getWindowMeta: ProxyPropertyType.Function,
|
getWindowMeta: ProxyPropertyType.Function,
|
||||||
|
requestShowRequireRestartDialog: ProxyPropertyType.Function,
|
||||||
sendToAllWindows: ProxyPropertyType.Function,
|
sendToAllWindows: ProxyPropertyType.Function,
|
||||||
goHome: ProxyPropertyType.Function,
|
goHome: ProxyPropertyType.Function,
|
||||||
goBack: ProxyPropertyType.Function,
|
goBack: ProxyPropertyType.Function,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const updateForm = (changes: any) => (dispatch: any) =>
|
||||||
changes,
|
changes,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const save = () => (dispatch: any, getState: any) => {
|
export const save = async () => (dispatch: any, getState: any) => {
|
||||||
const { form } = getState().dialogCodeInjection;
|
const { form } = getState().dialogCodeInjection;
|
||||||
|
|
||||||
const { codeInjectionType } = window.meta as WindowMeta[WindowNames.codeInjection];
|
const { codeInjectionType } = window.meta as WindowMeta[WindowNames.codeInjection];
|
||||||
|
|
@ -22,7 +22,7 @@ export const save = () => (dispatch: any, getState: any) => {
|
||||||
void window.service.preference.set('allowNodeInJsCodeInjection', form.allowNodeInJsCodeInjection);
|
void window.service.preference.set('allowNodeInJsCodeInjection', form.allowNodeInJsCodeInjection);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestShowRequireRestartDialog();
|
await window.service.window.requestShowRequireRestartDialog();
|
||||||
|
|
||||||
window.remote.closeCurrentWindow();
|
window.remote.closeCurrentWindow();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export const save = () => async (dispatch: any, getState: any) => {
|
||||||
|
|
||||||
if ((await window.service.preference.get('customUserAgent')) !== form.code) {
|
if ((await window.service.preference.get('customUserAgent')) !== form.code) {
|
||||||
await window.service.preference.set('customUserAgent', form.code);
|
await window.service.preference.set('customUserAgent', form.code);
|
||||||
requestShowRequireRestartDialog();
|
await window.service.window.requestShowRequireRestartDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.remote.closeCurrentWindow();
|
window.remote.closeCurrentWindow();
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ export const updateForm = (changes: any) => (dispatch: any, getState: any) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const save = () => (dispatch: any, getState: any) => {
|
export const save = async () => (dispatch: any, getState: any) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
const { form } = state.dialogProxy;
|
const { form } = state.dialogProxy;
|
||||||
|
|
@ -61,7 +61,7 @@ export const save = () => (dispatch: any, getState: any) => {
|
||||||
void window.service.preference.set('proxyBypassRules', form.proxyBypassRules);
|
void window.service.preference.set('proxyBypassRules', form.proxyBypassRules);
|
||||||
void window.service.preference.set('proxyPacScript', form.proxyPacScript);
|
void window.service.preference.set('proxyPacScript', form.proxyPacScript);
|
||||||
void window.service.preference.set('proxyType', form.proxyType);
|
void window.service.preference.set('proxyType', form.proxyType);
|
||||||
requestShowRequireRestartDialog();
|
await window.service.window.requestShowRequireRestartDialog()
|
||||||
|
|
||||||
window.remote.closeCurrentWindow();
|
window.remote.closeCurrentWindow();
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@ export const removeLanguage = (code: any) => (dispatch: any, getState: any) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const save = () => (dispatch: any, getState: any) => {
|
export const save = async () => (dispatch: any, getState: any) => {
|
||||||
const { form } = getState().dialogSpellcheckLanguages;
|
const { form } = getState().dialogSpellcheckLanguages;
|
||||||
|
|
||||||
void window.service.preference.set('spellcheckLanguages', form.spellcheckLanguages);
|
void window.service.preference.set('spellcheckLanguages', form.spellcheckLanguages);
|
||||||
|
|
||||||
requestShowRequireRestartDialog();
|
await window.service.window.requestShowRequireRestartDialog()
|
||||||
|
|
||||||
window.remote.closeCurrentWindow();
|
window.remote.closeCurrentWindow();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue