@@ -2,9 +2,9 @@ import { debounce } from "obsidian";
2
2
import type ObsidianGit from "./main" ;
3
3
4
4
export default class AutomaticsManager {
5
- timeoutIDCommitAndSync ?: number ;
6
- timeoutIDPush ?: number ;
7
- timeoutIDPull ?: number ;
5
+ private timeoutIDCommitAndSync ?: number ;
6
+ private timeoutIDPush ?: number ;
7
+ private timeoutIDPull ?: number ;
8
8
9
9
constructor ( private readonly plugin : ObsidianGit ) { }
10
10
@@ -147,41 +147,55 @@ export default class AutomaticsManager {
147
147
148
148
// this.plugin is used for both auto commit-and-sync and commit only
149
149
private doAutoCommitAndSync ( ) : void {
150
- this . plugin . promiseQueue . addTask ( ( ) => {
151
- if ( this . plugin . settings . differentIntervalCommitAndPush ) {
152
- return this . plugin . commit ( { fromAuto : true } ) ;
153
- } else {
154
- return this . plugin . commitAndSync ( true ) ;
150
+ this . plugin . promiseQueue . addTask (
151
+ ( ) => {
152
+ if ( this . plugin . settings . differentIntervalCommitAndPush ) {
153
+ return this . plugin . commit ( { fromAuto : true } ) ;
154
+ } else {
155
+ return this . plugin . commitAndSync ( true ) ;
156
+ }
157
+ } ,
158
+ ( ) => {
159
+ this . saveLastAuto ( new Date ( ) , "backup" ) ;
160
+ this . startAutoCommitAndSync ( ) ;
155
161
}
156
- } ) ;
157
- this . saveLastAuto ( new Date ( ) , "backup" ) ;
158
- this . startAutoCommitAndSync ( ) ;
162
+ ) ;
159
163
}
160
164
161
165
private startAutoPull ( minutes ?: number ) {
162
166
let time = ( minutes ?? this . plugin . settings . autoPullInterval ) * 60000 ;
163
167
// max timeout in js
164
168
if ( time > 2147483647 ) time = 2147483647 ;
165
169
166
- this . timeoutIDPull = window . setTimeout ( ( ) => {
167
- this . plugin . promiseQueue . addTask ( ( ) =>
168
- this . plugin . pullChangesFromRemote ( )
169
- ) ;
170
- this . saveLastAuto ( new Date ( ) , "pull" ) ;
171
- this . startAutoPull ( ) ;
172
- } , time ) ;
170
+ this . timeoutIDPull = window . setTimeout ( ( ) => this . doAutoPull ( ) , time ) ;
171
+ }
172
+
173
+ private doAutoPull ( ) : void {
174
+ this . plugin . promiseQueue . addTask (
175
+ ( ) => this . plugin . pullChangesFromRemote ( ) ,
176
+ ( ) => {
177
+ this . saveLastAuto ( new Date ( ) , "pull" ) ;
178
+ this . startAutoPull ( ) ;
179
+ }
180
+ ) ;
173
181
}
174
182
175
183
private startAutoPush ( minutes ?: number ) {
176
184
let time = ( minutes ?? this . plugin . settings . autoPushInterval ) * 60000 ;
177
185
// max timeout in js
178
186
if ( time > 2147483647 ) time = 2147483647 ;
179
187
180
- this . timeoutIDPush = window . setTimeout ( ( ) => {
181
- this . plugin . promiseQueue . addTask ( ( ) => this . plugin . push ( ) ) ;
182
- this . saveLastAuto ( new Date ( ) , "push" ) ;
183
- this . startAutoPush ( ) ;
184
- } , time ) ;
188
+ this . timeoutIDPush = window . setTimeout ( ( ) => this . doAutoPush ( ) , time ) ;
189
+ }
190
+
191
+ private doAutoPush ( ) : void {
192
+ this . plugin . promiseQueue . addTask (
193
+ ( ) => this . plugin . push ( ) ,
194
+ ( ) => {
195
+ this . saveLastAuto ( new Date ( ) , "push" ) ;
196
+ this . startAutoPush ( ) ;
197
+ }
198
+ ) ;
185
199
}
186
200
187
201
private clearAutoCommitAndSync ( ) : boolean {
0 commit comments