Client available upgrade notification
If the server is updated, but the client doesn't match the server version, a notification will appear instructing the user to reload.
This commit is contained in:
+19
-2
@@ -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
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -80,9 +80,19 @@ export class ProxyRouter extends EventEmitter<ProxyRouterEvents> {
|
||||
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;
|
||||
|
||||
@@ -229,7 +229,7 @@ export class HttpSpacePrimitives implements SpacePrimitives {
|
||||
}
|
||||
|
||||
// If not: throws an error or invokes a redirect
|
||||
async ping() {
|
||||
async ping(): Promise<string | undefined> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -249,4 +249,8 @@ export type ServiceWorkerSourceMessage =
|
||||
| {
|
||||
type: "encryption-key";
|
||||
key: string;
|
||||
}
|
||||
| {
|
||||
type: "server-version";
|
||||
serverVersion: string;
|
||||
};
|
||||
|
||||
@@ -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<void> {
|
||||
return syscall("editor.flashNotification", message, type);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,18 @@ export type FilterOption = {
|
||||
prefix?: string;
|
||||
} & Record<string, any>;
|
||||
|
||||
export type NotificationType = "info" | "error" | "warning";
|
||||
|
||||
export const notificationDismissTimeouts: Record<NotificationType, number> = {
|
||||
info: 4000,
|
||||
error: 5000,
|
||||
warning: 8000,
|
||||
};
|
||||
|
||||
export type Notification = {
|
||||
id: number;
|
||||
message: string;
|
||||
type: "info" | "error";
|
||||
type: NotificationType;
|
||||
date: Date;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
})
|
||||
|
||||
@@ -18,6 +18,8 @@ type ServerConfig struct {
|
||||
HostURLPrefix string
|
||||
|
||||
ClientBundle SpacePrimitives
|
||||
|
||||
Version string
|
||||
}
|
||||
|
||||
type UserPasswordAuthorizer func(username, password string) bool
|
||||
|
||||
@@ -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 .
|
||||
|
||||
@@ -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`
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user