+1








766fb96ff2
* Adding support for hosting with URL prefix to make reverse-proxy setup on sub-path possible
* Adjusting recent changes to auth.html (changing to relative URLs) after rebasing from upstream
* Adjusting service_worker and application manifest to support URL-prefix
* Add notes on Space Lua Pattern Matching (#1366)
* Remove common/space_lua/stdlib/math.md (#1371)
* Escape pipe symbol in string.gsub (#1370)
* feat: configure vim in CONFIG (#1369)
* Fix week calculation (#1368)
* Add more tests for week calculation
* Fix week calculation
* Add more tests
* Implement Lua built-in function os.difftime (#1367)
* Implement Lua built-in function os.difftime
* Test os.difftime
---------
Co-authored-by: Zef Hemel <zef@zef.me>
* Fix index page naming during server initialization (#1365)
* Allow non-zero shell exit codes (#1377)
* Generate version from git describe at build time (#1374)
* Generate version from git describe at build time
* Add 2.0-beta prefix
* Use Deno.Command instead of Deno.run
* Add missing case to math.random and check arguments (#1372)
* Fix paragraphs for the tag page (#1376)
* Render a predefined string for empty markdown table instead of pipe characters (#1387)
* Fix string.find (#1390)
* Fetch tags and history for proper version string generation (#1388)
* Fix support for disabling shortcuts (#1393)
* Add GitHub Actions Cache to reduce build times (#1394)
* Order strings in queries using collation algorithm (#1391)
Configurable with queryCollation, default value maintains old behaviour.
Added tests, schema, example settings, and documentation to query page.
Close: #614
Close: #1316
* Utility function to handle empty query results and templates (#1386)
* Add global Lua function 'some'
Moved documentation for 'each' function to non-standard section.
* Revert "Add optional argument to template.each for empty collection output (#1359)"
This reverts commit b73dadec67.
* Reimplement #1359 using 'some' function
* Update Lua to event.listEvents to match plugos syscall (#1397)
The documentation, example, and other function names use
`event.listEvents`, but `event.list` is being registered with the
client.
* Update widget header to not overflow container (#1410)
Also add a 10px margin below the header to maintain consistent spacing
around the widget contents.
* fix: case insensitive admonitions by default (#1409)
* fix: closing bracket is missing (#1408)
* Add optional priority attribute to PageCreatingContent (#1392)
* Add optional priority attribute to PageCreatingContent
* Minor simplification
* Fix comments
* Revert changes
* Add pageEventHandlers
* Use UTC year, month, and date for strings lacking time components (#1403)
* feat: allow CONFIG.md in any directory (#1398)
* fix: bundle external dependencies (#1379)
* Deno bump
* Copy-edit splash screen text (#1413)
* Fixes #1401 by implementing Lua's select
* Fixes offline capability of PWA (I hope).
Now storing config in localStorage.
* fix lint
* Reduce blast radius of Lua errors
* Fixes #1411: adds 'priority' setting for space style
* Refactor: Merging common/ into web/
* Fixes #1400
* Improves #1312 by rendering Lua expressions (but not widgets)
* Fix minor typos, add configuration to the docs
---------
Co-authored-by: wbhouston <wmbhouston@gmail.com>
Co-authored-by: Lennart Ochel <lennart.ochel@outlook.com>
Co-authored-by: Matthias Benaets <89214559+MatthiasBenaets@users.noreply.github.com>
Co-authored-by: Zef Hemel <zef@zef.me>
Co-authored-by: Marek S. Łukasiewicz <marek@lukasiewicz.tech>
Co-authored-by: Ivan Alejandro <ivanalejandro0@gmail.com>
Co-authored-by: Albert-Jan de Vries <aj+github@albert-jandevries.nl>
Co-authored-by: Cole Stowell <121599022+costowell@users.noreply.github.com>
Co-authored-by: Jim Tittsler <jimt@onjapan.net>
118 lines
3.9 KiB
TypeScript
118 lines
3.9 KiB
TypeScript
import { safeRun } from "$lib/async.ts";
|
|
import { Client, type ClientConfig } from "./client.ts";
|
|
|
|
const configCacheKey = "config";
|
|
|
|
safeRun(async () => {
|
|
// First we attempt to fetch the config from the server
|
|
let clientConfig: ClientConfig | undefined;
|
|
try {
|
|
const configResponse = await fetch(".config", {
|
|
// We don't want to follow redirects, we want to get the redirect header in case of auth issues
|
|
redirect: "manual",
|
|
// Add short timeout in case of a bad internet connection, this would block loading of the UI
|
|
signal: AbortSignal.timeout(1000),
|
|
});
|
|
const redirectHeader = configResponse.headers.get("location");
|
|
if (
|
|
configResponse.status === 401 && redirectHeader
|
|
) {
|
|
alert(
|
|
"Received an authentication redirect, redirecting to URL: " +
|
|
redirectHeader,
|
|
);
|
|
location.href = redirectHeader;
|
|
return;
|
|
}
|
|
clientConfig = await configResponse.json();
|
|
// Persist to localStorage
|
|
localStorage.setItem(configCacheKey, JSON.stringify(clientConfig));
|
|
} catch (e: any) {
|
|
console.error("Failed to fetch client config from server", e.message);
|
|
// We may be offline, let's see if we have a cached config
|
|
const configString = localStorage.getItem(configCacheKey);
|
|
if (configString) {
|
|
// Yep! Let's use it
|
|
clientConfig = JSON.parse(configString);
|
|
} else {
|
|
alert(
|
|
"Could not fetch configuration from server. Make sure you have an internet connection.",
|
|
);
|
|
// Returning here because there's no way to recover from this
|
|
return;
|
|
}
|
|
}
|
|
console.log("Client config", clientConfig);
|
|
console.log("Booting SilverBullet client");
|
|
|
|
if (clientConfig!.readOnly) {
|
|
console.log("Running in read-only mode");
|
|
}
|
|
if (navigator.serviceWorker) {
|
|
// Register service worker
|
|
navigator.serviceWorker
|
|
.register(new URL("service_worker.js", document.baseURI), {
|
|
type: "module",
|
|
})
|
|
.then((registration) => {
|
|
console.log("Service worker registered...");
|
|
|
|
// Set up update detection
|
|
registration.addEventListener("updatefound", () => {
|
|
const newWorker = registration.installing;
|
|
console.log("New service worker installing...");
|
|
|
|
if (newWorker) {
|
|
newWorker.addEventListener("statechange", () => {
|
|
if (
|
|
newWorker.state === "installed" &&
|
|
navigator.serviceWorker.controller
|
|
) {
|
|
console.log(
|
|
"New service worker installed and ready to take over.",
|
|
);
|
|
// Force the new service worker to activate immediately
|
|
newWorker.postMessage({ type: "skipWaiting" });
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Handle service worker controlled changes (when a new service worker takes over)
|
|
let refreshing = false;
|
|
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
|
if (!refreshing) {
|
|
refreshing = true;
|
|
console.log(
|
|
"New service worker activated, please reload to activate the new version.",
|
|
);
|
|
}
|
|
});
|
|
|
|
navigator.serviceWorker.ready.then((registration) => {
|
|
registration.active!.postMessage({
|
|
type: "config",
|
|
config: clientConfig,
|
|
});
|
|
});
|
|
} else {
|
|
console.warn(
|
|
"Not launching service worker, likely because not running from localhost or over HTTPs. This means SilverBullet will not be available offline.",
|
|
);
|
|
}
|
|
const client = new Client(
|
|
document.getElementById("sb-root")!,
|
|
clientConfig!,
|
|
);
|
|
// @ts-ignore: on purpose
|
|
globalThis.client = client;
|
|
await client.init();
|
|
});
|
|
|
|
if (!globalThis.indexedDB) {
|
|
alert(
|
|
"SilverBullet requires IndexedDB to operate and it is not available in your browser. Please use a recent version of Chrome, Firefox (not in private mode) or Safari.",
|
|
);
|
|
}
|