1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Use Electron safeStorage for keychain support (#10535)

This commit is contained in:
Henry Heino
2024-08-08 11:53:43 -07:00
committed by GitHub
parent 8d8c91ef50
commit 08eab7a73a
18 changed files with 351 additions and 41 deletions

View File

@ -142,7 +142,6 @@ export type SettingMetadataSection = {
export type MetadataBySection = SettingMetadataSection[];
class Setting extends BaseModel {
public static schemaUrl = 'https://joplinapp.org/schema/settings.json';
// For backward compatibility
@ -976,19 +975,10 @@ class Setting extends BaseModel {
// Also we don't control what happens on the keychain - the values can be edited or deleted
// outside the application. For that reason, we rewrite it every time the values are saved,
// even if, internally, they haven't changed.
// As an optimisation, we check if the value exists on the keychain before writing it again.
try {
const passwordName = `setting.${s.key}`;
const currentValue = await this.keychainService().password(passwordName);
if (currentValue !== valueAsString) {
const wasSet = await this.keychainService().setPassword(passwordName, valueAsString);
if (wasSet) continue;
} else {
// The value is already in the keychain - so nothing to do
// Make sure to `continue` here otherwise it will save the password
// in clear text in the database.
continue;
}
const wasSet = await this.keychainService().setPassword(passwordName, valueAsString);
if (wasSet) continue;
} catch (error) {
logger.error(`Could not set setting on the keychain. Will be saved to database instead: ${s.key}:`, error);
}