diff --git a/client/client.ts b/client/client.ts index 472ae5df..701ae76a 100644 --- a/client/client.ts +++ b/client/client.ts @@ -14,8 +14,11 @@ import type { CompleteEvent, EnrichedClickEvent, FilterOption, + NotificationType, SlashCompletions, } from "@silverbulletmd/silverbullet/type/client"; +import { notificationDismissTimeouts } from "@silverbulletmd/silverbullet/type/client"; +import { publicVersion } from "../public_version.ts"; import { EventHook } from "./plugos/hooks/event.ts"; import type { Command } from "./types/command.ts"; import { @@ -135,6 +138,7 @@ export class Client { }, 1000); // Track if plugs have been updated since sync cycle fullSyncCompleted = false; + private versionMismatchNotified = false; // Set to true once the system is ready (plugs loaded) public systemReady: boolean = false; @@ -508,7 +512,7 @@ export class Client { }); } - flashNotification(message: string, type: "info" | "error" = "info") { + flashNotification(message: string, type: NotificationType = "info") { const id = Math.floor(Math.random() * 1000000); this.ui.viewDispatch({ type: "show-notification", @@ -526,7 +530,7 @@ export class Client { id: id, }); }, - type === "info" ? 4000 : 5000, + notificationDismissTimeouts[type], ); } @@ -1360,6 +1364,19 @@ export class Client { } break; } + case "server-version": { + if ( + message.serverVersion !== publicVersion && + !this.versionMismatchNotified + ) { + this.versionMismatchNotified = true; + this.flashNotification( + "A new version of SilverBullet is available. Reload to update.", + "warning", + ); + } + break; + } } // Also dispatch it on the event hook for any other listeners diff --git a/client/plugos/syscalls/editor.ts b/client/plugos/syscalls/editor.ts index d5f7520d..706e2b19 100644 --- a/client/plugos/syscalls/editor.ts +++ b/client/plugos/syscalls/editor.ts @@ -22,6 +22,7 @@ import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim"; import type { SysCallMapping } from "../system.ts"; import type { FilterOption, + NotificationType, UploadFile, } from "@silverbulletmd/silverbullet/type/client"; import { openSearchPanel } from "@codemirror/search"; @@ -287,7 +288,7 @@ export function editorSyscalls(client: Client): SysCallMapping { "editor.flashNotification": ( _ctx, message: string, - type: "error" | "info" = "info", + type: NotificationType = "info", ) => { client.flashNotification(message, type); }, diff --git a/client/service_worker/proxy_router.ts b/client/service_worker/proxy_router.ts index b53f573a..14569151 100644 --- a/client/service_worker/proxy_router.ts +++ b/client/service_worker/proxy_router.ts @@ -80,9 +80,19 @@ export class ProxyRouter extends EventEmitter { async checkOnline() { if (this.syncEngine) { try { - await this.syncEngine.remote.ping(); + const serverVersion = await this.syncEngine.remote.ping(); // If the ping is successful, we are online this.online = true; + + if (serverVersion) { + const clients = await (self as any).clients.matchAll(); + for (const client of clients) { + client.postMessage({ + type: "server-version", + serverVersion, + }); + } + } } catch { // Otherwise we're not this.online = false; diff --git a/client/spaces/http_space_primitives.ts b/client/spaces/http_space_primitives.ts index 863dc387..32231c95 100644 --- a/client/spaces/http_space_primitives.ts +++ b/client/spaces/http_space_primitives.ts @@ -229,7 +229,7 @@ export class HttpSpacePrimitives implements SpacePrimitives { } // If not: throws an error or invokes a redirect - async ping() { + async ping(): Promise { const parentEndpoint = `${this.url.split("/").slice(0, -1).join("/")}/.ping`; const resp = await this.authenticatedFetch( parentEndpoint, @@ -248,7 +248,11 @@ export class HttpSpacePrimitives implements SpacePrimitives { await this.validateSpacePathFromHeaders(resp); + const serverVersion = resp.headers.get("X-Server-Version") ?? undefined; + // Consume the response body to avoid leaks await resp.text(); + + return serverVersion; } } diff --git a/client/styles/colors.scss b/client/styles/colors.scss index c2f32815..819a6897 100644 --- a/client/styles/colors.scss +++ b/client/styles/colors.scss @@ -67,6 +67,10 @@ background-color: var(--notification-error-background-color); } +.sb-notification-warning { + background-color: var(--notification-warning-background-color); +} + .sb-actions button { width: 28px; height: 28px; diff --git a/client/styles/theme.scss b/client/styles/theme.scss index 86320083..d285e130 100644 --- a/client/styles/theme.scss +++ b/client/styles/theme.scss @@ -48,6 +48,7 @@ html { --notifications-border-color: rgb(41, 41, 41); --notification-info-background-color: rgb(187, 221, 247); --notification-error-background-color: rgb(255, 84, 84); + --notification-warning-background-color: rgb(255, 213, 79); --button-background-color: #eee; --button-hover-background-color: inherit; @@ -210,6 +211,7 @@ html[data-theme="dark"] { --notifications-border-color: rgb(197, 197, 197); --notification-info-background-color: #1b76bb; --notification-error-background-color: #a32121; + --notification-warning-background-color: #b8860b; --button-background-color: #555; --button-hover-background-color: #777; diff --git a/client/types/ui.ts b/client/types/ui.ts index 14a4d092..ff1e5670 100644 --- a/client/types/ui.ts +++ b/client/types/ui.ts @@ -249,4 +249,8 @@ export type ServiceWorkerSourceMessage = | { type: "encryption-key"; key: string; + } + | { + type: "server-version"; + serverVersion: string; }; diff --git a/plug-api/syscalls/editor.ts b/plug-api/syscalls/editor.ts index 20fd7a08..a4709cc9 100644 --- a/plug-api/syscalls/editor.ts +++ b/plug-api/syscalls/editor.ts @@ -1,5 +1,9 @@ import { syscall } from "../syscall.ts"; -import type { FilterOption, UploadFile } from "../../plug-api/types/client.ts"; +import type { + FilterOption, + NotificationType, + UploadFile, +} from "../../plug-api/types/client.ts"; import type { Path, Ref } from "../lib/ref.ts"; import type { PageMeta } from "../../plug-api/types/index.ts"; @@ -220,7 +224,7 @@ export function uploadFile( */ export function flashNotification( message: string, - type: "info" | "error" = "info", + type: NotificationType = "info", ): Promise { return syscall("editor.flashNotification", message, type); } diff --git a/plug-api/types/client.ts b/plug-api/types/client.ts index 9cfa083d..0d59d5cf 100644 --- a/plug-api/types/client.ts +++ b/plug-api/types/client.ts @@ -11,10 +11,18 @@ export type FilterOption = { prefix?: string; } & Record; +export type NotificationType = "info" | "error" | "warning"; + +export const notificationDismissTimeouts: Record = { + info: 4000, + error: 5000, + warning: 8000, +}; + export type Notification = { id: number; message: string; - type: "info" | "error"; + type: NotificationType; date: Date; }; diff --git a/server/cmd/server.go b/server/cmd/server.go index f665688b..24269a51 100644 --- a/server/cmd/server.go +++ b/server/cmd/server.go @@ -240,13 +240,18 @@ func ServerCommand(bundledFiles fs.FS, versionFileText string, buildTime string) var port int var c = &cobra.Command{ Use: "silverbullet", - Short: "Run the Silverbullet server", + Short: "Run the SilverBullet server", Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { if version, err := server.ParseVersionFromTypeScript(versionFileText); err == nil { log.Printf("Starting SilverBullet version %s", version) } serverConfig := buildConfig(bundledFiles, args, buildTime) + version, err := server.ParseVersionFromTypeScript(versionFileText) + if err != nil { + log.Fatal("Could not parse version from version file, this should never happen.") + } + serverConfig.Version = version if port != 3000 { serverConfig.Port = port } diff --git a/server/server.go b/server/server.go index 49fbe00c..81ce5798 100644 --- a/server/server.go +++ b/server/server.go @@ -58,6 +58,7 @@ func Router(config *ServerConfig) chi.Router { spaceConfig := spaceConfigFromContext(r.Context()) w.Header().Set("Cache-Control", "no-cache") w.Header().Set("X-Space-Path", spaceConfig.SpaceFolderPath) + w.Header().Set("X-Server-Version", config.Version) w.WriteHeader(http.StatusOK) w.Write([]byte("OK")) }) diff --git a/server/types.go b/server/types.go index 82c3f3c3..ce22bea8 100644 --- a/server/types.go +++ b/server/types.go @@ -18,6 +18,8 @@ type ServerConfig struct { HostURLPrefix string ClientBundle SpacePrimitives + + Version string } type UserPasswordAuthorizer func(username, password string) bool diff --git a/website/Development.md b/website/Development.md index 04fab12c..38f27149 100644 --- a/website/Development.md +++ b/website/Development.md @@ -26,8 +26,8 @@ The SilverBullet server is written in [Go](https://go.dev/). * `website/`: silverbullet.md website content # Development -Requirements: -* [Deno](https://deno.land/) 2.4 or newer. +Requirements: +* [Node.js](https://nodejs.org/) 24.13 or newer (see `.nvmrc`) * [Go](https://go.dev/) 1.25 or newer * Make @@ -78,7 +78,7 @@ make test ``` ### Build a docker container -Note, you do not need Deno nor Go locally installed for this to work: +Note, you do not need Node.js nor Go locally installed for this to work: ```shell docker build -t silverbullet . diff --git a/website/Install/Configuration.md b/website/Install/Configuration.md index 56f81955..c42c00d6 100644 --- a/website/Install/Configuration.md +++ b/website/Install/Configuration.md @@ -10,7 +10,7 @@ SilverBullet is primarily configured via environment variables. This page gives * `SB_LOG_PUSH`: Set to any value to ask clients to push their logs to the server (for debugging purposes) # Network -* `SB_HOSTNAME`: Set to the hostname to bind to (defaults to `127.0.0.0`, set to `0.0.0.0` to accept outside connections for the local deno setup, defaults to `0.0.0.0` for docker) +* `SB_HOSTNAME`: Set to the hostname to bind to (defaults to `127.0.0.0`, set to `0.0.0.0` to accept outside connections for the local setup, defaults to `0.0.0.0` for docker) * `SB_PORT`: Sets the port to listen to, e.g. `SB_PORT=1234`, default is `3000` * `SB_URL_PREFIX`: Host SilverBullet on a particular URL prefix, e.g. `SB_URL_PREFIX=/notes` diff --git a/website/Plugs/Development.md b/website/Plugs/Development.md index cacfd1b5..a121dd25 100644 --- a/website/Plugs/Development.md +++ b/website/Plugs/Development.md @@ -2,10 +2,10 @@ The easiest way to get started is to click the “Use this template” on the [s Generally, every plug consists of a YAML manifest file named `yourplugname.plug.yaml`. This file defines all functions that form your plug. To be loadable by SilverBullet, it needs to be compiled into a bundle (ending with `.plug.js`). -For this you need to have [Deno](https://deno.com) installed, after which you can run the `deno task build` command specified in the plug template repo: +To compile it, run the build command specified in the plug template repo: ```shell -deno task build +npm run build ``` For development it’s easiest to simply copy the `.plug.js` file into your space’s `_plug/` folder after it’s built: