-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist user defines mode and manual user defines txt in local storage
- Loading branch information
1 parent
ed19248
commit 6e81cf1
Showing
7 changed files
with
115 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
src/ui/storage/commands/mergeWithDeviceOptionsFromStorage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
DeviceTarget, | ||
UserDefine, | ||
UserDefineKey, | ||
} from '../../gql/generated/types'; | ||
import { DeviceOptions, IApplicationStorage } from '../index'; | ||
|
||
const mergeWithDeviceOptionsFromStorage = async ( | ||
storage: IApplicationStorage, | ||
deviceTarget: DeviceTarget | null, | ||
deviceOptions: DeviceOptions | ||
): Promise<DeviceOptions> => { | ||
if (deviceTarget === null) { | ||
return deviceOptions; | ||
} | ||
const savedBindingPhrase = await storage.GetBindingPhrase(); | ||
const savedTargetOptions = await storage.GetDeviceOptions(deviceTarget); | ||
const userDefineOptions = deviceOptions.userDefineOptions.map( | ||
(deviceOption) => { | ||
if (savedTargetOptions === null) { | ||
return deviceOption; | ||
} | ||
const savedOption = savedTargetOptions?.userDefineOptions.find( | ||
({ key }) => key === deviceOption.key | ||
); | ||
if (savedOption === undefined) { | ||
return deviceOption; | ||
} | ||
|
||
const { enabled } = savedOption; | ||
let { value } = savedOption; | ||
if ( | ||
deviceOption.key === UserDefineKey.BINDING_PHRASE && | ||
savedBindingPhrase.length > 0 | ||
) { | ||
value = savedBindingPhrase; | ||
} | ||
const opt: UserDefine = { | ||
...deviceOption, | ||
enabled, | ||
value, | ||
}; | ||
return opt; | ||
} | ||
); | ||
return { | ||
userDefinesMode: | ||
savedTargetOptions?.userDefinesMode ?? deviceOptions.userDefinesMode, | ||
userDefinesTxt: | ||
savedTargetOptions?.userDefinesTxt ?? deviceOptions?.userDefinesTxt, | ||
userDefineOptions, | ||
}; | ||
}; | ||
|
||
export default mergeWithDeviceOptionsFromStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { DeviceTarget, UserDefineKey } from '../../gql/generated/types'; | ||
import { DeviceOptions, IApplicationStorage } from '../index'; | ||
|
||
const persistDeviceOptions = async ( | ||
storage: IApplicationStorage, | ||
deviceTarget: DeviceTarget, | ||
deviceOptions: DeviceOptions | ||
): Promise<void> => { | ||
if (deviceTarget !== null) { | ||
await storage.SaveDeviceOptions(deviceTarget, deviceOptions); | ||
|
||
const bindingPhrase = deviceOptions.userDefineOptions.find( | ||
({ key }) => key === UserDefineKey.BINDING_PHRASE | ||
); | ||
if ( | ||
bindingPhrase !== undefined && | ||
bindingPhrase.enabled && | ||
bindingPhrase.value && | ||
bindingPhrase.value?.length > 0 | ||
) { | ||
await storage.SetBindingPhrase(bindingPhrase.value); | ||
} | ||
} | ||
}; | ||
|
||
export default persistDeviceOptions; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters