@@ -32,7 +32,7 @@ import {
32
32
insertLoggerOutputByVault ,
33
33
clearExpiredLoggerOutputRecords ,
34
34
} from "./localdb" ;
35
- import type InvioPlugin from "./main" ; // unavoidable
35
+ import InvioPlugin from "./main" ; // unavoidable
36
36
import { RemoteClient } from "./remote" ;
37
37
import { messyConfigToNormal } from "./configPersist" ;
38
38
import type { TransItemType } from "./i18n" ;
@@ -46,6 +46,8 @@ import {
46
46
restoreLogWritterInplace ,
47
47
} from "./moreOnLog" ;
48
48
49
+ const settingsPrefix = `Invio-Settings>` ;
50
+ const settingsSuffix = `<&`
49
51
class PasswordModal extends Modal {
50
52
plugin : InvioPlugin ;
51
53
newPassword : string ;
@@ -354,6 +356,45 @@ export class InvioSettingTab extends PluginSettingTab {
354
356
plugin . saveSettings ( ) ;
355
357
}
356
358
359
+
360
+ static async exportSettings ( plugin : InvioPlugin ) {
361
+ const t = ( x : TransItemType , vars ?: any ) => {
362
+ return plugin . i18n . t ( x , vars ) ;
363
+ } ;
364
+ const data = await plugin . loadData ( ) ;
365
+ await navigator . clipboard . writeText ( `${ settingsPrefix } ${ data . d } ${ settingsSuffix } ` ) ;
366
+ new Notice ( t ( "settings_export_msg" ) ) ;
367
+ }
368
+
369
+ static async importSettings ( plugin : InvioPlugin , restoredStr : string ) {
370
+ const t = ( x : TransItemType , vars ?: any ) => {
371
+ return plugin . i18n . t ( x , vars ) ;
372
+ } ;
373
+ if ( ! restoredStr ) {
374
+ new Notice ( t ( "settings_import_err" ) ) ;
375
+ return ;
376
+ }
377
+ if ( ! ( restoredStr . startsWith ( settingsPrefix ) && restoredStr . endsWith ( settingsSuffix ) ) ) {
378
+ new Notice ( t ( "settings_import_err" ) ) ;
379
+ return ;
380
+ }
381
+
382
+ await plugin . loadSettings ( restoredStr . replace ( settingsPrefix , '' ) . replace ( settingsSuffix , '' ) . trim ( ) ) ;
383
+ // Create dir if necessary.
384
+ const dir = plugin . settings . localWatchDir ;
385
+ if ( dir && ( typeof dir === 'string' ) ) {
386
+ await mkdirpInVault ( dir , plugin . app . vault ) ;
387
+ await plugin . switchWorkingDir ( dir ) ;
388
+
389
+ setTimeout ( ( ) => {
390
+ plugin . syncRun ( 'auto' ) ;
391
+ } , 100 )
392
+ } else {
393
+ log . error ( 'Imported settings not configured correctly.' )
394
+ }
395
+ await plugin . saveSettings ( ) ;
396
+ }
397
+
357
398
display ( ) : void {
358
399
let { containerEl } = this ;
359
400
@@ -838,18 +879,15 @@ export class InvioSettingTab extends PluginSettingTab {
838
879
text : t ( "settings_importexport" ) ,
839
880
} ) ;
840
881
841
- const settingsPrefix = `Invio-Settings>` ;
842
- const settingsSuffix = `<&`
882
+
843
883
new Setting ( importExportDiv )
844
884
. setName ( t ( "settings_export" ) )
845
885
. setDesc ( t ( "settings_export_desc" ) )
846
886
. addButton ( async ( button ) => {
847
887
button . setButtonText ( t ( "settings_export_desc_button" ) ) ;
848
888
button . onClick ( async ( ) => {
849
889
// new ExportSettingsQrCodeModal(this.app, this.plugin).open();
850
- const data = await this . plugin . loadData ( ) ;
851
- await navigator . clipboard . writeText ( `${ settingsPrefix } ${ data . d } ${ settingsSuffix } ` ) ;
852
- new Notice ( t ( "settings_export_msg" ) ) ;
890
+ InvioSettingTab . exportSettings ( this . plugin ) ;
853
891
} ) ;
854
892
} ) ;
855
893
@@ -868,29 +906,7 @@ export class InvioSettingTab extends PluginSettingTab {
868
906
. addButton ( async ( button ) => {
869
907
button . setButtonText ( t ( "settings_import_desc_button" ) ) ;
870
908
button . onClick ( async ( ) => {
871
- if ( ! restoredStr ) {
872
- new Notice ( t ( "settings_import_err" ) ) ;
873
- return ;
874
- }
875
- if ( ! ( restoredStr . startsWith ( settingsPrefix ) && restoredStr . endsWith ( settingsSuffix ) ) ) {
876
- new Notice ( t ( "settings_import_err" ) ) ;
877
- return ;
878
- }
879
-
880
- await this . plugin . loadSettings ( restoredStr . replace ( settingsPrefix , '' ) . replace ( settingsSuffix , '' ) . trim ( ) ) ;
881
- // Create dir if necessary.
882
- const dir = this . plugin . settings . localWatchDir ;
883
- if ( dir && ( typeof dir === 'string' ) ) {
884
- await mkdirpInVault ( dir , this . plugin . app . vault ) ;
885
- await this . plugin . switchWorkingDir ( dir ) ;
886
-
887
- setTimeout ( ( ) => {
888
- this . plugin . syncRun ( 'auto' ) ;
889
- } , 100 )
890
- } else {
891
- log . error ( 'Imported settings not configured correctly.' )
892
- }
893
- await this . plugin . saveSettings ( ) ;
909
+ await InvioSettingTab . importSettings ( this . plugin , restoredStr ) ;
894
910
this . hide ( ) ;
895
911
this . display ( ) ;
896
912
} ) ;
0 commit comments