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.
This commit is contained in:
Christopher Serr
2025-04-13 17:11:55 +02:00
committed by GitHub
parent 7e54e84631
commit edc59d9062
3 changed files with 20 additions and 8 deletions
+2 -5
View File
@@ -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> | 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<HotkeyConfig> {
return expect(
+3 -1
View File
@@ -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(
<ShowLayout
+15 -2
View File
@@ -130,10 +130,23 @@ function View({
splitsInfos?: Array<[number, SplitsInfo]>;
refreshDb: () => Promise<void>;
}) {
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.");
}