From 9c04db6a9caede96e37a9222cb6fcc46315cc0f6 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 26 Jan 2023 15:54:28 +0100 Subject: [PATCH] Sync tweaks --- desktop/src/instance.ts | 2 -- desktop/src/menu.ts | 6 ++++++ plug-api/app_event.ts | 2 ++ plugs/core/plugmanager.ts | 4 ++++ plugs/sync/sync.plug.yaml | 12 ++++++++++++ plugs/sync/sync.ts | 32 +++++++++++++++++++++++++++++++- website/CHANGELOG.md | 9 ++++++++- 7 files changed, 63 insertions(+), 4 deletions(-) diff --git a/desktop/src/instance.ts b/desktop/src/instance.ts index 9f0dfbbd..2e9a3b34 100644 --- a/desktop/src/instance.ts +++ b/desktop/src/instance.ts @@ -155,8 +155,6 @@ let quitting = false; const icon = nativeImage.createFromPath(process.resourcesPath + "/logo.png"); export function newWindow(instance: Instance, windowState: WindowState) { - // Create the browser window. - console.log("Empty icon?", icon.isEmpty()); const window = new BrowserWindow({ height: windowState.height, width: windowState.width, diff --git a/desktop/src/menu.ts b/desktop/src/menu.ts index 55e61c04..f60b2b02 100644 --- a/desktop/src/menu.ts +++ b/desktop/src/menu.ts @@ -165,6 +165,12 @@ const template: MenuItemConstructorOptions[] = [ { label: "Help", submenu: [ + { + label: "Documentation", + click: () => { + shell.openExternal("https://silverbullet.md"); + }, + }, { role: "about", }, diff --git a/plug-api/app_event.ts b/plug-api/app_event.ts index 80e3057e..253f8065 100644 --- a/plug-api/app_event.ts +++ b/plug-api/app_event.ts @@ -7,6 +7,8 @@ export type AppEvent = | "minieditor:complete" | "page:load" | "editor:init" + | "editor:pageLoaded" + | "editor:pageReloaded" | "editor:modeswitch" | "plugs:loaded"; diff --git a/plugs/core/plugmanager.ts b/plugs/core/plugmanager.ts index 9428e855..8146233a 100644 --- a/plugs/core/plugmanager.ts +++ b/plugs/core/plugmanager.ts @@ -61,6 +61,10 @@ export async function updatePlugs() { ); } } catch (e: any) { + if (e.message.includes("Could not read file")) { + console.warn("No PLUGS page found, not loading anything"); + return; + } throw new Error(`Error processing PLUGS: ${e.message}`); } console.log("Plug YAML", plugList); diff --git a/plugs/sync/sync.plug.yaml b/plugs/sync/sync.plug.yaml index e16d4800..b22868fb 100644 --- a/plugs/sync/sync.plug.yaml +++ b/plugs/sync/sync.plug.yaml @@ -5,6 +5,11 @@ functions: command: name: "Sync: Configure" + disableCommand: + path: sync.ts:disableCommand + command: + name: "Sync: Disable" + syncCommand: path: sync.ts:syncCommand command: @@ -16,6 +21,11 @@ functions: command: name: "Sync: Wipe Local Space and Sync" + syncOpenedPage: + path: sync.ts:syncOpenedPage + events: + - editor:pageLoaded + check: env: server path: sync.ts:check @@ -23,8 +33,10 @@ functions: performSync: env: server path: sync.ts:performSync + # Sync every minute cron: "* * * * *" + # Automatically sync the current page upon change syncPage: path: sync.ts:syncPage env: server diff --git a/plugs/sync/sync.ts b/plugs/sync/sync.ts index 03e9eea9..2c161bcd 100644 --- a/plugs/sync/sync.ts +++ b/plugs/sync/sync.ts @@ -68,6 +68,20 @@ export async function syncCommand() { } } +export async function disableCommand() { + if ( + !(await editor.confirm( + "Are you sure you want to disable sync?", + )) + ) { + return; + } + + // remove all sync related keys from the store + await store.deletePrefix("sync."); + await editor.flashNotification("Sync disabled."); +} + export async function localWipeAndSyncCommand() { let config: SyncEndpoint | undefined = await store.get("sync.config"); if (!config) { @@ -112,6 +126,22 @@ export async function localWipeAndSyncCommand() { // Starting actual sync await syncCommand(); + + // And finally loading all plugs + await system.invokeFunction("client", "core.updatePlugsCommand"); +} + +export async function syncOpenedPage() { + // Is sync on? + if (!(await store.has("sync.config"))) { + // Nope -> exit + return; + } + await system.invokeFunction( + "server", + "syncPage", + await editor.getCurrentPage(), + ); } // Run on server @@ -119,8 +149,8 @@ export function check(config: SyncEndpoint) { return sync.check(config); } +// If a sync takes longer than this, we'll consider it timed out const syncTimeout = 1000 * 60 * 10; // 10 minutes -// const syncTimeout = 1000 * 20; // 20s // Run on server export async function performSync() { diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 42b9674e..85c807df 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -3,8 +3,15 @@ release. --- -## Next +## 0.2.11 * Regression fix: hashtag completion works again +* Sync improvements: + * Immediately trigger sync on file when opened in the editor (so you always get the latest version) + * Automatically perform a {[Plugs: Update]} after performing a {[Sync: Wipe Local Space and Sync]} + * New {[Sync: Disable]} command to disable sync (remove config and snapshot) +* {[Plugs: Update]} no longer fails when there is no [[PLUGS]] file. +* Desktop: New “Help” menu with link to documentation (silverbullet.md website) and About box with version number. +* You now see a clear error message when querying an non-supported query source. --- ## 0.2.10