diff --git a/src/platform/Hotkeys.ts b/src/platform/Hotkeys.ts index d0ee10b..6a18021 100644 --- a/src/platform/Hotkeys.ts +++ b/src/platform/Hotkeys.ts @@ -2,7 +2,7 @@ import { CommandSinkRef, HotkeyConfig, HotkeySystem } from "../livesplit-core"; import { expect } from "../util/OptionUtil"; export interface HotkeyImplementation { - ptr: number; + ptr?: number; config(): Promise | HotkeyConfig; setConfig(config: HotkeyConfig): void; activate(): void; @@ -11,10 +11,7 @@ export interface HotkeyImplementation { } class GlobalHotkeys implements HotkeyImplementation { - public ptr: number; - constructor(private hotkeySystem?: HotkeySystem) { - this.ptr = hotkeySystem?.ptr ?? 0; - } + constructor(private hotkeySystem?: HotkeySystem) { } public async config(): Promise { return expect( diff --git a/src/ui/LiveSplit.tsx b/src/ui/LiveSplit.tsx index 2ff9fcc..f3abb42 100644 --- a/src/ui/LiveSplit.tsx +++ b/src/ui/LiveSplit.tsx @@ -1170,7 +1170,9 @@ async function popOut( element.style.width = "100%"; element.style.height = "100%"; - if (hotkeySystem) HotkeySystem_add_window(hotkeySystem.ptr, childWindow); + if (hotkeySystem?.ptr) { + HotkeySystem_add_window(hotkeySystem.ptr, childWindow); + } createRoot(childDoc.body).render( ; refreshDb: () => Promise; }) { + const storeRun = async (run: Run) => { + try { + if (run.len() === 0) { + toast.error("Can't import empty splits."); + return; + } + await storeRunWithoutDisposing(run, undefined); + await refreshDb(); + } finally { + run[Symbol.dispose](); + } + }; + const addNewSplits = async () => { const run = Run.new(); run.pushSegment(Segment.new("Time")); - await storeRunWithoutDisposing(run, undefined); + await storeRun(run); }; const importSplitsFromArrayBuffer = async ( @@ -142,7 +155,7 @@ function View({ const [file] = buffer; using result = Run.parseArray(new Uint8Array(file), ""); if (result.parsedSuccessfully()) { - await storeRunWithoutDisposing(result.unwrap(), undefined); + await storeRun(result.unwrap()); } else { return Error("Couldn't parse the splits."); }