From edc59d906241781e612d24d7a14a5abdc0ebdf1e Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Sun, 13 Apr 2025 17:11:55 +0200 Subject: [PATCH] Fix Bugs Introduced in Refactoring (#1049) The splits selection view did not correctly cause rerenders among other smaller bugs in there. I'm not sure how these bugs got introduced, as I barely made changes to the content of the functions, but these were completely different. Maybe this was Copilot's fault. Additionally, when using Tauri, there was a bug where we had two hotkey implementations at the same time for the pop out windows. One was the global hotkey implementation and one was the local one we add to the pop out window. This caused the hotkey to be triggered twice. --- src/platform/Hotkeys.ts | 7 ++----- src/ui/LiveSplit.tsx | 4 +++- src/ui/views/SplitsSelection.tsx | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) 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."); }