Attempt to address #479
parent
cfd713c120
commit
398e452308
|
@ -186,6 +186,7 @@ export type AppEvent =
|
||||||
| "editor:init"
|
| "editor:init"
|
||||||
| "editor:pageLoaded" // args: pageName, previousPage, isSynced
|
| "editor:pageLoaded" // args: pageName, previousPage, isSynced
|
||||||
| "editor:pageReloaded"
|
| "editor:pageReloaded"
|
||||||
|
| "editor:pageSaving"
|
||||||
| "editor:pageSaved"
|
| "editor:pageSaved"
|
||||||
| "editor:modeswitch"
|
| "editor:modeswitch"
|
||||||
| "plugs:loaded"
|
| "plugs:loaded"
|
||||||
|
|
|
@ -667,6 +667,10 @@ export class Client {
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
console.log("Saving page", this.currentPage);
|
console.log("Saving page", this.currentPage);
|
||||||
|
this.dispatchAppEvent(
|
||||||
|
"editor:pageSaving",
|
||||||
|
this.currentPage,
|
||||||
|
);
|
||||||
this.space
|
this.space
|
||||||
.writePage(
|
.writePage(
|
||||||
this.currentPage,
|
this.currentPage,
|
||||||
|
|
|
@ -46,6 +46,8 @@ export interface ISyncService {
|
||||||
export class SyncService implements ISyncService {
|
export class SyncService implements ISyncService {
|
||||||
spaceSync: SpaceSync;
|
spaceSync: SpaceSync;
|
||||||
lastReportedSyncStatus = Date.now();
|
lastReportedSyncStatus = Date.now();
|
||||||
|
// If this is set to anything other than undefined, a file is currently saving
|
||||||
|
savingTimeout: number | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly localSpacePrimitives: SpacePrimitives,
|
readonly localSpacePrimitives: SpacePrimitives,
|
||||||
|
@ -75,7 +77,21 @@ export class SyncService implements ISyncService {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
eventHook.addLocalListener("editor:pageSaving", () => {
|
||||||
|
console.log("Saving...");
|
||||||
|
this.savingTimeout = setTimeout(() => {
|
||||||
|
this.savingTimeout = undefined;
|
||||||
|
}, 1000 * 5);
|
||||||
|
});
|
||||||
|
|
||||||
eventHook.addLocalListener("editor:pageSaved", (name) => {
|
eventHook.addLocalListener("editor:pageSaved", (name) => {
|
||||||
|
console.log("Done saving...");
|
||||||
|
if (this.savingTimeout) {
|
||||||
|
clearTimeout(this.savingTimeout);
|
||||||
|
this.savingTimeout = undefined;
|
||||||
|
} else {
|
||||||
|
console.warn("This should not happen, savingTimeout was not set");
|
||||||
|
}
|
||||||
const path = `${name}.md`;
|
const path = `${name}.md`;
|
||||||
this.scheduleFileSync(path).catch(console.error);
|
this.scheduleFileSync(path).catch(console.error);
|
||||||
});
|
});
|
||||||
|
@ -88,6 +104,12 @@ export class SyncService implements ISyncService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async isSyncing(): Promise<boolean> {
|
async isSyncing(): Promise<boolean> {
|
||||||
|
if (this.savingTimeout !== undefined) {
|
||||||
|
console.log(
|
||||||
|
"Saving a file at the moment, so reporting as isSyncing() = true",
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const startTime = await this.ds.get(syncStartTimeKey);
|
const startTime = await this.ds.get(syncStartTimeKey);
|
||||||
if (!startTime) {
|
if (!startTime) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue