@@ -14,6 +14,7 @@ interface ObsidianGitSettings {
14
14
commitMessage : string ;
15
15
commitDateFormat : string ;
16
16
autoSaveInterval : number ;
17
+ autoPullInterval : number ;
17
18
autoPullOnBoot : boolean ;
18
19
disablePush : boolean ;
19
20
pullBeforePush : boolean ;
@@ -24,6 +25,7 @@ const DEFAULT_SETTINGS: ObsidianGitSettings = {
24
25
commitMessage : "vault backup: {{date}}" ,
25
26
commitDateFormat : "YYYY-MM-DD HH:mm:ss" ,
26
27
autoSaveInterval : 0 ,
28
+ autoPullInterval : 0 ,
27
29
autoPullOnBoot : false ,
28
30
disablePush : false ,
29
31
pullBeforePush : true ,
@@ -36,7 +38,8 @@ export default class ObsidianGit extends Plugin {
36
38
settings : ObsidianGitSettings ;
37
39
statusBar : StatusBar ;
38
40
state : PluginState = PluginState . idle ;
39
- intervalID : number ;
41
+ intervalIDBackup : number ;
42
+ intervalIDPull : number ;
40
43
lastUpdate : number ;
41
44
gitReady = false ;
42
45
conflictOutputFile = "conflict-files-obsidian-git.md" ;
@@ -125,6 +128,9 @@ export default class ObsidianGit extends Plugin {
125
128
if ( this . settings . autoSaveInterval > 0 ) {
126
129
this . enableAutoBackup ( ) ;
127
130
}
131
+ if ( this . settings . autoPullInterval > 0 ) {
132
+ this . enableAutoPull ( ) ;
133
+ }
128
134
}
129
135
130
136
} catch ( error ) {
@@ -298,19 +304,35 @@ export default class ObsidianGit extends Plugin {
298
304
299
305
enableAutoBackup ( ) {
300
306
const minutes = this . settings . autoSaveInterval ;
301
- this . intervalID = window . setInterval (
307
+ this . intervalIDBackup = window . setInterval (
302
308
async ( ) => await this . createBackup ( true ) ,
303
309
minutes * 60000
304
310
) ;
305
- this . registerInterval ( this . intervalID ) ;
311
+ this . registerInterval ( this . intervalIDBackup ) ;
312
+ }
313
+
314
+ enableAutoPull ( ) {
315
+ const minutes = this . settings . autoPullInterval ;
316
+ this . intervalIDPull = window . setInterval (
317
+ async ( ) => await this . pullChangesFromRemote ( ) ,
318
+ minutes * 60000
319
+ ) ;
320
+ this . registerInterval ( this . intervalIDPull ) ;
306
321
}
307
322
308
323
disableAutoBackup ( ) : boolean {
309
- if ( this . intervalID ) {
310
- clearInterval ( this . intervalID ) ;
324
+ if ( this . intervalIDBackup ) {
325
+ clearInterval ( this . intervalIDBackup ) ;
311
326
return true ;
312
327
}
328
+ return false ;
329
+ }
313
330
331
+ disableAutoPull ( ) : boolean {
332
+ if ( this . intervalIDPull ) {
333
+ clearInterval ( this . intervalIDPull ) ;
334
+ return true ;
335
+ }
314
336
return false ;
315
337
}
316
338
@@ -429,7 +451,7 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
429
451
) ;
430
452
} else if (
431
453
plugin . settings . autoSaveInterval <= 0 &&
432
- plugin . intervalID
454
+ plugin . intervalIDBackup
433
455
) {
434
456
plugin . disableAutoBackup ( ) &&
435
457
new Notice ( "Automatic backup disabled!" ) ;
@@ -439,6 +461,37 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
439
461
}
440
462
} )
441
463
) ;
464
+ new Setting ( containerEl )
465
+ . setName ( "Auto pull interval (minutes)" )
466
+ . setDesc (
467
+ "Pull changes every X minutes. To disable automatic pull, specify negative value or zero (default)"
468
+ )
469
+ . addText ( ( text ) =>
470
+ text
471
+ . setValue ( String ( plugin . settings . autoPullInterval ) )
472
+ . onChange ( ( value ) => {
473
+ if ( ! isNaN ( Number ( value ) ) ) {
474
+ plugin . settings . autoPullInterval = Number ( value ) ;
475
+ plugin . saveSettings ( ) ;
476
+
477
+ if ( plugin . settings . autoPullInterval > 0 ) {
478
+ plugin . disableAutoPull ( ) ;
479
+ plugin . enableAutoPull ( ) ;
480
+ new Notice (
481
+ `Automatic pull enabled! Every ${ plugin . settings . autoPullInterval } minutes.`
482
+ ) ;
483
+ } else if (
484
+ plugin . settings . autoPullInterval <= 0 &&
485
+ plugin . intervalIDPull
486
+ ) {
487
+ plugin . disableAutoPull ( ) &&
488
+ new Notice ( "Automatic pull disabled!" ) ;
489
+ }
490
+ } else {
491
+ new Notice ( "Please specify a valid number." ) ;
492
+ }
493
+ } )
494
+ ) ;
442
495
443
496
new Setting ( containerEl )
444
497
. setName ( "Commit message" )
@@ -680,7 +733,6 @@ class ChangedFilesModal extends FuzzySuggestModal<FileStatusResult> {
680
733
super ( plugin . app ) ;
681
734
this . plugin = plugin ;
682
735
this . changedFiles = changedFiles ;
683
- console . log ( changedFiles ) ;
684
736
this . setPlaceholder ( "Only files in vault can be openend!" ) ;
685
737
}
686
738
0 commit comments