Skip to content

Commit

Permalink
enh(schedule all): Add a button that schedules all profiles for sync
Browse files Browse the repository at this point in the history
fixes #563

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Dec 8, 2023
1 parent 9ef21a6 commit b8c69e6
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 6 deletions.
6 changes: 6 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
"LabelCancelsync": {
"message": "Cancel sync"
},
"LabelSyncall": {
"message": "Sync all profiles"
},
"LabelAutosync": {
"message": "Auto-sync"
},
Expand All @@ -185,6 +188,9 @@
"StatusSyncing": {
"message": "Syncing"
},
"StatusScheduled": {
"message": "Scheduled"
},
"LabelReset": {
"message": "Reset"
},
Expand Down
8 changes: 8 additions & 0 deletions src/lib/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export default class Controller implements IController {
console.log('Sending message to service worker: ', message)
}

async scheduleAll(): Promise<void> {
console.log('Waiting for service worker readiness')
const worker = await this.getWorker()
const message = {type: 'scheduleAll', params: []}
worker.postMessage(message)
console.log('Sending message to service worker: ', message)
}

async setEnabled(enabled: boolean): Promise<void> {
const worker = await this.getWorker()
const message = {type: 'setEnabled', params: [enabled]}
Expand Down
9 changes: 9 additions & 0 deletions src/lib/browser/BrowserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,18 @@ export default class BrowserController {
}

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

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

async scheduleAll() {
const accounts = await Account.getAllAccounts()
for (const account of accounts) {
this.scheduleSync(account.id)
}
}

async cancelSync(accountId, keepEnabled) {
let account = await Account.get(accountId)
// Avoid starting it again automatically
Expand All @@ -302,6 +310,7 @@ export default class BrowserController {
return
}
let account = await Account.get(accountId)
await account.setData({ ...account.getData(), scheduled: false })
if (account.getData().syncing) {
console.log('Account is already syncing. Not triggering another sync.')
return
Expand Down
1 change: 1 addition & 0 deletions src/lib/interfaces/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default interface IController {
setEnabled(enabled:boolean): void;
unlock(key):Promise<void>;
scheduleSync(accountId, wait):Promise<void>;
scheduleAll():Promise<void>;
cancelSync(accountId, keepEnabled):Promise<void>;
syncAccount(accountId, strategy):Promise<void>;
onStatusChange(listener):()=>void;
Expand Down
7 changes: 7 additions & 0 deletions src/lib/native/NativeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export default class NativeController {
return Promise.resolve(this.unlocked)
}

async scheduleAll() {
const accounts = await Account.getAllAccounts()
for (const account of accounts) {
this.scheduleSync(account.id)
}
}

async scheduleSync(accountId, wait) {
if (wait) {
if (this.schedule[accountId]) {
Expand Down
13 changes: 10 additions & 3 deletions src/ui/components/AccountCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
</v-select>
<v-btn
v-if="!account.data.syncing"
:disabled="account.data.scheduled"
class="primary"
small
:title="t('LabelSyncnow')"
Expand Down Expand Up @@ -200,19 +201,22 @@ export default {
disabled: 'rgb(125, 114, 128)',
ok: '#3d8e39',
error: '#8e3939',
syncing: '#2196F3'
syncing: '#2196F3',
scheduled: '#2196F3',
},
statusIcons: {
disabled: 'mdi-sync-off',
ok: 'mdi-check',
error: 'mdi-sync-alert',
syncing: 'mdi-sync'
syncing: 'mdi-sync',
scheduled: 'mdi-timer-sync-outline'
},
statusLabels: {
disabled: this.t('StatusDisabled'),
ok: this.t('StatusAllgood'),
error: this.t('StatusError'),
syncing: this.t('StatusSyncing')
syncing: this.t('StatusSyncing'),
scheduled: this.t('StatusScheduled')
},
strategyIcons: {
slave: 'mdi-arrow-down-bold',
Expand Down Expand Up @@ -249,6 +253,9 @@ export default {
if (this.account.data.syncing) {
return 'syncing'
}
if (this.account.data.scheduled) {
return 'scheduled'
}
if (this.account.data.error) {
return 'error'
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const actionsDefinition = {
const controller = await Controller.getSingleton()
controller.syncAccount(accountId)
},
async [actions.TRIGGER_SYNC_ALL]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
controller.scheduleAll()
},
async [actions.TRIGGER_SYNC_DOWN]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
await controller.syncAccount(accountId, 'slave')
Expand Down
1 change: 1 addition & 0 deletions src/ui/store/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const actions = {
RESET_ACCOUNT: 'RESET_ACCOUNT',
STORE_ACCOUNT: 'STORE_ACCOUNT',
TRIGGER_SYNC: 'TRIGGER_SYNC',
TRIGGER_SYNC_ALL: 'TRIGGER_SYNC_ALL',
TRIGGER_SYNC_UP: 'TRIGGER_SYNC_UP',
TRIGGER_SYNC_DOWN: 'TRIGGER_SYNC_DOWN',
CANCEL_SYNC: 'CANCEL_SYNC',
Expand Down
23 changes: 20 additions & 3 deletions src/ui/views/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<v-container class="d-flex flex-row pa-0">
<v-btn
class="flex-grow-1 me-1"
color="primary"
:to="{ name: routes.NEW_ACCOUNT }"
target="_blank">
<v-icon>
Expand All @@ -48,11 +49,18 @@
{{ t('LabelNewAccount') }}
</v-btn>
<v-btn
:title="t('LabelImportExport')"
:to="{ name: routes.IMPORTEXPORT }"
target="_blank">
class="me-1"
:title="t('LabelImportExport')"
:to="{ name: routes.IMPORTEXPORT }"
target="_blank">
<v-icon>mdi-export</v-icon>
</v-btn>
<v-btn
:disabled="!canScheduleAll"
:title="t('LabelSyncall')"
@click="clickSyncAll">
<v-icon>mdi-sync-circle</v-icon>
</v-btn>
</v-container>
</template>
</v-container>
Expand All @@ -61,6 +69,7 @@
<script>
import AccountCard from '../components/AccountCard'
import { routes } from '../router'
import { actions } from '../store'
export default {
name: 'Overview',
Expand All @@ -74,6 +83,14 @@ export default {
},
loading() {
return this.$store.state.loading.accounts
},
canScheduleAll() {
return !(this.$store.state.accounts && Object.values(this.$store.state.accounts).some(account => account.data.scheduled))
}
},
methods: {
clickSyncAll() {
this.$store.dispatch(actions.TRIGGER_SYNC_ALL)
}
}
}
Expand Down

0 comments on commit b8c69e6

Please sign in to comment.