mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-11-03 14:58:18 +00:00
Simplify conflict scheduling and lifecycle subscriptions
This commit is contained in:
1 parent
ad91776ad9
commit
84be444689
8 files changed
+206
-75
No files matched your search
@@ -61,22 +61,23 @@ export function useInteractiveConflictResolutionFeature(
|
||||
});
|
||||
services.appLifecycle.getUnresolvedMessages.addHandler(operations.getActiveConflictMessages);
|
||||
services.conflict.resolveByUserInteraction.addHandler(operations.resolveByUserInteraction);
|
||||
const offConflictCancelled = services.context.events.onEvent(EVENT_CONFLICT_CANCELLED, (filename) => {
|
||||
operations.invalidateWaitingResolution(filename);
|
||||
fireAndForget(() => operations.refreshConflictState(filename));
|
||||
});
|
||||
let featureDisposed = false;
|
||||
const eventSubscriptions = new AbortController();
|
||||
const dispose = () => {
|
||||
if (featureDisposed) return;
|
||||
featureDisposed = true;
|
||||
// Stop the refresh listener before cancellation so that unloading does
|
||||
// not start a database read which can race with database disposal.
|
||||
offConflictCancelled();
|
||||
eventSubscriptions.abort();
|
||||
operations.dispose();
|
||||
};
|
||||
const offPluginUnloaded = services.context.events.onceEvent(EVENT_PLUGIN_UNLOADED, dispose);
|
||||
services.context.events.onEvent(
|
||||
EVENT_CONFLICT_CANCELLED,
|
||||
(filename) => {
|
||||
operations.invalidateWaitingResolution(filename);
|
||||
fireAndForget(() => operations.refreshConflictState(filename));
|
||||
},
|
||||
{ signal: eventSubscriptions.signal }
|
||||
);
|
||||
services.context.events.onceEvent(EVENT_PLUGIN_UNLOADED, dispose, { signal: eventSubscriptions.signal });
|
||||
services.appLifecycle.onUnload.addHandler(() => {
|
||||
offPluginUnloaded();
|
||||
dispose();
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user