Skip to content

Commit bf97c4c

Browse files
committed
Updates option
1 parent 91676f6 commit bf97c4c

6 files changed

Lines changed: 101 additions & 5 deletions

File tree

src/components/Actions/index.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { Plus } from "lucide-react";
1+
import { useCallback, useEffect, useState } from "react";
2+
import { GitPullRequestArrow, Plus } from "lucide-react";
23

34
import type { ProjectData } from "../../defs/ProjectData";
45

5-
import { getData, openProject, storeData } from "../../utils/desktopTools";
66
import { generateId } from "../../utils/generatorTools";
7+
import {
8+
checkUpdates,
9+
getData,
10+
openProject,
11+
storeData,
12+
updateTools,
13+
} from "../../utils/desktopTools";
714

815
import "./style.css";
916

1017
export function Actions() {
11-
const openNewProject = () => {
18+
const [updatesAvailable, setUpdatesAvailable] = useState(false);
19+
const openNewProject = useCallback(() => {
1220
const projectId = generateId();
1321

1422
const newProject: ProjectData = {
@@ -33,7 +41,24 @@ export function Actions() {
3341

3442
location.reload();
3543
})();
36-
};
44+
}, []);
45+
46+
const startUpdate = useCallback(() => {
47+
const message = [
48+
"Are you sure you want to update the tools?",
49+
"This will close the application.",
50+
"You will need to start it again manually.",
51+
].join(" ");
52+
53+
if (!confirm(message)) return;
54+
updateTools();
55+
}, []);
56+
57+
useEffect(() => {
58+
(async () => {
59+
setUpdatesAvailable(await checkUpdates());
60+
})();
61+
}, []);
3762

3863
return (<>
3964
<div className="actions">
@@ -43,6 +68,17 @@ export function Actions() {
4368
New Project
4469
</span>
4570
</button>
71+
72+
<button
73+
className="action"
74+
onClick={startUpdate}
75+
disabled={!updatesAvailable}
76+
>
77+
<GitPullRequestArrow className="action-icon" />
78+
<span className="action-name">
79+
Update Tools
80+
</span>
81+
</button>
4682
</div>
4783
</>);
4884
}

src/components/Actions/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@
4949
opacity: 1;
5050
}
5151

52+
.action[disabled] {
53+
cursor: not-allowed;
54+
opacity: 1;
55+
}
56+
57+
.action[disabled] .action-icon {
58+
opacity: 0.1;
59+
}
60+
61+
.action[disabled]:active .action-icon {
62+
scale: 1;
63+
}
64+

src/components/AppBar/index.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
import { closeWindow } from "../../utils/desktopTools";
1+
import { useEffect, useState } from "react";
2+
import { closeWindow, getVersion } from "../../utils/desktopTools";
23

34
import "./style.css";
45

56
export function AppBar() {
7+
const [version, setVersion] = useState<string>("v0");
8+
9+
useEffect(() => {
10+
(async () => {
11+
const appVersion = await getVersion();
12+
setVersion(appVersion);
13+
})();
14+
}, []);
15+
616
return (<>
717
<div className="app-bar">
818
<div className="window-actions">
@@ -12,6 +22,10 @@ export function AppBar() {
1222
onClick={() => closeWindow()}
1323
/>
1424
</div>
25+
26+
<div className="version-info">
27+
Launcher {version}
28+
</div>
1529
</div>
1630
</>);
1731
}

src/components/AppBar/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
width: 100%;
55
z-index: 1000;
66
pointer-events: none;
7+
display: flex;
8+
align-items: start;
79
}
810

911
.window-actions {
1012
display: flex;
1113
gap: 0.5rem;
1214
padding: 1rem;
15+
flex: 1;
1316
}
1417

1518
.window-action-button {
@@ -56,3 +59,9 @@
5659
cursor: not-allowed;
5760
}
5861

62+
.version-info {
63+
padding: 0.25rem;
64+
font-size: 0.75rem;
65+
font-weight: 200;
66+
}
67+

src/defs/PyWebview.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export interface PyWebview {
44
open_project: (project_id: string) => Promise<void>;
55
get_data: () => Promise<string>;
66
store_data: (data: string) => Promise<boolean>;
7+
get_version: () => Promise<string>;
8+
check_updates: () => Promise<boolean>;
9+
update: () => Promise<void>;
710
}
811
};
912

src/utils/desktopTools.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,29 @@ const setupDesktopTools = () => {
4848
return await getApi()?.store_data(data) || false;
4949
}
5050

51+
const getVersion = async (): Promise<string> => {
52+
await waitForPWV();
53+
return await getApi()?.get_version() || "v0";
54+
}
55+
56+
const checkUpdates = async (): Promise<boolean> => {
57+
await waitForPWV();
58+
return await getApi()?.check_updates() || false;
59+
}
60+
61+
const updateTools = async () => {
62+
await waitForPWV();
63+
return await getApi()?.update();
64+
}
65+
5166
return {
5267
closeWindow,
5368
openProject,
5469
getData,
5570
storeData,
71+
getVersion,
72+
checkUpdates,
73+
updateTools,
5674
}
5775
};
5876

@@ -61,5 +79,8 @@ export const {
6179
openProject,
6280
getData,
6381
storeData,
82+
getVersion,
83+
checkUpdates,
84+
updateTools,
6485
} = setupDesktopTools();
6586

0 commit comments

Comments
 (0)