Skip to content

Commit d28bee4

Browse files
committed
Cache clearing on app version change
1 parent 93ec4f1 commit d28bee4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/App.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,29 @@ import NewProjectView from "./views/new-project/new-project-view";
1313
import SettingsView from "./views/settings/settings-view";
1414
import useBetterState from "./hooks/useBetterState";
1515
import FirstBoot from "./views/first-boot/first-boot";
16+
import { getVersion } from "@tauri-apps/api/app";
17+
import { TauriRouter } from "./utils/tauri-router";
1618

1719
function App() {
1820
const globalContext = useContext(GlobalContext.Context);
1921
const isLoading = useBetterState(true);
2022
const isFirstBoot = useBetterState(false);
2123

2224
useEffect(() => {
23-
// window.localStorage.removeItem("pastFirstBoot");
24-
const firstBoot = !window.localStorage.getItem("pastFirstBoot");
25+
let version = window.localStorage.getItem("app_version");
26+
const check = async () => {
27+
const appVersion = await getVersion();
28+
if (!version || appVersion !== version) {
29+
TauriRouter.delete_template_cache();
30+
window.localStorage.setItem("app_version", appVersion);
31+
}
32+
};
33+
check();
34+
}, []);
35+
36+
useEffect(() => {
37+
// window.localStorage.removeItem("past_first_boot");
38+
const firstBoot = !window.localStorage.getItem("past_first_boot");
2539

2640
const load = async () => {
2741
isFirstBoot.set(true);

src/views/first-boot/first-boot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function FirstBoot() {
3333

3434
function LastStage() {
3535
useEffect(() => {
36-
window.localStorage.setItem("pastFirstBoot", "true");
36+
window.localStorage.setItem("past_first_boot", "true");
3737
window.location.reload();
3838
}, []);
3939
return null;

0 commit comments

Comments
 (0)