forked from gitbutlerapp/gitbutler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds configurable telemetry settings for error reporting and me…
…trics tracking
- Loading branch information
Showing
11 changed files
with
248 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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
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,84 @@ | ||
/** | ||
* This file contains functions for managing application settings. | ||
* Settings are persisted in <Application Data>/settings.json and are used by both the UI and the backend. | ||
* | ||
* @module appSettings | ||
*/ | ||
|
||
import { writable, type Writable } from 'svelte/store'; | ||
import { Store } from 'tauri-plugin-store-api'; | ||
|
||
const store = new Store('settings.json'); | ||
|
||
/** | ||
* Provides a writable store for obtaining or setting the current state of application metrics. | ||
* The application metrics can be enabled or disabled by setting the value of the store to true or false. | ||
* @returns A writable store with the appMetricsEnabled config. | ||
*/ | ||
export function appMetricsEnabled() { | ||
return persisted(true, 'appMetricsEnabled'); | ||
} | ||
|
||
/** | ||
* Provides a writable store for obtaining or setting the current state of application error reporting. | ||
* The application error reporting can be enabled or disabled by setting the value of the store to true or false. | ||
* @returns A writable store with the appErrorReportingEnabled config. | ||
*/ | ||
export function appErrorReportingEnabled() { | ||
return persisted(true, 'appErrorReportingEnabled'); | ||
} | ||
|
||
function persisted<T>(initial: T, key: string): Writable<T> & { onDisk: () => Promise<T> } { | ||
const setAndPersist = async (value: T, set: (value: T) => void) => { | ||
await store.set(key, value); | ||
await store.save(); | ||
|
||
set(value); | ||
}; | ||
|
||
const synchronize = async (set: (value: T) => void): Promise<void> => { | ||
const value = await storeValueWithDefault(initial, key); | ||
set(value); | ||
}; | ||
|
||
const update = () => { | ||
throw 'Not implemented'; | ||
}; | ||
|
||
const thisStore = writable<T>(initial, (set) => { | ||
synchronize(set); | ||
}); | ||
|
||
const set = async (value: T) => { | ||
setAndPersist(value, thisStore.set); | ||
}; | ||
|
||
const onDisk = async () => { | ||
return storeValueWithDefault(initial, key); | ||
}; | ||
|
||
const subscribe = thisStore.subscribe; | ||
|
||
return { | ||
subscribe, | ||
set, | ||
update, | ||
onDisk | ||
}; | ||
} | ||
|
||
async function storeValueWithDefault<T>(initial: T, key: string): Promise<T> { | ||
try { | ||
await store.load(); | ||
} catch (e) { | ||
// If file does not exist, reset it | ||
store.reset(); | ||
} | ||
const stored = (await store.get(key)) as T; | ||
|
||
if (stored === null) { | ||
return initial; | ||
} else { | ||
return stored; | ||
} | ||
} |
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
Oops, something went wrong.