fix: extension settings are not retained in new sessions (#5154)

This commit is contained in:
Louis 2025-05-31 21:28:08 +07:00 committed by GitHub
parent 9265a56f04
commit 646ba86de8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 14 deletions

View File

@ -118,9 +118,10 @@ export abstract class BaseExtension implements ExtensionType {
setting.extensionName = this.name
})
try {
const oldSettings = localStorage.getItem(this.name)
const oldSettingsJson = localStorage.getItem(this.name)
// Persists new settings
if (oldSettings) {
if (oldSettingsJson) {
const oldSettings = JSON.parse(oldSettingsJson)
settings.forEach((setting) => {
// Keep setting value
if (setting.controllerProps && Array.isArray(oldSettings))
@ -169,13 +170,13 @@ export abstract class BaseExtension implements ExtensionType {
if (!this.name) return []
try {
const settingsString = localStorage.getItem(this.name);
if (!settingsString) return [];
const settings: SettingComponentProps[] = JSON.parse(settingsString);
return settings;
const settingsString = localStorage.getItem(this.name)
if (!settingsString) return []
const settings: SettingComponentProps[] = JSON.parse(settingsString)
return settings
} catch (err) {
console.warn(err);
return [];
console.warn(err)
return []
}
}
@ -201,8 +202,8 @@ export abstract class BaseExtension implements ExtensionType {
if (!updatedSettings.length) updatedSettings = componentProps as SettingComponentProps[]
localStorage.setItem(this.name, JSON.stringify(updatedSettings));
localStorage.setItem(this.name, JSON.stringify(updatedSettings))
updatedSettings.forEach((setting) => {
this.onSettingUpdate<typeof setting.controllerProps.value>(
setting.key,

View File

@ -49,6 +49,12 @@ pub fn install_extensions(app: tauri::AppHandle, force: bool) -> Result<(), Stri
if std::env::var("CLEAN").is_ok() {
clean_up = true;
}
log::info!(
"Installing extensions. Clean up: {}, Stored version: {}, App version: {}",
clean_up,
stored_version,
app_version
);
if !clean_up && stored_version == app_version && extensions_path.exists() {
return Ok(());
}

View File

@ -97,10 +97,7 @@ const ProvidersMenu = ({
<Dialog>
<DialogTrigger asChild>
<div
className="bg-main-view flex cursor-pointer px-4 my-1.5 items-center gap-1.5 text-main-view-fg/80"
onClick={() => {}}
>
<div className="bg-main-view flex cursor-pointer px-4 my-1.5 items-center gap-1.5 text-main-view-fg/80">
<IconCirclePlus size={18} />
<span className="capitalize">Add Provider</span>
</div>