Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Keep notifications clear of the top bar and the right dock bar

Jeffrey Chenf7f87d581d5f
diff --git a/app/src/assets/scss/component/_snackbar.scss b/app/src/assets/scss/component/_snackbar.scss
index 3668ddac86..d0de1f133a 100644
--- a/app/src/assets/scss/component/_snackbar.scss
+++ b/app/src/assets/scss/component/_snackbar.scss
@@ -1,3 +1,25 @@
+// 通知与顶栏、右侧停靠栏和窗口边缘保持同一固定间距,提前定义在 body 上以便启动阶段的临时通知复用
+body {
+ --b3-snackbar-gap: 4px;
+ // 非融合顶栏使用工具栏高度
+ --b3-snackbar-top-bar-height: var(--b3-ui-toolbar-height, 32px);
+ // 原生窗口控件可能高于顶栏,通知从其下方开始
+ --b3-snackbar-top: calc(max(var(--b3-snackbar-top-bar-height), var(--b3-window-controls-height, 0px)) + var(--b3-snackbar-gap));
+ // 右侧停靠栏占用布局空间时避让它的宽度,隐藏或浮动时只保留窗口边缘间距
+ --b3-snackbar-right: calc(var(--b3-dock-right-width, 0px) + var(--b3-snackbar-gap));
+}
+
+// 页签融合至顶栏时工具栏与页签行同高;独立窗口没有工具栏,顶部同样是页签行
+body.body--toolbar-hide,
+body.body--window {
+ --b3-snackbar-top-bar-height: var(--b3-ui-panel-height, 42px);
+}
+
+// 桌面浏览器顶栏高度跟随浏览器标题栏
+html[data-frontend="browser-desktop"] body:not(.body--toolbar-hide):not(.body--window) {
+ --b3-snackbar-top-bar-height: calc(env(titlebar-area-height, var(--b3-ui-browser-titlebar-height, 31px)) + 1px);
+}
+
.b3-snackbar {
position: relative;
transition: transform 256ms cubic-bezier(.45, .05, .55, .95) 0ms;
@@ -16,12 +38,11 @@
}
&s {
- --b3-snackbar-top: max(22px, calc(var(--b3-window-controls-height, 0px) + 16px));
position: fixed;
- right: 30px;
+ right: var(--b3-snackbar-right);
top: var(--b3-snackbar-top);
// 不能设置死,否则右键菜单会被遮盖 z-index: 999999;
- max-height: calc(100vh - var(--b3-snackbar-top) - 16px);
+ max-height: calc(100vh - var(--b3-snackbar-top) - var(--b3-snackbar-gap));
display: flex;
flex-direction: column;
transform: translate3d(calc(20vw + 48px), 0, 0);
@@ -102,8 +123,8 @@
@media screen and (max-width: 520px) {
.b3-snackbars {
- --b3-snackbar-top: max(35px, calc(var(--b3-window-controls-height, 0px) + 16px));
- right: calc(10vw - 18px);
+ // 窄窗口压缩横向间距,同时仍然避让右侧停靠栏
+ right: max(calc(10vw - 18px), var(--b3-snackbar-right));
}
.b3-snackbar__content {
diff --git a/app/src/config/entryVisibility/runtime.test.ts b/app/src/config/entryVisibility/runtime.test.ts
index 42de015588..ae66edcd14 100644
--- a/app/src/config/entryVisibility/runtime.test.ts
+++ b/app/src/config/entryVisibility/runtime.test.ts
@@ -327,7 +327,8 @@ test("entry profile saves in settings windows send requests and flush pending ch
const context = {
window,
document: {querySelectorAll: (): HTMLElement[] => [], querySelector: (): Element => null,
- getElementById: (): HTMLElement => null},
+ getElementById: (): HTMLElement => null,
+ documentElement: {style: {setProperty: () => {}}}},
CustomEvent: class {constructor(public type: string) {}},
};
const bar = {} as typeof import("../../layout/dock/barVisibility");
diff --git a/app/src/dialog/message.ts b/app/src/dialog/message.ts
index 5cb8586ea8..906d00cd93 100644
--- a/app/src/dialog/message.ts
+++ b/app/src/dialog/message.ts
@@ -81,7 +81,7 @@ export const showMessage = (message: string, timeout = 6000, type = "info", mess
if (!messagesElement) {
let tempMessages = document.getElementById("tempMessage");
if (!tempMessages) {
- document.body.insertAdjacentHTML("beforeend", `<div style="font-size: 14px;top: max(22px, calc(var(--b3-window-controls-height, 0px) + 16px));position: fixed;z-index: 100;right: 30px;line-height: 20px;word-break: break-word;display: flex;flex-direction: column;align-items: flex-end;"
+ document.body.insertAdjacentHTML("beforeend", `<div style="font-size: 14px;top: var(--b3-snackbar-top, 48px);position: fixed;z-index: 100;right: var(--b3-snackbar-right, 16px);line-height: 20px;word-break: break-word;display: flex;flex-direction: column;align-items: flex-end;"
id="tempMessage"></div>`);
tempMessages = document.getElementById("tempMessage");
}
diff --git a/app/src/layout/dock/barVisibility.test.ts b/app/src/layout/dock/barVisibility.test.ts
index 5d7fd7fad2..d2e53631d9 100644
--- a/app/src/layout/dock/barVisibility.test.ts
+++ b/app/src/layout/dock/barVisibility.test.ts
@@ -10,12 +10,18 @@ const loadBarVisibility = (layout: unknown, hideStatusBar = false) => {
const source = readFileSync(resolve(process.cwd(), "src/layout/dock/barVisibility.ts"), "utf8");
const compiled = transpileModule(source, {compilerOptions: {module: ModuleKind.CommonJS}}).outputText;
const exports = {} as typeof import("./barVisibility");
+ const rootProperties: Record<string, string> = {};
runInNewContext(compiled, {
exports,
- document: {querySelectorAll: (): HTMLElement[] => []},
+ document: {
+ documentElement: {style: {setProperty: (name: string, value: string) => {
+ rootProperties[name] = value;
+ }}},
+ querySelectorAll: (): HTMLElement[] => [],
+ },
window: {siyuan: {layout, config: {appearance: {hideStatusBar}}}},
});
- return exports;
+ return {bar: exports, rootProperties};
};
describe("dock padding", () => {
@@ -23,9 +29,10 @@ describe("dock padding", () => {
for (const layout of [undefined, {}, {layout: {children: []}},
{layout: {children: [{element: {style: {}}}]}},
{layout: {children: [{element: {style: {}}}]}, leftDock: {elements: []}, rightDock: {elements: []}}]) {
- const bar = loadBarVisibility(layout);
+ const {bar, rootProperties} = loadBarVisibility(layout);
assert.doesNotThrow(bar.adjustDockPadding);
assert.doesNotThrow(bar.syncDockBarVisibility);
+ assert.equal(rootProperties["--b3-dock-right-width"], "0px");
}
});
@@ -38,15 +45,15 @@ describe("dock padding", () => {
leftDock: {elements: [{parentElement: {classList: {contains: () => leftHidden}}}]},
rightDock: {elements: [{parentElement: {classList: {contains: () => rightHidden}}}]},
};
- loadBarVisibility(layout, true).adjustDockPadding();
+ loadBarVisibility(layout, true).bar.adjustDockPadding();
assert.deepEqual(style, {marginLeft: "var(--b3-layout-space)", marginRight: "",
marginBottom: "var(--b3-layout-space)"});
leftHidden = false;
rightHidden = true;
- loadBarVisibility(layout).adjustDockPadding();
+ loadBarVisibility(layout).bar.adjustDockPadding();
assert.deepEqual(style, {marginLeft: "", marginRight: "var(--b3-layout-space)", marginBottom: ""});
rightHidden = false;
- loadBarVisibility(layout).adjustDockPadding();
+ loadBarVisibility(layout).bar.adjustDockPadding();
assert.deepEqual(style, {marginLeft: "", marginRight: "", marginBottom: ""});
});
@@ -58,7 +65,7 @@ describe("dock padding", () => {
leftDock: {elements: [{parentElement: floatingBar}]},
rightDock: {elements: [{parentElement: floatingBar}]},
};
- loadBarVisibility(layout).adjustDockPadding();
+ loadBarVisibility(layout).bar.adjustDockPadding();
assert.deepEqual(style, {marginLeft: "var(--b3-layout-space)", marginRight: "var(--b3-layout-space)", marginBottom: ""});
});
});
diff --git a/app/src/layout/dock/barVisibility.ts b/app/src/layout/dock/barVisibility.ts
index 6cbd73d295..4a8602b57f 100644
--- a/app/src/layout/dock/barVisibility.ts
+++ b/app/src/layout/dock/barVisibility.ts
@@ -35,6 +35,8 @@ export const adjustDockPadding = () => {
export const syncDockBarVisibility = () => {
let changed = false;
let hasFloatingBar = false;
+ // 右侧停靠栏占用布局空间时记录宽度,供通知等固定定位元素避让
+ let rightDockWidth = "0px";
document.querySelectorAll<HTMLElement>(".dock").forEach((item) => {
const sections = Array.from(item.querySelectorAll<HTMLElement>(":scope > .dock__items"));
const sectionVisibility = sections.map((section) =>
@@ -62,6 +64,9 @@ export const syncDockBarVisibility = () => {
);
changed = item.classList.contains("fn__none") !== hidden || wasFloating !== floating || changed;
item.classList.toggle("fn__none", hidden);
+ if (item.id === "dockRight" && !hidden && !floating) {
+ rightDockWidth = "var(--b3-ui-dock-width, 42px)";
+ }
if (floating) {
hasFloatingBar = true;
// 保留停靠栏原有的顶栏避让和高度范围,临时显示时脱离编辑区布局。
@@ -75,6 +80,7 @@ export const syncDockBarVisibility = () => {
item.style.zIndex = "";
}
});
+ document.documentElement.style.setProperty("--b3-dock-right-width", rightDockWidth);
adjustDockPadding();
if (hasFloatingBar && !floatingBarResizeObserver) {
floatingBarResizeObserver = new ResizeObserver(() => {
diff --git a/app/tests/dockBarVisibility.test.js b/app/tests/dockBarVisibility.test.js
index 6af5289785..6bf694384a 100644
--- a/app/tests/dockBarVisibility.test.js
+++ b/app/tests/dockBarVisibility.test.js
@@ -83,6 +83,12 @@ const browserCases = async (sources, css, template) => {
const leftBar = document.getElementById("dockLeft");
const rightBar = document.getElementById("dockRight");
check.ok(hidden(leftBar) && hidden(rightBar));
+ const rightDockSpace = () => document.documentElement.style.getPropertyValue("--b3-dock-right-width");
+ const checkRightDockSpace = (message) => {
+ const reserved = !hidden(rightBar) && !rightBar.classList.contains("dock--float");
+ check.equal(rightDockSpace(), reserved ? "var(--b3-ui-dock-width, 42px)" : "0px", message);
+ };
+ checkRightDockSpace("a hidden right bar reserves no space for fixed overlays");
const {windowMouseMove} = load("mousemove", dependencies);
const move = event => windowMouseMove(event);
document.addEventListener("mousemove", move);
@@ -221,6 +227,7 @@ const browserCases = async (sources, css, template) => {
open("Bottom");
await settle();
check.ok(!hidden(leftBar) && !hidden(rightBar));
+ checkRightDockSpace("a temporary right bar overlays the editor instead of reserving space");
docks.Left.hideDock();
check.ok(hidden(leftBar) && !hidden(rightBar), "each side closes independently");
check.equal(bottom.element.style.left, "0px");
@@ -270,6 +277,8 @@ const browserCases = async (sources, css, template) => {
bar.syncDockBarVisibility();
docks.Right.showDock(true);
check.ok(!hidden(leftBar) && !hidden(rightBar));
+ check.equal(rightDockSpace(), "var(--b3-ui-dock-width, 42px)",
+ "a fixed right bar publishes its width so notifications keep a gap from it");
check.equal(rightBar.style.top, "");
check.equal(rightBar.style.zIndex, "");
docks.Right.hideDock();
@@ -277,6 +286,7 @@ const browserCases = async (sources, css, template) => {
window.siyuan.config.uiLayout.hideDock = true;
bar.syncDockBarVisibility();
check.ok(hidden(leftBar) && hidden(rightBar));
+ check.equal(rightDockSpace(), "0px", "hiding the right bar restores the window edge offset");
check.equal(window.siyuan.config.uiLayout.hideDock, true);
return "Floating dock bar cases passed";
};
diff --git a/app/tests/snackbarPosition.test.js b/app/tests/snackbarPosition.test.js
index 9ad62c7102..0d8c88c3d9 100644
--- a/app/tests/snackbarPosition.test.js
+++ b/app/tests/snackbarPosition.test.js
@@ -3,48 +3,79 @@ const {mkdtempSync, readFileSync, rmSync} = require("node:fs");
const os = require("node:os");
const path = require("node:path");
-const cases = async (source, css, mobileCSS) => {
+const cases = async (source, css, densityCSS, mobileCSS) => {
const check = require("node:assert/strict");
const style = document.createElement("style");
- style.textContent = css + `body {margin:0} .fn__flex-1 {flex:1;min-height:0;overflow:auto}
+ style.textContent = densityCSS + css + `body {margin:0} .fn__flex-1 {flex:1;min-height:0;overflow:auto}
.b3-snackbars, .b3-snackbar {transition:none}`;
document.head.append(style);
window.siyuan = {languages: {}, zIndex: 100};
const {initMessage, showMessage} = new Function("genUUID", "Constants", "getHostCapabilities", "sanitizeKernelHTML",
source + "\nreturn {initMessage, showMessage};")(() => "notification", {SIYUAN_VERSION: "test", TIMEOUT_INPUT: 0},
() => ({ownsKernel: true}), html => html);
- for (const width of [900, 420]) {
- await require("electron").ipcRenderer.invoke("resize", width);
- for (const height of [0, 28, 32, 34, 42, 64]) {
- document.documentElement.style.setProperty("--b3-window-controls-height", `${height}px`);
- document.body.innerHTML = '<div id="message" class="b3-snackbars"></div>';
- showMessage("Startup notification", 0);
- check.ok(document.getElementById("tempMessage").getBoundingClientRect().top >= height + (height ? 16 : 0),
- "startup notifications avoid native window controls");
- initMessage();
- await new Promise(resolve => setTimeout(resolve, 0));
- const container = document.getElementById("message");
- const message = container.querySelector(".b3-snackbar");
- const rect = message.getBoundingClientRect();
- check.ok(rect.top >= height + (height ? 16 : 0), `notification avoids ${height}px caption buttons at ${width}px`);
- check.ok(rect.top + parseFloat(getComputedStyle(container).maxHeight) <= innerHeight - 15,
- "the notification stack remains inside the viewport");
- const close = message.querySelector(".b3-snackbar__close");
- const closeRect = close.getBoundingClientRect();
- const target = document.elementFromPoint(closeRect.left + closeRect.width / 2, closeRect.top + closeRect.height / 2);
- check.equal(target.closest(".b3-snackbar__close"), close, "the close button receives the pointer");
- target.dispatchEvent(new MouseEvent("click", {bubbles: true}));
- check.equal(message.classList.contains("b3-snackbar--hide"), true, "click closes the notification");
- await new Promise(resolve => setTimeout(resolve, 0));
+ const gap = parseFloat(getComputedStyle(document.body).getPropertyValue("--b3-snackbar-gap"));
+ const near = (actual, expected, message) =>
+ check.ok(Math.abs(actual - expected) <= 1, `${message}: ${actual} vs ${expected}`);
+ const root = document.documentElement;
+ for (const compact of [false, true]) {
+ if (compact) {
+ root.setAttribute("data-ui-density", "compact");
+ } else {
+ root.removeAttribute("data-ui-density");
+ }
+ for (const fused of [false, true]) {
+ document.body.classList.toggle("body--toolbar-hide", fused);
+ for (const width of [900, 420]) {
+ await require("electron").ipcRenderer.invoke("resize", width);
+ const narrowRight = width <= 520 ? width * 0.1 - 18 : 0;
+ for (const dock of [0, 34, 42]) {
+ root.style.setProperty("--b3-dock-right-width", `${dock}px`);
+ for (const height of [0, 28, 32, 34, 42, 64]) {
+ root.style.setProperty("--b3-window-controls-height", `${height}px`);
+ const topBar = fused ? (compact ? 34 : 42) : (compact ? 28 : 32);
+ const expectedTop = Math.max(topBar, height) + gap;
+ const expectedRight = Math.max(dock + gap, narrowRight);
+ const label = `${compact ? "compact " : ""}${fused ? "fused" : "separate"} top bar, ` +
+ `${dock}px dock, ${height}px caption buttons at ${width}px`;
+ document.body.innerHTML = '<div id="message" class="b3-snackbars"></div>';
+ showMessage("Startup notification", 0);
+ near(document.getElementById("tempMessage").getBoundingClientRect().top, expectedTop,
+ `startup notifications keep the top bar gap with ${label}`);
+ initMessage();
+ await new Promise(resolve => setTimeout(resolve, 0));
+ const container = document.getElementById("message");
+ const message = container.querySelector(".b3-snackbar");
+ const rect = message.getBoundingClientRect();
+ near(rect.top, expectedTop, `notifications clear the ${label}`);
+ near(container.getBoundingClientRect().right, innerWidth - expectedRight,
+ `notifications keep the dock and edge gap with ${label}`);
+ check.ok(rect.top + parseFloat(getComputedStyle(container).maxHeight) <= innerHeight - gap + 1,
+ "the notification stack remains inside the viewport");
+ const close = message.querySelector(".b3-snackbar__close");
+ const closeRect = close.getBoundingClientRect();
+ const target = document.elementFromPoint(closeRect.left + closeRect.width / 2,
+ closeRect.top + closeRect.height / 2);
+ check.equal(target.closest(".b3-snackbar__close"), close, "the close button receives the pointer");
+ target.dispatchEvent(new MouseEvent("click", {bubbles: true}));
+ check.equal(message.classList.contains("b3-snackbar--hide"), true, "click closes the notification");
+ await new Promise(resolve => setTimeout(resolve, 0));
+ }
+ }
+ }
}
}
+ document.body.classList.remove("body--toolbar-hide");
+ root.removeAttribute("data-ui-density");
+ root.style.removeProperty("--b3-window-controls-height");
+ root.style.removeProperty("--b3-dock-right-width");
style.textContent += mobileCSS;
- document.documentElement.style.removeProperty("--b3-window-controls-height");
+ document.body.innerHTML = '<div id="message" class="b3-snackbars"></div>';
for (const safeTop of [0, 44]) {
document.body.style.setProperty("--mobile-top-safe-area", `${safeTop}px`);
const container = document.getElementById("message");
check.equal(container.getBoundingClientRect().top, safeTop + 35, "mobile notifications retain their safe-area offset");
- check.ok(container.getBoundingClientRect().top + parseFloat(getComputedStyle(container).maxHeight) <= innerHeight - 15);
+ check.ok(container.getBoundingClientRect().top + parseFloat(getComputedStyle(container).maxHeight) <=
+ innerHeight - gap + 1, "mobile notifications keep the bottom gap");
}
return "Snackbar positioning passed";
};
@@ -62,13 +93,16 @@ if (process.versions.electron && process.type === "browser") {
.replace(/^import .*;\r?\n/gm, "").replace(/^export /gm, ""),
{compilerOptions: {target: ts.ScriptTarget.ES2021}}).outputText;
const css = require("sass").compile(path.join(__dirname, "../src/assets/scss/component/_snackbar.scss")).css;
+ const densityCSS = require("sass").compile(path.join(__dirname, "../src/assets/scss/util/_density.scss")).css;
const mobileCSS = require("sass").compile(path.join(__dirname, "../src/assets/scss/main/_mobile.scss")).css;
- console.log(await win.webContents.executeJavaScript(`(${cases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(css)}, ${JSON.stringify(mobileCSS)})`));
+ console.log(await win.webContents.executeJavaScript(
+ `(${cases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(css)}, ` +
+ `${JSON.stringify(densityCSS)}, ${JSON.stringify(mobileCSS)})`));
win.destroy();
app.exit(0);
})().catch(error => { console.error(error); require("electron").app.exit(1); });
} else {
- require("node:test").test("notifications and close buttons avoid native captions at every window density", {
+ require("node:test").test("notifications keep a fixed gap from the top bar, the right dock and the window edge", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 30000,
}, async () => {