@@ -11,6 +11,7 @@ import darkIcon from "./imgs/dark-icon.png";
11
11
import { useThemeStore } from "@/stores/themeStore" ;
12
12
import { useUpdateStore } from "@/stores/updateStore" ;
13
13
import { OpenURLWithBrowser } from "@/utils/index" ;
14
+ import { useAppStore } from "@/stores/appStore" ;
14
15
15
16
interface State {
16
17
loading ?: boolean ;
@@ -33,6 +34,7 @@ const UpdateApp = ({ checkUpdate, relaunchApp }: UpdateAppProps) => {
33
34
const isOptional = useUpdateStore ( ( state ) => state . isOptional ) ;
34
35
const updateInfo = useUpdateStore ( ( state ) => state . updateInfo ) ;
35
36
const setUpdateInfo = useUpdateStore ( ( state ) => state . setUpdateInfo ) ;
37
+ const addError = useAppStore ( ( state ) => state . addError ) ;
36
38
37
39
const state = useReactive < State > ( { download : 0 } ) ;
38
40
@@ -65,24 +67,28 @@ const UpdateApp = ({ checkUpdate, relaunchApp }: UpdateAppProps) => {
65
67
} , [ state . total , state . download ] ) ;
66
68
67
69
const handleDownload = async ( ) => {
68
- if ( state . loading ) return ;
69
-
70
- state . loading = true ;
71
-
72
- await updateInfo ?. downloadAndInstall ( ( progress : any ) => {
73
- switch ( progress . event ) {
74
- case "Started" :
75
- state . total = progress . data . contentLength ;
76
- break ;
77
- case "Progress" :
78
- state . download += progress . data . chunkLength ;
79
- break ;
80
- }
81
- } ) ;
82
-
83
- state . loading = false ;
84
-
85
- relaunchApp ( ) ;
70
+ try {
71
+ if ( state . loading ) return ;
72
+
73
+ state . loading = true ;
74
+
75
+ await updateInfo ?. downloadAndInstall ( ( progress : any ) => {
76
+ switch ( progress . event ) {
77
+ case "Started" :
78
+ state . total = progress . data . contentLength ;
79
+ break ;
80
+ case "Progress" :
81
+ state . download += progress . data . chunkLength ;
82
+ break ;
83
+ }
84
+ } ) ;
85
+
86
+ relaunchApp ( ) ;
87
+ } catch ( error ) {
88
+ addError ( String ( error ) ) ;
89
+ } finally {
90
+ state . loading = false ;
91
+ }
86
92
} ;
87
93
88
94
const handleCancel = ( ) => {
0 commit comments