diff --git a/src/index.tsx b/src/index.tsx index 435c13a..c46a748 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -43,6 +43,8 @@ try { splits, splitsKey, layout, + comparison, + timingMethod, hotkeys, layoutWidth, layoutHeight, @@ -88,6 +90,8 @@ try { { serverUrl: generalSettings.serverUrl, }; } + +export async function storeTimingMethod(timingMethod: TimingMethod) { + const db = await getDb(); + + await db.put("settings", timingMethod, "timingMethod"); +} + +export async function loadTimingMethod(): Promise { + const db = await getDb(); + + return await db.get("settings", "timingMethod") ?? TimingMethod.RealTime; +} + +export async function storeComparison(comparison: string) { + const db = await getDb(); + + await db.put("settings", comparison, "comparison"); +} + +export async function loadComparison(): Promise { + const db = await getDb(); + + return await db.get("settings", "comparison"); +} diff --git a/src/ui/LiveSplit.tsx b/src/ui/LiveSplit.tsx index 99e1cbb..9ea68d5 100644 --- a/src/ui/LiveSplit.tsx +++ b/src/ui/LiveSplit.tsx @@ -52,6 +52,8 @@ type Menu = export interface Props { splits?: Uint8Array, layout?: Storage.LayoutSettings, + comparison?: string, + timingMethod: TimingMethod, hotkeys?: Storage.HotkeyConfigSettings, layoutWidth: number, layoutHeight: number, @@ -97,6 +99,8 @@ export class LiveSplit extends React.Component { const splitsKey = await Storage.loadSplitsKey(); const splits = splitsKey !== undefined ? await Storage.loadSplits(splitsKey) : undefined; const layout = await Storage.loadLayout(); + const comparison = await Storage.loadComparison(); + const timingMethod = await Storage.loadTimingMethod(); const hotkeys = await Storage.loadHotkeys(); const [layoutWidth, layoutHeight] = await Storage.loadLayoutDims(); const generalSettings = await Storage.loadGeneralSettings(); @@ -105,6 +109,8 @@ export class LiveSplit extends React.Component { splits, splitsKey, layout, + comparison, + timingMethod, hotkeys, layoutWidth, layoutHeight, @@ -171,6 +177,11 @@ export class LiveSplit extends React.Component { } } + if (props.comparison !== undefined) { + timer.setCurrentComparison(props.comparison); + } + timer.setCurrentTimingMethod(props.timingMethod); + let layout: Option = null; try { const data = props.layout; @@ -775,17 +786,33 @@ export class LiveSplit extends React.Component { currentComparisonChanged(): void { if (this.state != null) { - this.setState({ - currentComparison: this.state.eventSink.currentComparison(), - }); + const currentComparison = this.state.eventSink.currentComparison(); + + (async () => { + try { + await Storage.storeComparison(currentComparison); + } catch { + // It's fine if this fails. + } + })(); + + this.setState({ currentComparison }); } } currentTimingMethodChanged(): void { if (this.state != null) { - this.setState({ - currentTimingMethod: this.state.eventSink.currentTimingMethod(), - }); + const currentTimingMethod = this.state.eventSink.currentTimingMethod(); + + (async () => { + try { + await Storage.storeTimingMethod(currentTimingMethod); + } catch { + // It's fine if this fails. + } + })(); + + this.setState({ currentTimingMethod }); } } diff --git a/webpack.config.js b/webpack.config.js index 18de4b7..ea0ba08 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -123,6 +123,9 @@ export default async (env, argv) => { appleIcon: { offset: 10, }, + appleStartup: { + offset: 15, + }, android: { background: true, offset: 10,