File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export interface PyWebview {
10
10
load_file : ( ) => Promise < string > ;
11
11
load_project_id : ( ) => Promise < string | null > ;
12
12
backup_project : ( content : string ) => Promise < boolean > ;
13
- restore_project : ( ) => Promise < void > ;
13
+ restore_project : ( ) => Promise < string > ;
14
14
}
15
15
}
16
16
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ import { usePromptContext } from "@utils/prompt";
16
16
import { usePalleteContext } from "@utils/pallete" ;
17
17
import { useVariablesContext } from "@utils/variables" ;
18
18
import { loadProject , saveProject } from "@utils/engineTools" ;
19
+ import { packProject } from "@utils/packerTools" ;
20
+ import { backupProject , getRestoredProject } from "@utils/desktopTools" ;
21
+ import { saveData } from "@utils/persistentTools" ;
19
22
import {
20
23
getBreadcrumb ,
21
24
getWindowTools ,
@@ -155,6 +158,8 @@ const createAppDataContext = () => {
155
158
useEffect ( ( ) => {
156
159
( async ( ) => {
157
160
const existingId = await loadExistingId ( ) ;
161
+ const restoredProject = await getRestoredProject ( ) ;
162
+ saveData ( `p:${ existingId } ` , restoredProject ) ;
158
163
setProjectId ( existingId ) ;
159
164
160
165
loadProject (
@@ -209,6 +214,32 @@ const createAppDataContext = () => {
209
214
statesList ,
210
215
customComponents ,
211
216
] ) ;
217
+
218
+ useEffect ( ( ) => {
219
+ const backupInterval = setInterval ( ( ) => {
220
+ const project = packProject (
221
+ projectId ! ,
222
+ nodeSystem ,
223
+ entries ,
224
+ {
225
+ states : statesList ,
226
+ customComponents,
227
+ }
228
+ ) ;
229
+
230
+ backupProject ( JSON . stringify ( project , null , 2 ) ) ;
231
+ } , 5000 ) ;
232
+
233
+ return ( ) => {
234
+ clearInterval ( backupInterval ) ;
235
+ }
236
+ } , [
237
+ customComponents ,
238
+ entries ,
239
+ nodeSystem ,
240
+ projectId ,
241
+ statesList ,
242
+ ] ) ;
212
243
213
244
const exposed = {
214
245
projectId,
Original file line number Diff line number Diff line change @@ -99,13 +99,27 @@ const setupDesktopTools = () => {
99
99
return ( await getApi ( ) ! . load_project_id ( ) ) || null ;
100
100
}
101
101
102
+ const backupProject = async ( content : string ) : Promise < boolean > => {
103
+ if ( ! isDesktop ( ) ) return false ;
104
+ await waitForPWV ( ) ;
105
+ return getApi ( ) ! . backup_project ( content ) ;
106
+ }
107
+
108
+ const getRestoredProject = async ( ) : Promise < string > => {
109
+ if ( ! isDesktop ( ) ) return "" ;
110
+ await waitForPWV ( ) ;
111
+ return getApi ( ) ! . restore_project ( ) ;
112
+ }
113
+
102
114
return {
103
115
isDesktop,
104
116
closeWindow,
105
117
toggleWindowFullscreen,
106
118
saveFile,
107
119
loadFile,
108
120
loadProjectId,
121
+ backupProject,
122
+ getRestoredProject
109
123
}
110
124
} ;
111
125
@@ -116,5 +130,7 @@ export const {
116
130
saveFile,
117
131
loadFile,
118
132
loadProjectId,
133
+ backupProject,
134
+ getRestoredProject,
119
135
} = setupDesktopTools ( ) ;
120
136
You can’t perform that action at this time.
0 commit comments