1- import { Plus } from "lucide-react" ;
1+ import { useCallback , useEffect , useState } from "react" ;
2+ import { GitPullRequestArrow , Plus } from "lucide-react" ;
23
34import type { ProjectData } from "../../defs/ProjectData" ;
45
5- import { getData , openProject , storeData } from "../../utils/desktopTools" ;
66import { generateId } from "../../utils/generatorTools" ;
7+ import {
8+ checkUpdates ,
9+ getData ,
10+ openProject ,
11+ storeData ,
12+ updateTools ,
13+ } from "../../utils/desktopTools" ;
714
815import "./style.css" ;
916
1017export 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}
0 commit comments