Skip to content

Commit

Permalink
fixed 1.0.5 new settings bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanosborne committed Jan 20, 2024
1 parent 2be2f24 commit 1fc22bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
10 changes: 0 additions & 10 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ function Main(): JSX.Element {
void setupTauriEventListeners()
void getWiresockVersion()

// Handle version 1.0.5 adding 'startMinimized' setting
if (settings.startMinimized === undefined) {
setSettings({ ...settings, startMinimized: false })
}

// Handle version 1.0.5 adding 'minimizeToTray' setting
if (settings.minimizeToTray === undefined) {
setSettings({ ...settings, minimizeToTray: true })
}

// Show the app window
if (!settings.startMinimized) {
void invoke('show_app')
Expand Down
12 changes: 6 additions & 6 deletions src/models/SettingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default class SettingsModel {
startMinimized: boolean
minimizeToTray: boolean

constructor() {
this.autoStart = false
this.autoConnectTunnelID = ''
this.logLevel = 'debug'
this.startMinimized = false
this.minimizeToTray = true
constructor(data?: Partial<SettingsModel>) {
this.autoStart = data?.autoStart ?? false
this.autoConnectTunnelID = data?.autoConnectTunnelID ?? ''
this.logLevel = data?.logLevel ?? 'debug'
this.startMinimized = data?.startMinimized ?? false
this.minimizeToTray = data?.minimizeToTray ?? true
}
}
5 changes: 3 additions & 2 deletions src/utilities/storageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function saveSettingsToStorage(settings: SettingsModel): void {
export function getSettingsFromStorage(): SettingsModel {
console.log('Retrieving settings from local storage')
const settingsStorageItem = localStorage.getItem('settings')
const settings = settingsStorageItem !== null ? JSON.parse(settingsStorageItem) : new SettingsModel()
return settings
const settingsData = settingsStorageItem !== null ? JSON.parse(settingsStorageItem) : {}
// Use the constructor to handle default values
return new SettingsModel(settingsData)
}

0 comments on commit 1fc22bb

Please sign in to comment.