Sync tweaks

pull/369/head
Zef Hemel 2023-01-26 15:54:28 +01:00
parent 4c39d0b964
commit 9c04db6a9c
7 changed files with 63 additions and 4 deletions

View File

@ -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,

View File

@ -165,6 +165,12 @@ const template: MenuItemConstructorOptions[] = [
{
label: "Help",
submenu: [
{
label: "Documentation",
click: () => {
shell.openExternal("https://silverbullet.md");
},
},
{
role: "about",
},

View File

@ -7,6 +7,8 @@ export type AppEvent =
| "minieditor:complete"
| "page:load"
| "editor:init"
| "editor:pageLoaded"
| "editor:pageReloaded"
| "editor:modeswitch"
| "plugs:loaded";

View File

@ -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);

View File

@ -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

View File

@ -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() {

View File

@ -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