@@ -49,9 +49,28 @@ function backupRestore() {
4949 try {
5050 const settings = appSettings . value ;
5151 const keyBindings = await fsOperation ( KEYBINDING_FILE ) . readFile ( "json" ) ;
52- const installedPlugins = (
53- await fsOperation ( window . PLUGIN_DIR ) . lsDir ( )
54- ) . map ( ( plugin ) => plugin . name ) ;
52+ const plugins = await fsOperation ( window . PLUGIN_DIR ) . lsDir ( ) ;
53+ const installedPlugins = [ ] ;
54+ const installedPluginsWithSource = [ ] ;
55+
56+ for ( const plugin of plugins ) {
57+ try {
58+ const pluginJsonPath = Url . join (
59+ window . PLUGIN_DIR ,
60+ plugin . name ,
61+ "plugin.json" ,
62+ ) ;
63+ const pluginJson = await fsOperation ( pluginJsonPath ) . readFile ( "json" ) ;
64+
65+ if ( pluginJson . source ) {
66+ installedPluginsWithSource . push ( pluginJson . source ) ;
67+ } else {
68+ installedPlugins . push ( plugin . name ) ;
69+ }
70+ } catch ( error ) {
71+ installedPlugins . push ( plugin . name ) ;
72+ }
73+ }
5574
5675 const { url } = await FileBrowser ( "folder" , strings [ "select folder" ] ) ;
5776
@@ -74,7 +93,7 @@ function backupRestore() {
7493 const backupString = JSON . stringify ( {
7594 settings,
7695 keyBindings,
77- installedPlugins,
96+ installedPlugins : [ ... installedPlugins , ... installedPluginsWithSource ] ,
7897 } ) ;
7998
8099 await backupFileFS . writeFile ( backupString ) ;
@@ -130,35 +149,48 @@ backupRestore.restore = async function (url) {
130149 for ( const id of installedPlugins ) {
131150 try {
132151 if ( ! id ) continue ;
133- const pluginUrl = Url . join ( constants . API_BASE , `plugin/${ id } ` ) ;
134- const remotePlugin = await fsOperation ( pluginUrl )
135- . readFile ( "json" )
136- . catch ( ( ) => null ) ;
137-
138- if ( remotePlugin ) {
139- let purchaseToken = null ;
140- if ( Number . parseFloat ( remotePlugin . price ) > 0 ) {
141- try {
142- const [ product ] = await helpers . promisify ( iap . getProducts , [
143- remotePlugin . sku ,
144- ] ) ;
145- if ( product ) {
146- async function getPurchase ( sku ) {
147- const purchases = await helpers . promisify ( iap . getPurchases ) ;
148- const purchase = purchases . find ( ( p ) =>
149- p . productIds . includes ( sku ) ,
150- ) ;
151- return purchase ;
152+ if (
153+ id . startsWith ( "content://" ) ||
154+ id . startsWith ( "file://" ) ||
155+ id . includes ( "/" )
156+ ) {
157+ // Local plugin case - pass URI directly
158+ toast ( "Restoring plugins" ) ;
159+ await installPlugin ( id ) ;
160+ } else {
161+ // Remote plugin case - fetch from API
162+ const pluginUrl = Url . join ( constants . API_BASE , `plugin/${ id } ` ) ;
163+ const remotePlugin = await fsOperation ( pluginUrl )
164+ . readFile ( "json" )
165+ . catch ( ( ) => null ) ;
166+
167+ if ( remotePlugin ) {
168+ let purchaseToken = null ;
169+ if ( Number . parseFloat ( remotePlugin . price ) > 0 ) {
170+ try {
171+ const [ product ] = await helpers . promisify ( iap . getProducts , [
172+ remotePlugin . sku ,
173+ ] ) ;
174+ if ( product ) {
175+ async function getPurchase ( sku ) {
176+ const purchases = await helpers . promisify (
177+ iap . getPurchases ,
178+ ) ;
179+ const purchase = purchases . find ( ( p ) =>
180+ p . productIds . includes ( sku ) ,
181+ ) ;
182+ return purchase ;
183+ }
184+ const purchase = await getPurchase ( product . productId ) ;
185+ purchaseToken = purchase ?. purchaseToken ;
152186 }
153- const purchase = await getPurchase ( product . productId ) ;
154- purchaseToken = purchase ?. purchaseToken ;
187+ } catch ( error ) {
188+ helpers . error ( error ) ;
155189 }
156- } catch ( error ) {
157- helpers . error ( error ) ;
158190 }
191+ toast ( "Restoring plugins" , 3000 ) ;
192+ await installPlugin ( id , remotePlugin . name , purchaseToken ) ;
159193 }
160- toast ( "Restoring plugins" , 3000 ) ;
161- await installPlugin ( id , remotePlugin . name , purchaseToken ) ;
162194 }
163195 } catch ( error ) {
164196 console . error ( `Error restoring plugin ${ id } :` , error ) ;
0 commit comments