Skip to content

Commit b8c69e6

Browse files
committed
enh(schedule all): Add a button that schedules all profiles for sync
fixes #563 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 9ef21a6 commit b8c69e6

File tree

9 files changed

+66
-6
lines changed

9 files changed

+66
-6
lines changed

_locales/en/messages.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
"LabelCancelsync": {
165165
"message": "Cancel sync"
166166
},
167+
"LabelSyncall": {
168+
"message": "Sync all profiles"
169+
},
167170
"LabelAutosync": {
168171
"message": "Auto-sync"
169172
},
@@ -185,6 +188,9 @@
185188
"StatusSyncing": {
186189
"message": "Syncing"
187190
},
191+
"StatusScheduled": {
192+
"message": "Scheduled"
193+
},
188194
"LabelReset": {
189195
"message": "Reset"
190196
},

src/lib/Controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ export default class Controller implements IController {
8787
console.log('Sending message to service worker: ', message)
8888
}
8989

90+
async scheduleAll(): Promise<void> {
91+
console.log('Waiting for service worker readiness')
92+
const worker = await this.getWorker()
93+
const message = {type: 'scheduleAll', params: []}
94+
worker.postMessage(message)
95+
console.log('Sending message to service worker: ', message)
96+
}
97+
9098
async setEnabled(enabled: boolean): Promise<void> {
9199
const worker = await this.getWorker()
92100
const message = {type: 'setEnabled', params: [enabled]}

src/lib/browser/BrowserController.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,18 @@ export default class BrowserController {
281281
}
282282

283283
this.waiting[accountId] = true
284+
await account.setData({ ...account.getData(), scheduled: true })
284285

285286
return this.jobs.add(() => this.syncAccount(accountId))
286287
}
287288

289+
async scheduleAll() {
290+
const accounts = await Account.getAllAccounts()
291+
for (const account of accounts) {
292+
this.scheduleSync(account.id)
293+
}
294+
}
295+
288296
async cancelSync(accountId, keepEnabled) {
289297
let account = await Account.get(accountId)
290298
// Avoid starting it again automatically
@@ -302,6 +310,7 @@ export default class BrowserController {
302310
return
303311
}
304312
let account = await Account.get(accountId)
313+
await account.setData({ ...account.getData(), scheduled: false })
305314
if (account.getData().syncing) {
306315
console.log('Account is already syncing. Not triggering another sync.')
307316
return

src/lib/interfaces/Controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default interface IController {
22
setEnabled(enabled:boolean): void;
33
unlock(key):Promise<void>;
44
scheduleSync(accountId, wait):Promise<void>;
5+
scheduleAll():Promise<void>;
56
cancelSync(accountId, keepEnabled):Promise<void>;
67
syncAccount(accountId, strategy):Promise<void>;
78
onStatusChange(listener):()=>void;

src/lib/native/NativeController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export default class NativeController {
9191
return Promise.resolve(this.unlocked)
9292
}
9393

94+
async scheduleAll() {
95+
const accounts = await Account.getAllAccounts()
96+
for (const account of accounts) {
97+
this.scheduleSync(account.id)
98+
}
99+
}
100+
94101
async scheduleSync(accountId, wait) {
95102
if (wait) {
96103
if (this.schedule[accountId]) {

src/ui/components/AccountCard.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
</v-select>
112112
<v-btn
113113
v-if="!account.data.syncing"
114+
:disabled="account.data.scheduled"
114115
class="primary"
115116
small
116117
:title="t('LabelSyncnow')"
@@ -200,19 +201,22 @@ export default {
200201
disabled: 'rgb(125, 114, 128)',
201202
ok: '#3d8e39',
202203
error: '#8e3939',
203-
syncing: '#2196F3'
204+
syncing: '#2196F3',
205+
scheduled: '#2196F3',
204206
},
205207
statusIcons: {
206208
disabled: 'mdi-sync-off',
207209
ok: 'mdi-check',
208210
error: 'mdi-sync-alert',
209-
syncing: 'mdi-sync'
211+
syncing: 'mdi-sync',
212+
scheduled: 'mdi-timer-sync-outline'
210213
},
211214
statusLabels: {
212215
disabled: this.t('StatusDisabled'),
213216
ok: this.t('StatusAllgood'),
214217
error: this.t('StatusError'),
215-
syncing: this.t('StatusSyncing')
218+
syncing: this.t('StatusSyncing'),
219+
scheduled: this.t('StatusScheduled')
216220
},
217221
strategyIcons: {
218222
slave: 'mdi-arrow-down-bold',
@@ -249,6 +253,9 @@ export default {
249253
if (this.account.data.syncing) {
250254
return 'syncing'
251255
}
256+
if (this.account.data.scheduled) {
257+
return 'scheduled'
258+
}
252259
if (this.account.data.error) {
253260
return 'error'
254261
}

src/ui/store/actions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export const actionsDefinition = {
7777
const controller = await Controller.getSingleton()
7878
controller.syncAccount(accountId)
7979
},
80+
async [actions.TRIGGER_SYNC_ALL]({ commit, dispatch, state }, accountId) {
81+
const controller = await Controller.getSingleton()
82+
controller.scheduleAll()
83+
},
8084
async [actions.TRIGGER_SYNC_DOWN]({ commit, dispatch, state }, accountId) {
8185
const controller = await Controller.getSingleton()
8286
await controller.syncAccount(accountId, 'slave')

src/ui/store/definitions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const actions = {
2121
RESET_ACCOUNT: 'RESET_ACCOUNT',
2222
STORE_ACCOUNT: 'STORE_ACCOUNT',
2323
TRIGGER_SYNC: 'TRIGGER_SYNC',
24+
TRIGGER_SYNC_ALL: 'TRIGGER_SYNC_ALL',
2425
TRIGGER_SYNC_UP: 'TRIGGER_SYNC_UP',
2526
TRIGGER_SYNC_DOWN: 'TRIGGER_SYNC_DOWN',
2627
CANCEL_SYNC: 'CANCEL_SYNC',

src/ui/views/Overview.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<v-container class="d-flex flex-row pa-0">
4141
<v-btn
4242
class="flex-grow-1 me-1"
43+
color="primary"
4344
:to="{ name: routes.NEW_ACCOUNT }"
4445
target="_blank">
4546
<v-icon>
@@ -48,11 +49,18 @@
4849
{{ t('LabelNewAccount') }}
4950
</v-btn>
5051
<v-btn
51-
:title="t('LabelImportExport')"
52-
:to="{ name: routes.IMPORTEXPORT }"
53-
target="_blank">
52+
class="me-1"
53+
:title="t('LabelImportExport')"
54+
:to="{ name: routes.IMPORTEXPORT }"
55+
target="_blank">
5456
<v-icon>mdi-export</v-icon>
5557
</v-btn>
58+
<v-btn
59+
:disabled="!canScheduleAll"
60+
:title="t('LabelSyncall')"
61+
@click="clickSyncAll">
62+
<v-icon>mdi-sync-circle</v-icon>
63+
</v-btn>
5664
</v-container>
5765
</template>
5866
</v-container>
@@ -61,6 +69,7 @@
6169
<script>
6270
import AccountCard from '../components/AccountCard'
6371
import { routes } from '../router'
72+
import { actions } from '../store'
6473
6574
export default {
6675
name: 'Overview',
@@ -74,6 +83,14 @@ export default {
7483
},
7584
loading() {
7685
return this.$store.state.loading.accounts
86+
},
87+
canScheduleAll() {
88+
return !(this.$store.state.accounts && Object.values(this.$store.state.accounts).some(account => account.data.scheduled))
89+
}
90+
},
91+
methods: {
92+
clickSyncAll() {
93+
this.$store.dispatch(actions.TRIGGER_SYNC_ALL)
7794
}
7895
}
7996
}

0 commit comments

Comments
 (0)