fix: adjust service mode ui

This commit is contained in:
GyDi 2022-11-23 17:45:22 +08:00
parent 28d3691e0b
commit 06dabf1e4e
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
2 changed files with 50 additions and 35 deletions

View File

@ -24,7 +24,11 @@ export const ServiceViewer = forwardRef<DialogRef, Props>((props, ref) => {
const { data: status, mutate: mutateCheck } = useSWR( const { data: status, mutate: mutateCheck } = useSWR(
"checkService", "checkService",
checkService, checkService,
{ revalidateIfStale: false, shouldRetryOnError: false } {
revalidateIfStale: false,
shouldRetryOnError: false,
focusThrottleInterval: 36e5, // 1 hour
}
); );
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@ -64,9 +68,14 @@ export const ServiceViewer = forwardRef<DialogRef, Props>((props, ref) => {
// fix unhandled error of the service mode // fix unhandled error of the service mode
const onDisable = useLockFn(async () => { const onDisable = useLockFn(async () => {
await patchVergeConfig({ enable_service_mode: false }); try {
mutateCheck(); await patchVergeConfig({ enable_service_mode: false });
setOpen(false); mutateCheck();
setOpen(false);
} catch (err: any) {
mutateCheck();
Notice.error(err.message || err.toString());
}
}); });
return ( return (
@ -81,8 +90,8 @@ export const ServiceViewer = forwardRef<DialogRef, Props>((props, ref) => {
{(state === "unknown" || state === "uninstall") && ( {(state === "unknown" || state === "uninstall") && (
<Typography> <Typography>
Information: Please make sure the Clash Verge Service is installed and Information: Please make sure that the Clash Verge Service is
enabled installed and enabled
</Typography> </Typography>
)} )}

View File

@ -27,7 +27,11 @@ const SettingSystem = ({ onError }: Props) => {
const { data: serviceStatus } = useSWR( const { data: serviceStatus } = useSWR(
isWIN ? "checkService" : null, isWIN ? "checkService" : null,
checkService, checkService,
{ revalidateIfStale: false, shouldRetryOnError: false } {
revalidateIfStale: false,
shouldRetryOnError: false,
focusThrottleInterval: 36e5, // 1 hour
}
); );
const serviceRef = useRef<DialogRef>(null); const serviceRef = useRef<DialogRef>(null);
@ -70,47 +74,49 @@ const SettingSystem = ({ onError }: Props) => {
<SettingItem <SettingItem
label={t("Service Mode")} label={t("Service Mode")}
extra={ extra={
(serviceStatus === "active" || serviceStatus === "installed") && (
<PrivacyTipRounded
fontSize="small"
style={{ cursor: "pointer", opacity: 0.75 }}
onClick={() => serviceRef.current?.open()}
/>
)
}
>
{serviceStatus === "active" || serviceStatus === "installed" ? (
<GuardState
value={enable_service_mode ?? false}
valueProps="checked"
onCatch={onError}
onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ enable_service_mode: e })}
onGuard={(e) => patchVerge({ enable_service_mode: e })}
>
<Switch edge="end" />
</GuardState>
) : (
<IconButton <IconButton
color="inherit" color="inherit"
size="small" size="small"
sx={{ my: "2px" }}
onClick={() => serviceRef.current?.open()} onClick={() => serviceRef.current?.open()}
> >
<ArrowForward /> <PrivacyTipRounded
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton> </IconButton>
)} }
>
<GuardState
value={enable_service_mode ?? false}
valueProps="checked"
onCatch={onError}
onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ enable_service_mode: e })}
onGuard={(e) => patchVerge({ enable_service_mode: e })}
>
<Switch
edge="end"
disabled={
serviceStatus !== "active" && serviceStatus !== "installed"
}
/>
</GuardState>
</SettingItem> </SettingItem>
)} )}
<SettingItem <SettingItem
label={t("System Proxy")} label={t("System Proxy")}
extra={ extra={
<Settings <IconButton
fontSize="small" color="inherit"
style={{ cursor: "pointer", opacity: 0.75 }} size="small"
onClick={() => sysproxyRef.current?.open()} onClick={() => sysproxyRef.current?.open()}
/> >
<Settings
fontSize="inherit"
style={{ cursor: "pointer", opacity: 0.75 }}
/>
</IconButton>
} }
> >
<GuardState <GuardState