mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-03 09:33:10 -07:00
cleaner DismissedUpdates configuration display in the config
This commit is contained in:
parent
803df29d76
commit
bdb69b77f0
3 changed files with 28 additions and 17 deletions
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { useKoboldVersionsStore } from '@/stores/koboldVersions';
|
import { useKoboldVersionsStore } from '@/stores/koboldVersions';
|
||||||
import { getROCmDownload } from '@/utils/rocm';
|
import { getROCmDownload } from '@/utils/rocm';
|
||||||
import type { InstalledVersion, DownloadItem } from '@/types/electron';
|
import type { InstalledVersion, DownloadItem } from '@/types/electron';
|
||||||
|
import type { DismissedUpdate } from '@/types';
|
||||||
|
|
||||||
export interface BinaryUpdateInfo {
|
export interface BinaryUpdateInfo {
|
||||||
currentVersion: InstalledVersion;
|
currentVersion: InstalledVersion;
|
||||||
|
|
@ -17,8 +18,8 @@ export const useUpdateChecker = () => {
|
||||||
const [updateInfo, setUpdateInfo] = useState<BinaryUpdateInfo | null>(null);
|
const [updateInfo, setUpdateInfo] = useState<BinaryUpdateInfo | null>(null);
|
||||||
const [isChecking, setIsChecking] = useState(false);
|
const [isChecking, setIsChecking] = useState(false);
|
||||||
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
const [showUpdateModal, setShowUpdateModal] = useState(false);
|
||||||
const [dismissedUpdates, setDismissedUpdates] = useState<Set<string>>(
|
const [dismissedUpdates, setDismissedUpdates] = useState<DismissedUpdate[]>(
|
||||||
new Set()
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { availableDownloads: releases, loadingRemote } =
|
const { availableDownloads: releases, loadingRemote } =
|
||||||
|
|
@ -27,10 +28,10 @@ export const useUpdateChecker = () => {
|
||||||
const loadDismissedUpdates = async () => {
|
const loadDismissedUpdates = async () => {
|
||||||
const dismissed = (await window.electronAPI.config.get(
|
const dismissed = (await window.electronAPI.config.get(
|
||||||
'dismissedUpdates'
|
'dismissedUpdates'
|
||||||
)) as string[] | undefined;
|
)) as DismissedUpdate[] | undefined;
|
||||||
|
|
||||||
if (dismissed) {
|
if (dismissed) {
|
||||||
setDismissedUpdates(new Set(dismissed));
|
setDismissedUpdates(dismissed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -72,9 +73,13 @@ export const useUpdateChecker = () => {
|
||||||
compareVersions(matchingDownload.version, currentVersion.version) > 0;
|
compareVersions(matchingDownload.version, currentVersion.version) > 0;
|
||||||
|
|
||||||
if (hasUpdate) {
|
if (hasUpdate) {
|
||||||
const updateKey = `${currentVersion.path}-${matchingDownload.version}`;
|
const isUpdateDismissed = dismissedUpdates.some(
|
||||||
|
(dismissedUpdate) =>
|
||||||
|
dismissedUpdate.currentVersionPath === currentVersion.path &&
|
||||||
|
dismissedUpdate.targetVersion === matchingDownload.version
|
||||||
|
);
|
||||||
|
|
||||||
if (!dismissedUpdates.has(updateKey)) {
|
if (!isUpdateDismissed) {
|
||||||
setUpdateInfo({
|
setUpdateInfo({
|
||||||
currentVersion,
|
currentVersion,
|
||||||
availableUpdate: matchingDownload,
|
availableUpdate: matchingDownload,
|
||||||
|
|
@ -88,14 +93,15 @@ export const useUpdateChecker = () => {
|
||||||
}, [dismissedUpdates, releases, loadingRemote]);
|
}, [dismissedUpdates, releases, loadingRemote]);
|
||||||
|
|
||||||
const skipUpdate = useCallback(() => {
|
const skipUpdate = useCallback(() => {
|
||||||
if (updateInfo) {
|
if (updateInfo && updateInfo.availableUpdate.version) {
|
||||||
const updateKey = `${updateInfo.currentVersion.path}-${updateInfo.availableUpdate.version}`;
|
const newDismissedUpdate: DismissedUpdate = {
|
||||||
const newDismissedUpdates = new Set([...dismissedUpdates, updateKey]);
|
currentVersionPath: updateInfo.currentVersion.path,
|
||||||
|
targetVersion: updateInfo.availableUpdate.version,
|
||||||
|
};
|
||||||
|
|
||||||
|
const newDismissedUpdates = [...dismissedUpdates, newDismissedUpdate];
|
||||||
setDismissedUpdates(newDismissedUpdates);
|
setDismissedUpdates(newDismissedUpdates);
|
||||||
window.electronAPI.config.set(
|
window.electronAPI.config.set('dismissedUpdates', newDismissedUpdates);
|
||||||
'dismissedUpdates',
|
|
||||||
Array.from(newDismissedUpdates)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
setShowUpdateModal(false);
|
setShowUpdateModal(false);
|
||||||
setUpdateInfo(null);
|
setUpdateInfo(null);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { join } from 'path';
|
||||||
import { platform } from 'process';
|
import { platform } from 'process';
|
||||||
import { nativeTheme } from 'electron';
|
import { nativeTheme } from 'electron';
|
||||||
import { PRODUCT_NAME } from '@/constants';
|
import { PRODUCT_NAME } from '@/constants';
|
||||||
import type { FrontendPreference } from '@/types';
|
import type { FrontendPreference, DismissedUpdate } from '@/types';
|
||||||
import type { MantineColorScheme } from '@mantine/core';
|
import type { MantineColorScheme } from '@mantine/core';
|
||||||
import type { SavedNotepadState } from '@/types/electron';
|
import type { SavedNotepadState } from '@/types/electron';
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ interface AppConfig {
|
||||||
windowBounds?: WindowBounds;
|
windowBounds?: WindowBounds;
|
||||||
hasSeenWelcome?: boolean;
|
hasSeenWelcome?: boolean;
|
||||||
skipEjectConfirmation?: boolean;
|
skipEjectConfirmation?: boolean;
|
||||||
dismissedUpdates?: string[];
|
dismissedUpdates?: DismissedUpdate[];
|
||||||
zoomLevel?: number;
|
zoomLevel?: number;
|
||||||
notepad?: SavedNotepadState;
|
notepad?: SavedNotepadState;
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +154,9 @@ export function setSkipEjectConfirmation(skipEjectConfirmation: boolean) {
|
||||||
saveConfigAsync();
|
saveConfigAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDismissedUpdates = () => config.dismissedUpdates;
|
export const getDismissedUpdates = () => config.dismissedUpdates || [];
|
||||||
|
|
||||||
export function setDismissedUpdates(dismissedUpdates: string[]) {
|
export function setDismissedUpdates(dismissedUpdates: DismissedUpdate[]) {
|
||||||
config.dismissedUpdates = dismissedUpdates;
|
config.dismissedUpdates = dismissedUpdates;
|
||||||
saveConfigAsync();
|
saveConfigAsync();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
src/types/index.d.ts
vendored
5
src/types/index.d.ts
vendored
|
|
@ -47,6 +47,11 @@ export interface InstalledVersion {
|
||||||
size?: number;
|
size?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DismissedUpdate {
|
||||||
|
currentVersionPath: string;
|
||||||
|
targetVersion: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SelectOption {
|
export interface SelectOption {
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue