Skip to content

Commit dfc8d5a

Browse files
authored
Merge pull request #2065 from floccusaddon/enh/split-sync-interval-and-auto-sync
Split interval based sync and change-based sync into two options
2 parents aa38269 + e26cef2 commit dfc8d5a

File tree

14 files changed

+105
-32
lines changed

14 files changed

+105
-32
lines changed

_locales/en/messages.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"message": "Sync all profiles"
205205
},
206206
"LabelAutosync": {
207-
"message": "Auto-sync"
207+
"message": "Change-based synchronization"
208208
},
209209
"StatusLastsynced": {
210210
"message": "Last synchronized: {0} ago"
@@ -853,7 +853,7 @@
853853
"message": "Do you really want to force sync? Syncing with two devices at the same time can have unforeseen consequences including corruption of your data. Make sure that no other device is syncing at the moment before confirming."
854854
},
855855
"DescriptionAutosync": {
856-
"message": "Turning on automatic sync will make sure a sync run is triggered regularly within a certain configurable interval as well as on demand a few seconds after you make changes. If you don't turn on automatic sync you will need to trigger sync runs manually by pressing the sync button."
856+
"message": "Turning on change-based synchronization will make sure a sync is run every time you make changes locally."
857857
},
858858
"LabelOpeninnewtab": {
859859
"message": "Open this view in a new tab"
@@ -899,5 +899,11 @@
899899
},
900900
"NotificationSyncingfailed": {
901901
"message": "Failed to sync profile {0}"
902+
},
903+
"LabelSyncintervalenabled": {
904+
"message": "Time-based synchronization"
905+
},
906+
"DescriptionSyncintervalenabled": {
907+
"message": "Turning on time-based synchronization will automatically schedule a sync run of this profile every few minutes"
902908
}
903909
}

src/lib/Account.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default class Account {
6464

6565
static async import(accounts:IAccountData[]):Promise<void> {
6666
for (const accountData of accounts) {
67-
await this.create({...accountData, enabled: false})
67+
await this.create({...accountData, enabled: false, syncIntervalEnabled: false})
6868
}
6969
}
7070

@@ -104,6 +104,7 @@ export default class Account {
104104

105105
getData():IAccountData {
106106
const data = {
107+
enabled: false,
107108
localRoot: null,
108109
strategy: 'default' as TAccountStrategy,
109110
syncInterval: 15,
@@ -115,6 +116,9 @@ export default class Account {
115116
clickCountEnabled: false,
116117
...this.server.getData()
117118
}
119+
if (!('syncIntervalEnabled' in data) && 'enabled' in data) {
120+
data.syncIntervalEnabled = data.enabled
121+
}
118122
if ('type' in data && data.type === 'nextcloud-folders') {
119123
data.type = 'nextcloud-bookmarks'
120124
}

src/lib/browser/BrowserController.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AlarmManager {
4444
continue
4545
}
4646
if (
47+
data.syncIntervalEnabled &&
4748
Date.now() >
4849
interval * 1000 * 60 + lastSync
4950
) {
@@ -386,10 +387,6 @@ export default class BrowserController {
386387
if (account.getData().syncing) {
387388
return
388389
}
389-
// if the account is already scheduled, don't prevent it, to avoid getting stuck
390-
if (!account.getData().enabled && !account.getData().scheduled) {
391-
return
392-
}
393390

394391
const status = await this.getStatus()
395392
if (status === STATUS_SYNCING) {
@@ -476,7 +473,7 @@ export default class BrowserController {
476473
}, STATUS_ALLGOOD)
477474

478475
if (overallStatus === STATUS_ALLGOOD) {
479-
if (accounts.every(account => !account.getData().enabled)) {
476+
if (accounts.every(account => !account.getData().enabled && !account.getData().syncIntervalEnabled)) {
480477
// if status is allgood but no account is enabled, show disabled
481478
overallStatus = STATUS_DISABLED
482479
}

src/lib/interfaces/AccountStorage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { ISerializedSyncProcess } from '../strategies/Default'
55
export type TAccountStrategy = 'default' | 'overwrite' | 'slave'
66

77
export interface IAccountData {
8+
enabled?: boolean
89
localRoot?: string
910
strategy?: TAccountStrategy
11+
syncIntervalEnabled?: boolean
1012
syncInterval?: number
1113
nestedSync?: boolean
1214
failsafe?: boolean

src/lib/native/NativeController.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AlarmManager {
5454
continue
5555
}
5656
if (
57+
data.syncIntervalEnabled &&
5758
Date.now() >
5859
interval * 1000 * 60 + data.lastSync
5960
) {
@@ -163,10 +164,6 @@ export default class NativeController {
163164
if (account.getData().syncing) {
164165
return
165166
}
166-
// if the account is already scheduled, don't prevent it, to avoid getting stuck
167-
if (!account.getData().enabled && !account.getData().scheduled) {
168-
return
169-
}
170167

171168
const status = await this.getStatus()
172169
if (status === STATUS_SYNCING) {
@@ -266,7 +263,7 @@ export default class NativeController {
266263
}, STATUS_ALLGOOD)
267264

268265
if (overallStatus === STATUS_ALLGOOD) {
269-
if (accounts.every(account => !account.getData().enabled)) {
266+
if (accounts.every(account => !account.getData().enabled && !account.getData().syncIntervalEnabled)) {
270267
overallStatus = STATUS_DISABLED
271268
}
272269
}

src/ui/components/AccountCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export default {
243243
if (this.account.data.error) {
244244
return 'error'
245245
}
246-
if (!this.account.data.enabled) {
246+
if (!this.account.data.enabled && !this.account.data.syncIntervalEnabled) {
247247
return 'disabled'
248248
}
249249
return 'ok'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<div>
3+
<div class="text-h6">
4+
{{ t('LabelSyncintervalenabled') }}
5+
</div>
6+
<div class="caption">
7+
{{ t('DescriptionSyncintervalenabled') }}
8+
</div>
9+
<v-switch
10+
:input-value="value"
11+
:aria-label="t('LabelSyncintervalenabled')"
12+
:label="t('LabelSyncintervalenabled')"
13+
dense
14+
class="mt-0 pt-0"
15+
@change="$emit('input', $event)" />
16+
</div>
17+
</template>
18+
19+
<script>
20+
export default {
21+
name: 'OptionSyncIntervalEnabled',
22+
props: {
23+
value: {
24+
type: Boolean,
25+
default: true,
26+
}
27+
},
28+
}
29+
</script>
30+
31+
<style scoped>
32+
33+
</style>

src/ui/components/OptionsGit.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@
9696
<OptionAutoSync
9797
:value="enabled"
9898
@input="$emit('update:enabled', $event)" />
99+
<OptionSyncIntervalEnabled
100+
:value="syncIntervalEnabled"
101+
@input="$emit('update:syncIntervalEnabled', $event)" />
99102
<OptionSyncInterval
103+
v-if="syncIntervalEnabled"
100104
:value="syncInterval"
101105
@input="$emit('update:syncInterval', $event)" />
102106
<OptionSyncStrategy
@@ -151,11 +155,12 @@ import OptionAllowNetwork from './native/OptionAllowNetwork'
151155
import OptionFileType from './OptionFileType'
152156
import OptionExportBookmarks from './OptionExportBookmarks.vue'
153157
import OptionAutoSync from './OptionAutoSync.vue'
158+
import OptionSyncIntervalEnabled from './OptionSyncIntervalEnabled.vue'
154159
155160
export default {
156161
name: 'OptionsGit',
157-
components: { OptionAutoSync, OptionExportBookmarks, OptionAllowNetwork, OptionDownloadLogs, OptionAllowRedirects, OptionClientCert, OptionFailsafe, OptionSyncFolder, OptionDeleteAccount, OptionSyncStrategy, OptionResetCache, OptionSyncInterval, OptionNestedSync, OptionFileType },
158-
props: ['url', 'username', 'password', 'branch', 'includeCredentials', 'serverRoot', 'localRoot', 'allowNetwork', 'syncInterval', 'strategy', 'bookmark_file', 'nestedSync', 'failsafe', 'allowRedirects', 'bookmark_file_type', 'enabled', 'label'],
162+
components: { OptionSyncIntervalEnabled, OptionAutoSync, OptionExportBookmarks, OptionAllowNetwork, OptionDownloadLogs, OptionAllowRedirects, OptionClientCert, OptionFailsafe, OptionSyncFolder, OptionDeleteAccount, OptionSyncStrategy, OptionResetCache, OptionSyncInterval, OptionNestedSync, OptionFileType },
163+
props: ['url', 'username', 'password', 'branch', 'includeCredentials', 'serverRoot', 'localRoot', 'allowNetwork', 'syncInterval', 'strategy', 'bookmark_file', 'nestedSync', 'failsafe', 'allowRedirects', 'bookmark_file_type', 'enabled', 'label', 'syncIntervalEnabled'],
159164
data() {
160165
return {
161166
panels: [0, 1],

src/ui/components/OptionsGoogleDrive.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@
9494
<OptionAutoSync
9595
:value="enabled"
9696
@input="$emit('update:enabled', $event)" />
97+
<OptionSyncIntervalEnabled
98+
:value="syncIntervalEnabled"
99+
@input="$emit('update:syncIntervalEnabled', $event)" />
97100
<OptionSyncInterval
101+
v-if="syncIntervalEnabled"
98102
:value="syncInterval"
99103
@input="$emit('update:syncInterval', $event)" />
100104
<OptionSyncStrategy
@@ -139,11 +143,12 @@ import OptionAllowNetwork from './native/OptionAllowNetwork'
139143
import OptionPassphrase from './OptionPassphrase'
140144
import OptionExportBookmarks from './OptionExportBookmarks.vue'
141145
import OptionAutoSync from './OptionAutoSync.vue'
146+
import OptionSyncIntervalEnabled from './OptionSyncIntervalEnabled.vue'
142147
143148
export default {
144149
name: 'OptionsGoogleDrive',
145-
components: { OptionAutoSync, OptionExportBookmarks, OptionPassphrase, OptionAllowNetwork, OptionDownloadLogs, OptionFailsafe, OptionSyncFolder, OptionDeleteAccount, OptionSyncStrategy, OptionResetCache, OptionSyncInterval, OptionNestedSync },
146-
props: ['username', 'password', 'refreshToken', 'localRoot', 'allowNetwork', 'syncInterval', 'strategy', 'bookmark_file', 'nestedSync', 'failsafe', 'enabled', 'label'],
150+
components: { OptionSyncIntervalEnabled, OptionAutoSync, OptionExportBookmarks, OptionPassphrase, OptionAllowNetwork, OptionDownloadLogs, OptionFailsafe, OptionSyncFolder, OptionDeleteAccount, OptionSyncStrategy, OptionResetCache, OptionSyncInterval, OptionNestedSync },
151+
props: ['username', 'password', 'refreshToken', 'localRoot', 'allowNetwork', 'syncInterval', 'strategy', 'bookmark_file', 'nestedSync', 'failsafe', 'enabled', 'label', 'syncIntervalEnabled'],
147152
data() {
148153
return {
149154
panels: [0, 1],

src/ui/components/OptionsKarakeep.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@
8686
<OptionAutoSync
8787
:value="enabled"
8888
@input="$emit('update:enabled', $event)" />
89+
<OptionSyncIntervalEnabled
90+
:value="syncIntervalEnabled"
91+
@input="$emit('update:syncIntervalEnabled', $event)" />
8992
<OptionSyncInterval
93+
v-if="syncIntervalEnabled"
9094
:value="syncInterval"
9195
@input="$emit('update:syncInterval', $event)" />
9296
<OptionSyncStrategy
@@ -140,10 +144,12 @@ import OptionDownloadLogs from './OptionDownloadLogs'
140144
import OptionAllowNetwork from './native/OptionAllowNetwork'
141145
import OptionExportBookmarks from './OptionExportBookmarks.vue'
142146
import OptionAutoSync from './OptionAutoSync.vue'
147+
import OptionSyncIntervalEnabled from './OptionSyncIntervalEnabled.vue'
143148
144149
export default {
145150
name: 'OptionsKarakeep',
146151
components: {
152+
OptionSyncIntervalEnabled,
147153
OptionAutoSync,
148154
OptionExportBookmarks,
149155
OptionAllowNetwork,
@@ -174,6 +180,7 @@ export default {
174180
'allowRedirects',
175181
'enabled',
176182
'label',
183+
'syncIntervalEnabled',
177184
],
178185
data() {
179186
return {

0 commit comments

Comments
 (0)