A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Ask where a download from the app window goes
Fei24113282b12dbd0c
diff --git a/app/src/downloads.mjs b/app/src/downloads.mjsnew file mode 100644index 00000000..094fdef6--- /dev/null+++ b/app/src/downloads.mjs@@ -0,0 +1,13 @@+// A file the main window downloads asks where it should go first. Downloads from+// any other contents (the sign-in child, a Bot browser guest) keep their own+// session's rules.+import { join } from 'node:path'++export function downloadSaver({ window, dialog, downloads }) {+ return (event, item, source) => {+ if (source !== window.webContents) return+ const file = dialog.showSaveDialogSync(window, { defaultPath: join(downloads, item.getFilename()) })+ if (file === undefined) event.preventDefault()+ else item.setSavePath(file)+ }+}diff --git a/app/src/main.mjs b/app/src/main.mjsindex 92482a00..628f1a88 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -14,6 +14,7 @@ import { BotBrowserGuests, partitionOf } from './bot-browser.mjs'import { importFromBrowser, listSources } from './browser-sources.mjs'import { applyCookies, CookieImports } from './cookie-import.mjs'import { parseCookieFile } from './cookie-parse.mjs'+import { downloadSaver } from './downloads.mjs'import { canonicalExecPath } from './canonical-path.mjs'import { chooseLocations, localeText, programFolder, saveLocations, text } from './first-run.mjs'import { hostPort } from './host-port.mjs'@@ -448,6 +449,7 @@ function createWindow() {mainWindow.on('closed', () => { mainWindow = undefined })browserGuests.bind(mainWindow)const contents = mainWindow.webContents+ contents.session.on('will-download', downloadSaver({ window: mainWindow, dialog, downloads: app.getPath('downloads') }))if (win32) {// Fullscreen hides the caption buttons, and the page drops its band meanwhile. A reload// registers the page's listener again, so the state goes out after every load too.diff --git a/app/test/downloads.test.mjs b/app/test/downloads.test.mjsnew file mode 100644index 00000000..909a0e35--- /dev/null+++ b/app/test/downloads.test.mjs@@ -0,0 +1,53 @@+// The main window's will-download handler: a system save dialog picks the path,+// a cancelled dialog drops the download, other contents' downloads pass through.+import assert from 'node:assert/strict'+import test from 'node:test'+import { downloadSaver } from '../src/downloads.mjs'++const item = () => ({ getFilename: () => 'chart.png', path: undefined, setSavePath(path) { this.path = path } })+const event = () => ({ prevented: false, preventDefault() { this.prevented = true } })++test('a download from the main window asks for a path and saves there', () => {+ const contents = {}+ const window = { webContents: contents }+ const calls = []+ const save = downloadSaver({+ window,+ dialog: { showSaveDialogSync: (win, options) => { calls.push({ win, options }); return '/picked/chart.png' } },+ downloads: '/downloads',+ })+ const ev = event()+ const download = item()+ save(ev, download, contents)+ assert.equal(download.path, '/picked/chart.png')+ assert.equal(ev.prevented, false)+ assert.equal(calls.length, 1)+ assert.equal(calls[0].win, window)+ assert.match(calls[0].options.defaultPath, /chart\.png$/)+ assert.ok(calls[0].options.defaultPath.includes('downloads'), 'the dialog starts in the downloads folder')+})++test('a cancelled dialog drops the download', () => {+ const contents = {}+ const save = downloadSaver({ window: { webContents: contents }, dialog: { showSaveDialogSync: () => undefined }, downloads: '/downloads' })+ const ev = event()+ const download = item()+ save(ev, download, contents)+ assert.equal(ev.prevented, true)+ assert.equal(download.path, undefined)+})++test('a download from another contents passes through', () => {+ let asked = false+ const save = downloadSaver({+ window: { webContents: {} },+ dialog: { showSaveDialogSync: () => { asked = true; return '/picked' } },+ downloads: '/downloads',+ })+ const ev = event()+ const download = item()+ save(ev, download, { other: true })+ assert.equal(asked, false)+ assert.equal(download.path, undefined)+ assert.equal(ev.prevented, false)+})