Skip to content

Commit

Permalink
enh(Account#sync): Allow forcing sync when profile is scheduled
Browse files Browse the repository at this point in the history
fixes #1769

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr committed Nov 29, 2024
1 parent f066269 commit 50412fd
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 10 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## [5.4.0] - 2024-11-28

### New
* enh(Tree): Add confirmation before deleting items
* enh(tabs): Make merge strategy work with tabs
* [native] enh(DialogChooseFolder): Allow creating folders
* [native] enh(Drawer): Add github issues link
* [native] enh(search): Show search results from other folders
* [native] enh: Allow selecting up down sync by long press on sync button
* [native] enh: Remember sort option & sort folders first
* [native] enh: Improve search by ranking better matches higher
* [native] fix(DialogChooseFolder): Sort folders according to sort order setting
* [native] fix(newbookmark): Use neutral user agent to get correct title
* fix(Scanner): Improve move stability with same-titled folders
* [native] fix(Tree): Sorting by link
* fix(GoogleDrive|WebDAV): fix _.includes is not a function error

## [5.3.4] - 2024-11-17

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -803,5 +803,11 @@
},
"LabelSearchresultsotherfolders": {
"message": "Results from other folders"
},
"LabelScheduledforcesync": {
"message": "Force sync"
},
"DescriptionScheduledforcesync": {
"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."
}
}
6 changes: 3 additions & 3 deletions src/lib/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class Account {
throw new Error('Not implemented')
}

async sync(strategy?:TAccountStrategy):Promise<void> {
async sync(strategy?:TAccountStrategy, forceSync = false):Promise<void> {
let mappings: Mappings
try {
if (this.getData().syncing || this.syncing) return
Expand All @@ -173,13 +173,13 @@ export default class Account {
const needLock = (strategy || this.getData().strategy) !== 'slave'
let status
try {
status = await this.server.onSyncStart(needLock)
status = await this.server.onSyncStart(needLock, forceSync)
} catch (e) {
await this.server.onSyncFail()
// Resource locked
if (e.code === 37) {
// We got a resource locked error
if (this.getData().lastSync < Date.now() - this.lockTimeout) {
if (this.getData().lastSync < Date.now() - this.lockTimeout || forceSync) {
// but if we've been waiting for the lock for more than 2h
// start again without locking the resource
status = await this.server.onSyncStart(false, true)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export default class Controller implements IController {
console.log('Sending message to service worker: ', message)
}

async syncAccount(accountId, strategy): Promise<void> {
async syncAccount(accountId, strategy, forceSync = false): Promise<void> {
console.log('Waiting for service worker readiness')
const worker = await this.getWorker()
const message = {type: 'syncAccount', params: [accountId, strategy]}
const message = {type: 'syncAccount', params: [accountId, strategy, forceSync]}
worker.postMessage(message)
console.log('Sending message to service worker: ', message)
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/browser/BrowserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export default class BrowserController {
await account.cancelSync()
}

async syncAccount(accountId, strategy) {
async syncAccount(accountId, strategy, forceSync = false) {
if (!this.enabled) {
return
}
Expand All @@ -342,7 +342,7 @@ export default class BrowserController {
const interval = setInterval(() => browser.tabs.getCurrent(), 2e4)
setTimeout(() => this.updateStatus(), 500)
try {
await account.sync(strategy)
await account.sync(strategy, forceSync)
} catch (error) {
console.error(error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/interfaces/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default interface IController {
scheduleSync(accountId, wait):Promise<void>;
scheduleAll():Promise<void>;
cancelSync(accountId, keepEnabled):Promise<void>;
syncAccount(accountId, strategy):Promise<void>;
syncAccount(accountId, strategy, forceSync):Promise<void>;
onStatusChange(listener):()=>void;
getUnlocked():Promise<boolean>;
onLoad():void;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/native/NativeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class NativeController {
await account.cancelSync()
}

async syncAccount(accountId, strategy) {
async syncAccount(accountId, strategy, forceSync = false) {
if (!this.enabled) {
return
}
Expand All @@ -150,7 +150,7 @@ export default class NativeController {
}
setTimeout(() => this.updateStatus(), 500)
try {
await account.sync(strategy)
await account.sync(strategy, forceSync)
} catch (error) {
console.error(error)
}
Expand Down
14 changes: 14 additions & 0 deletions src/ui/components/AccountCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
{{ t('LabelDebuglogs') }}
</v-btn>
</template>
<template v-if="status === 'scheduled'">
<v-btn
:color="statusType"
class="float-right"
x-small
@click="onForceSync">
{{ t('LabelScheduledforcesync') }}
</v-btn>
</template>
</v-alert>
<v-alert
v-if="legacyWarning"
Expand Down Expand Up @@ -317,6 +326,11 @@ export default {
},
onGetLogs() {
this.$store.dispatch(actions.DOWNLOAD_LOGS)
},
onForceSync() {
if (confirm(this.t('DescriptionScheduledforcesync'))) {
this.$store.dispatch(actions.FORCE_SYNC, this.account.id)
}
}
}
}
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 @@ -80,6 +80,10 @@ export const actionsDefinition = {
const controller = await Controller.getSingleton()
controller.syncAccount(accountId)
},
async [actions.FORCE_SYNC]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
controller.syncAccount(accountId, null, true)
},
async [actions.TRIGGER_SYNC_ALL]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
controller.scheduleAll()
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 @@ -22,6 +22,7 @@ export const actions = {
RESET_ACCOUNT: 'RESET_ACCOUNT',
STORE_ACCOUNT: 'STORE_ACCOUNT',
TRIGGER_SYNC: 'TRIGGER_SYNC',
FORCE_SYNC: 'FORCE_SYNC',
TRIGGER_SYNC_ALL: 'TRIGGER_SYNC_ALL',
TRIGGER_SYNC_UP: 'TRIGGER_SYNC_UP',
TRIGGER_SYNC_DOWN: 'TRIGGER_SYNC_DOWN',
Expand Down
4 changes: 4 additions & 0 deletions src/ui/store/native/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export const actionsDefinition = {
const controller = await Controller.getSingleton()
controller.syncAccount(accountId)
},
async [actions.FORCE_SYNC]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
controller.syncAccount(accountId, null, true)
},
async [actions.TRIGGER_SYNC_DOWN]({ commit, dispatch, state }, accountId) {
const controller = await Controller.getSingleton()
await controller.syncAccount(accountId, 'slave')
Expand Down

0 comments on commit 50412fd

Please sign in to comment.