Skip to content

Commit 43fd84a

Browse files
committed
fix(startup): wait to show main window until repo restore
1 parent 32b6025 commit 43fd84a

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/components/App.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {useState, useCallback, useEffect, useRef} from "react";
2+
import {invoke} from "@tauri-apps/api/core";
23
import {listen} from "@tauri-apps/api/event";
34
import {ask, open} from "@tauri-apps/plugin-dialog";
45
import {Toast} from "./Toast";
@@ -139,6 +140,7 @@ export function App() {
139140
} = useUpdateFlow();
140141

141142
const [repoPath, setRepoPath] = useState<string | null>(null);
143+
const [ready, setReady] = useState(false);
142144
const [recentRepos, setRecentRepos] = useState<string[]>(() => {
143145
try {
144146
return JSON.parse(localStorage.getItem("gitmun.recentRepos") ?? "[]");
@@ -430,20 +432,31 @@ export function App() {
430432

431433
useEffect(() => {
432434
const stored = localStorage.getItem(REPO_STORAGE_KEY);
433-
if (!stored) return;
435+
if (!stored) {
436+
setReady(true);
437+
return;
438+
}
434439
api.validateRepoPath(stored).then(() => {
435440
setRepoPath(stored);
441+
setReady(true);
436442
}).catch(() => {
437443
localStorage.removeItem(REPO_STORAGE_KEY);
438444
setRecentRepos(prev => {
439445
const next = prev.filter(p => p !== stored);
440446
localStorage.setItem("gitmun.recentRepos", JSON.stringify(next));
441447
return next;
442448
});
449+
setReady(true);
443450
});
444451
// eslint-disable-next-line react-hooks/exhaustive-deps
445452
}, []);
446453

454+
useEffect(() => {
455+
if (ready) {
456+
invoke("show_window", {label: "main"}).catch(() => {});
457+
}
458+
}, [ready]);
459+
447460
useEffect(() => {
448461
if (repoPath) {
449462
localStorage.setItem(REPO_STORAGE_KEY, repoPath);

‎src/windows/main.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from "react";
22
import { createRoot } from "react-dom/client";
3-
import { invoke } from "@tauri-apps/api/core";
43
import { App } from "../components/App";
54
import "../styles/tokens.css";
65
import "../styles/animations.css";
@@ -16,5 +15,4 @@ document.addEventListener("contextmenu", (e) => {
1615
const root = document.getElementById("root");
1716
if (root) {
1817
createRoot(root).render(<App />);
19-
setTimeout(() => void invoke("show_window", { label: "main" }), 0);
2018
}

0 commit comments

Comments
 (0)