Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Keep the close-to-tray card in front of the user

AdamPlatin123f92c27420ace
diff --git a/app/src/background-notice.mjs b/app/src/background-notice.mjs
index 0c7cbbc0..dadeb957 100644
--- a/app/src/background-notice.mjs
+++ b/app/src/background-notice.mjs
@@ -18,12 +18,13 @@ export class BackgroundNotice {
/**
* @param {{
* marker: string,
- * show: (options: object) => Promise<{ response: number }>,
+ * show: (options: object) => Promise<{ response: number, unasked?: boolean }>,
* focus?: () => void,
* message: string,
* confirm: string,
* log?: Pick<Console, 'warn'>,
- * }} options `marker` is where the acknowledgement is kept, `show` the shell dialog.
+ * }} options `marker` is where the acknowledgement is kept, `show` the shell's question;
+ * an `unasked` answer (the question could not be shown) hides without being kept.
*/
constructor(options) {
this.#marker = options.marker
@@ -56,12 +57,13 @@ export class BackgroundNotice {
async #ask(hide) {
try {
- const { response } = await this.#show({
+ const { response, unasked = false } = await this.#show({
type: 'info', title: 'DeepSeek Bot', message: this.#message,
buttons: [this.#confirm], defaultId: 0, cancelId: -1, noLink: true,
})
// A cancelled box leaves the window where it is.
if (this.#disposed || response !== 0) return
+ if (unasked) { hide(); return }
this.#acknowledged = true
try {
mkdirSync(dirname(this.#marker), { recursive: true })
diff --git a/app/src/bot-views.mjs b/app/src/bot-views.mjs
index e8fa722b..b75e4acb 100644
--- a/app/src/bot-views.mjs
+++ b/app/src/bot-views.mjs
@@ -47,6 +47,7 @@ export class BotViews {
#saved = {}
#active = new Map()
#held = new Set()
+ #covered = false
// The tabs whose view waits for a window to belong to.
#waiting = new Set()
@@ -254,7 +255,8 @@ export class BotViews {
const entry = this.#views.get(tabId)
if (!entry) return false
if (rect !== null) entry.view.setBounds(rectOf(rect))
- entry.view.setVisible(visible === true)
+ entry.shown = visible === true
+ entry.view.setVisible(entry.shown && !this.#covered)
if (visible === true) {
this.#active.set(entry.botId, tabId)
this.#remember(entry)
@@ -337,6 +339,18 @@ export class BotViews {
return `ws://127.0.0.1:${this.#address.port}/devtools/browser/${token}`
}
+ /**
+ * The app's card is up in the window (main.mjs askInWindow). The views are drawn above the
+ * page, so they stay hidden until it goes, or they would cover the card.
+ * @param {boolean} covered
+ */
+ cover(covered) {
+ this.#covered = covered
+ for (const entry of this.#views.values()) {
+ if (!entry.view.webContents.isDestroyed()) entry.view.setVisible(entry.shown === true && !covered)
+ }
+ }
+
sync(botId) {
return [...this.#views.values()].filter(entry => entry.botId === botId).map(entry => this.#state(entry))
}
diff --git a/app/src/main.mjs b/app/src/main.mjs
index b7380f3d..5e9557ed 100644
--- a/app/src/main.mjs
+++ b/app/src/main.mjs
@@ -155,7 +155,8 @@ const shell = createShell({
ready: () => places !== undefined && origin !== undefined && bootstrap !== undefined,
// The one-time notice is a card in the team window; a page that cannot show it lets the window
// go to the tray, which is what the notice would have said.
- notice: { marker: () => join(app.getPath('userData'), 'tray-close-acknowledged'), show: options => boxInWindow(options, 0) },
+ // A second close while the card is up brings the window, and so the card, to the front.
+ notice: { marker: () => join(app.getPath('userData'), 'tray-close-acknowledged'), show: options => boxInWindow(options, 0), focus: () => { toFront(mainWindow) } },
// Without a tray the close asks whether the app should end; unasked, the window minimizes.
fallback: { show: options => boxInWindow(options, options.cancelId) },
})
@@ -1103,13 +1104,17 @@ let cardCount = 0
* (preload.cjs showCard, page-card.css): the index of the button the user clicks, -1 when a newer
* card took its place, undefined when the page cannot show it (not loaded, gone, or silent for
* CARD_SHOWN_MS) or goes away before the answer.
+ * `front` brings the window to the front first: a close waits on the answer, so its card must
+ * be where the user looks.
* @param {{ message: string, detail?: string, buttons: { label: string, primary?: boolean }[], cancel?: number }} card
+ * @param {{ front?: boolean }} [how]
* @returns {Promise<number | undefined>}
*/
-function askInWindow(card) {
+function askInWindow(card, { front = false } = {}) {
const win = mainWindow
const contents = win?.webContents
if (win === undefined || win.isDestroyed() || contents.isLoading() || !contents.getURL().startsWith(`${origin}/`)) return Promise.resolve(undefined)
+ if (front) toFront(win)
const id = (cardCount += 1)
return new Promise((resolve) => {
let seen = false
@@ -1119,11 +1124,14 @@ function askInWindow(card) {
clearTimeout(timer)
contents.off('did-start-loading', away)
contents.off('destroyed', away)
+ if (cards.size === 0) botViews?.cover(false)
resolve(value)
}
const away = () => { settle(undefined) }
const timer = setTimeout(() => { if (!seen) away() }, CARD_SHOWN_MS)
cards.set(id, { settle, shown: () => { seen = true } })
+ // The Bot browser views are drawn above the page and would cover the card.
+ botViews?.cover(true)
contents.once('did-start-loading', away)
contents.once('destroyed', away)
contents.send(IPC.card, { id, ...card })
@@ -1135,8 +1143,15 @@ function askInWindow(card) {
async function boxInWindow(options, unasked) {
const buttons = options.buttons.map((label, index) => ({ label, primary: index === options.defaultId }))
const cancel = options.cancelId >= 0 ? options.cancelId : undefined
- const answer = await askInWindow({ message: options.message, detail: options.detail, buttons, cancel })
- return { response: answer === undefined ? unasked : answer }
+ const answer = await askInWindow({ message: options.message, detail: options.detail, buttons, cancel }, { front: true })
+ return answer === undefined ? { response: unasked, unasked: true } : { response: answer }
+}
+
+function toFront(win) {
+ if (win === undefined || win.isDestroyed()) return
+ if (win.isMinimized()) win.restore()
+ win.show()
+ win.focus()
}
// What the updater does when the user says yes. The answer may come later, when the window
diff --git a/app/src/shell.mjs b/app/src/shell.mjs
index 1760f7a9..6856d3fb 100644
--- a/app/src/shell.mjs
+++ b/app/src/shell.mjs
@@ -40,7 +40,7 @@ export const SHELL_TEXT = {
* quit: () => void,
* busy: () => boolean,
* ready: () => boolean,
- * notice: { marker: () => string, show: (options: object) => Promise<{ response: number }> },
+ * notice: { marker: () => string, show: (options: object) => Promise<{ response: number }>, focus?: () => void },
* fallback?: { show: (options: object) => Promise<{ response: number }> },
* log?: Pick<Console, 'warn'>,
* }} options the pieces of the app the shell drives
@@ -204,7 +204,7 @@ export function createShell(options) {
powerMonitor.on('shutdown', () => { sessionEnding = true })
}
notice = new BackgroundNotice({
- marker: options.notice.marker(), show: options.notice.show, message: text().notice, confirm: text().noticeConfirm, log,
+ marker: options.notice.marker(), show: options.notice.show, focus: options.notice.focus, message: text().notice, confirm: text().noticeConfirm, log,
})
buildTray()
}
diff --git a/app/test/background-notice.test.mjs b/app/test/background-notice.test.mjs
index 5657d878..44beec9f 100644
--- a/app/test/background-notice.test.mjs
+++ b/app/test/background-notice.test.mjs
@@ -41,6 +41,20 @@ describe('the notice before the window hides', () => {
assert.equal(existsSync(join(app.folder, 'acknowledged')), false, 'nothing is kept')
})
+ test('a notice that could not be shown hides the window and asks again next time', async (t) => {
+ const asked = []
+ const app = harness({ show: async (options) => { asked.push(options); return { response: 0, unasked: true } } })
+ t.after(app.cleanup)
+ let hidden = 0
+ app.notice.close(() => { hidden += 1 })
+ await settle()
+ assert.equal(hidden, 1, 'the window is hidden')
+ assert.equal(existsSync(join(app.folder, 'acknowledged')), false, 'nothing is kept')
+ app.notice.close(() => { hidden += 1 })
+ await settle()
+ assert.equal(asked.length, 2, 'the next close asks again')
+ })
+
test('a notice that is answered once is not shown again', async (t) => {
const app = harness()
t.after(app.cleanup)
diff --git a/app/test/bot-views.test.mjs b/app/test/bot-views.test.mjs
index 8e023f4e..bd9b9012 100644
--- a/app/test/bot-views.test.mjs
+++ b/app/test/bot-views.test.mjs
@@ -455,6 +455,26 @@ test('saved active tabs restore their tab id and URL', async t => {
t.after(() => socket.close())
})
+test('the views stay hidden while the app’s card is up, and the shown ones come back after it', t => {
+ const { manager, views } = fixture()
+ t.after(() => manager.dispose())
+ manager.create('a', { tabId: 'A' })
+ manager.create('a', { tabId: 'B' })
+ const rect = { left: 0, top: 0, width: 400, height: 300 }
+ manager.place('A', rect, true)
+ manager.cover(true)
+ assert.deepEqual(views.map(view => view.visible), [false, false])
+ // The page places its view again while the card is up: it still waits.
+ manager.place('B', rect, true)
+ assert.equal(views[1].visible, false)
+ manager.cover(false)
+ assert.deepEqual(views.map(view => view.visible), [true, true])
+ manager.place('A', rect, false)
+ manager.cover(true)
+ manager.cover(false)
+ assert.deepEqual(views.map(view => view.visible), [false, true])
+})
+
test('closing the active saved tab preserves the replacement after another page updates', async t => {
const directory = mkdtempSync(join(tmpdir(), 'bot-views-active-state-'))
const statePath = join(directory, 'bot-views.json')
diff --git a/app/test/main-close-card.test.mjs b/app/test/main-close-card.test.mjs
index 926d4eae..793e4dfd 100644
--- a/app/test/main-close-card.test.mjs
+++ b/app/test/main-close-card.test.mjs
@@ -14,22 +14,45 @@ await installHooks()
before(async () => { await startApp({ acknowledged: false }) })
-test('the first close asks on a card in the window and hides it once the card is answered', async () => {
+test('a page that does not show the card does not hold the close', async () => {
await waitFor(() => window() !== undefined, 'open the window')
await waitFor(() => state.tray !== undefined, 'build the tray')
hostState.release()
await handOff()
const win = window()
+ const silent = win.webContents.send
+ win.webContents.send = () => {}
+ try {
+ win.close()
+ await waitFor(() => win.visible === false, 'hide the window once the card is not shown in time', 5000)
+ } finally {
+ win.webContents.send = silent
+ }
+ assert.ok(!existsSync(join(paths.userData, 'tray-close-acknowledged')), 'the next close tells again')
+ assert.deepEqual(messageBoxes(), [], 'no message box')
+})
+
+test('the close asks on a card in the window and hides it once the card is answered', async () => {
+ const win = window()
+ trayMenu()[0].click()
+ await waitFor(() => win.visible === true, 'show the window')
+ // The window was pushed down behind another one: the close still asks where the user looks.
+ win.minimize()
+ const focused = win.focused
win.close()
await waitFor(() => windowCards(win).length === 1, 'tell about the tray on a card')
+ assert.equal(win.minimized, false, 'the window comes back up with its card')
+ assert.ok(win.focused > focused, 'the window with the card is brought to the front')
const card = windowCards(win)[0]
assert.match(card.message, /system tray/u)
assert.deepEqual(card.buttons, [{ label: 'OK', primary: true }])
assert.equal(card.cancel, undefined, 'only the answer lets the window go')
assert.equal(win.visible, true, 'the window stays until the answer')
- // A second close while the card is up asks nothing more.
+ // A second close while the card is up asks nothing more; it brings the card to the front.
+ const again = win.focused
win.close()
assert.equal(windowCards(win).length, 1)
+ assert.ok(win.focused > again, 'the second close brings the card forward')
answerCard(0, win)
await waitFor(() => win.visible === false, 'hide the window')
assert.ok(existsSync(join(paths.userData, 'tray-close-acknowledged')), 'the answer is kept')
diff --git a/docs/plans/2026-10-16-desktop-app.md b/docs/plans/2026-10-16-desktop-app.md
index 55d2374a..a12f608e 100644
--- a/docs/plans/2026-10-16-desktop-app.md
+++ b/docs/plans/2026-10-16-desktop-app.md
@@ -40,7 +40,7 @@
- 关掉窗口不是退出:窗口藏起来,引擎和 Bot 照常工作,Bot 浏览器的标签页也还在。再打开一次应用,窗口回到桌面上(单实例锁把第二次启动交给已经在跑的那一个)。
- 窗口真的不在了的时候(渲染进程没了之类),托盘的「打开」重新建一个窗口,接着现在跑着的引擎:地址还是引擎的本机地址,第一次加载换来的 cookie 还在,不用启动第二个引擎,也不用再用一次启动用的令牌。
- 所有窗口都关掉不会退出应用。托盘里的「退出」是唯一的正常退出入口。
-- 第一次关窗口时,窗口里出一张卡片(盖在页面上,不是系统对话框),说明应用会留在托盘里继续运行。只有点了卡片上的〔好〕窗口才藏起来;Esc 不关这张卡。这个确认记在应用自己的数据里,以后不再问。页面画不出卡片(没加载完、2 秒内没回话)时窗口照样藏进托盘,下次关窗口再说(待维护者确认)。
+- 第一次关窗口时,窗口里出一张卡片(盖在页面上,不是系统对话框),说明应用会留在托盘里继续运行。只有点了卡片上的〔好〕窗口才藏起来;Esc 不关这张卡。这个确认记在应用自己的数据里,以后不再问。页面画不出卡片(没加载完、2 秒内没回话)时窗口照样藏进托盘,下次关窗口再说(待维护者确认)。关窗口等着这张卡片的回答,所以卡片出来时窗口先回到最前(最小化的先还原),卡片还在时再点一次关闭也是把窗口带到最前;Bot 浏览器的视图画在页面上面,卡片在的时候先藏起来,免得把卡片挡住。
- 导入团队、搬数据位置的时候,关窗口是取消这些事,和以前一样:复制停在安全的地方,不留下半个团队。
- 这些时候窗口是真的关掉,不是藏起来:更新装好要重启、搬完数据要重启、启动失败、系统的关机和注销。
- macOS:点一下托盘图标出菜单,Dock 图标点一下窗口回来。全屏的窗口先退出全屏再藏起来,不然桌面上留下一块黑。