From 149e409bfacadb235f8ad2d522d41aea8752844f Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 27 Jan 2024 16:59:19 +0000 Subject: [PATCH] Desktop, Mobile: Fixes #9157: Clear "Some items cannot be synchronised" banner after situation is resolved --- .eslintignore | 1 + .gitignore | 1 + .../gui/StatusScreen/StatusScreen.tsx | 8 ++--- packages/app-mobile/root.tsx | 4 ++- packages/lib/Synchronizer.ts | 4 ++- packages/lib/models/BaseItem.ts | 5 ++++ packages/lib/reducer.ts | 2 +- packages/lib/services/ResourceFetcher.ts | 5 ++-- .../checkDisabledSyncItemsNotification.ts | 30 +++++++++++++++++++ 9 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.ts diff --git a/.eslintignore b/.eslintignore index df44b7f2d..5a4f44e81 100644 --- a/.eslintignore +++ b/.eslintignore @@ -973,6 +973,7 @@ packages/lib/services/synchronizer/syncInfoUtils.js packages/lib/services/synchronizer/synchronizer_LockHandler.test.js packages/lib/services/synchronizer/synchronizer_MigrationHandler.test.js packages/lib/services/synchronizer/tools.js +packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.js packages/lib/services/synchronizer/utils/handleConflictAction.js packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js packages/lib/services/synchronizer/utils/resourceRemotePath.js diff --git a/.gitignore b/.gitignore index eeb871ef5..33c391132 100644 --- a/.gitignore +++ b/.gitignore @@ -953,6 +953,7 @@ packages/lib/services/synchronizer/syncInfoUtils.js packages/lib/services/synchronizer/synchronizer_LockHandler.test.js packages/lib/services/synchronizer/synchronizer_MigrationHandler.test.js packages/lib/services/synchronizer/tools.js +packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.js packages/lib/services/synchronizer/utils/handleConflictAction.js packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js packages/lib/services/synchronizer/utils/resourceRemotePath.js diff --git a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx index ca4080ed5..4e9a1d3c4 100644 --- a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx +++ b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx @@ -81,10 +81,10 @@ function StatusScreen(props: Props) { ); } - const renderRetryAll = (section: ReportSection) => { + const renderRetryAll = (key: string, section: ReportSection) => { const items: React.JSX.Element[] = []; if (section.canRetryAll) { - items.push(renderSectionRetryAll(section.title, async () => { + items.push(renderSectionRetryAll(`${key}_${section.title}`, async () => { await section.retryAllHandler(); void resfreshScreen(); })); @@ -97,7 +97,7 @@ function StatusScreen(props: Props) { items.push(renderSectionTitle(section.title, section.title)); - items = items.concat(renderRetryAll(section)); + items = items.concat(renderRetryAll('top', section)); let currentListKey = ''; let listItems: React.JSX.Element[] = []; @@ -158,7 +158,7 @@ function StatusScreen(props: Props) { } } - items = items.concat(renderRetryAll(section)); + items = items.concat(renderRetryAll('bottom', section)); return
{items}
; }; diff --git a/packages/app-mobile/root.tsx b/packages/app-mobile/root.tsx index 53511be49..d931d1ef9 100644 --- a/packages/app-mobile/root.tsx +++ b/packages/app-mobile/root.tsx @@ -543,7 +543,7 @@ async function initialize(dispatch: Function) { if (Setting.value('env') === 'prod') { await db.open({ name: getDatabaseName(currentProfile, isSubProfile) }); } else { - await db.open({ name: getDatabaseName(currentProfile, isSubProfile, '-3') }); + await db.open({ name: getDatabaseName(currentProfile, isSubProfile, '-20240127-1') }); // await db.clearForTesting(); } @@ -755,6 +755,8 @@ async function initialize(dispatch: Function) { await runOnDeviceFsDriverTests(); } + dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' }); + reg.logger().info('Application initialized'); } diff --git a/packages/lib/Synchronizer.ts b/packages/lib/Synchronizer.ts index 73704b6d8..c8701c7a3 100644 --- a/packages/lib/Synchronizer.ts +++ b/packages/lib/Synchronizer.ts @@ -31,6 +31,7 @@ import resourceRemotePath from './services/synchronizer/utils/resourceRemotePath import syncDeleteStep from './services/synchronizer/utils/syncDeleteStep'; import { ErrorCode } from './errors'; import { SyncAction } from './services/synchronizer/utils/types'; +import checkDisabledSyncItemsNotification from './services/synchronizer/utils/checkDisabledSyncItemsNotification'; const { sprintf } = require('sprintf-js'); const { Dirnames } = require('./services/synchronizer/utils/types'); @@ -405,7 +406,6 @@ export default class Synchronizer { const handleCannotSyncItem = async (ItemClass: any, syncTargetId: any, item: any, cannotSyncReason: string, itemLocation: any = null) => { await ItemClass.saveSyncDisabled(syncTargetId, item, cannotSyncReason, itemLocation); - this.dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' }); }; // We index resources before sync mostly to flag any potential orphan @@ -1127,6 +1127,8 @@ export default class Synchronizer { withErrors: Synchronizer.reportHasErrors(this.progressReport_), }); + await checkDisabledSyncItemsNotification((action: any) => this.dispatch(action)); + this.onProgress_ = function() {}; this.progressReport_ = {}; diff --git a/packages/lib/models/BaseItem.ts b/packages/lib/models/BaseItem.ts index 3d7b2937f..05419bb92 100644 --- a/packages/lib/models/BaseItem.ts +++ b/packages/lib/models/BaseItem.ts @@ -791,6 +791,11 @@ export default class BaseItem extends BaseModel { return output; } + public static async syncDisabledItemsCount(syncTargetId: number) { + const r = await this.db().selectOne('SELECT count(*) as total FROM sync_items WHERE sync_disabled = 1 AND sync_target = ?', [syncTargetId]); + return r ? r.total : 0; + } + public static updateSyncTimeQueries(syncTarget: number, item: any, syncTime: number, syncDisabled = false, syncDisabledReason = '', itemLocation: number = null) { const itemType = item.type_; const itemId = item.id; diff --git a/packages/lib/reducer.ts b/packages/lib/reducer.ts index 5a20c1261..4e1fa9b92 100644 --- a/packages/lib/reducer.ts +++ b/packages/lib/reducer.ts @@ -1155,7 +1155,7 @@ const reducer = produce((draft: Draft = defaultState, action: any) => { break; case 'SYNC_HAS_DISABLED_SYNC_ITEMS': - draft.hasDisabledSyncItems = true; + draft.hasDisabledSyncItems = 'value' in action ? action.value : true; break; case 'ENCRYPTION_HAS_DISABLED_ITEMS': diff --git a/packages/lib/services/ResourceFetcher.ts b/packages/lib/services/ResourceFetcher.ts index 5eda5bfc9..d1d546cac 100644 --- a/packages/lib/services/ResourceFetcher.ts +++ b/packages/lib/services/ResourceFetcher.ts @@ -4,6 +4,7 @@ import BaseService from './BaseService'; import ResourceService from './ResourceService'; import Logger from '@joplin/utils/Logger'; import shim from '../shim'; +import notifyDisabledSyncItems from './synchronizer/utils/checkDisabledSyncItemsNotification'; const { Dirnames } = require('./synchronizer/utils/types'); const EventEmitter = require('events'); @@ -243,9 +244,7 @@ export default class ResourceFetcher extends BaseService { this.logger().info(`ResourceFetcher: Auto-added resources: ${count}`); - const errorCount = await Resource.downloadStatusCounts(Resource.FETCH_STATUS_ERROR); - if (errorCount) this.dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' }); - + await notifyDisabledSyncItems((action: any) => this.dispatch(action)); } finally { this.addingResources_ = false; this.autoAddResourcesCalls_.pop(); diff --git a/packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.ts b/packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.ts new file mode 100644 index 000000000..31d3e33df --- /dev/null +++ b/packages/lib/services/synchronizer/utils/checkDisabledSyncItemsNotification.ts @@ -0,0 +1,30 @@ +import { Dispatch } from 'redux'; +import Resource from '../../../models/Resource'; +import BaseItem from '../../../models/BaseItem'; +import Setting from '../../../models/Setting'; +import Logger from '@joplin/utils/Logger'; + +const logger = Logger.create('checkDisabledSyncItemsNotification'); + +export default async (dispatch: Dispatch) => { + const errorCount = await Resource.downloadStatusCounts(Resource.FETCH_STATUS_ERROR); + if (errorCount) { + logger.info(`${errorCount} resource download errors: Triggering notification`); + dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' }); + return; + } + + const disabledCount = await BaseItem.syncDisabledItemsCount(Setting.value('sync.target')); + if (disabledCount) { + logger.info(`${disabledCount} disabled sync items: Triggering notification`); + dispatch({ type: 'SYNC_HAS_DISABLED_SYNC_ITEMS' }); + return; + } + + logger.info('No errors: Hiding notification'); + + dispatch({ + type: 'SYNC_HAS_DISABLED_SYNC_ITEMS', + value: false, + }); +};