feat: refine download UX and native host flow

This commit is contained in:
tongki078
2026-02-25 11:12:23 +09:00
parent 34f63acf49
commit d85fdc1101
12 changed files with 474 additions and 72 deletions

View File

@@ -1,4 +1,3 @@
import { execFile } from 'node:child_process'
import { appendFile, mkdir } from 'node:fs/promises'
import { homedir } from 'node:os'
import { dirname, join } from 'node:path'
@@ -45,40 +44,7 @@ async function enqueueExternalAdd(payload) {
}
function focusGdownApp() {
return new Promise((resolve) => {
if (process.platform !== 'darwin') {
resolve({ ok: true, note: 'focus noop on non-macos in step1 host' })
return
}
const attempts = [
['osascript', ['-e', 'tell application id "com.tauri.dev" to activate']],
['osascript', ['-e', 'tell application "gdown" to activate']],
['osascript', ['-e', 'tell application "System Events" to set frontmost of first process whose name is "gdown" to true']],
['osascript', ['-e', 'tell application "System Events" to set frontmost of first process whose name is "Gdown" to true']],
['osascript', ['-e', 'tell application "System Events" to set frontmost of first process whose name is "app" to true']],
['open', ['-b', 'com.tauri.dev']],
['open', ['-a', 'gdown']],
]
const run = (index) => {
if (index >= attempts.length) {
resolve({ ok: false, message: 'all focus strategies failed' })
return
}
const [bin, args] = attempts[index]
execFile(bin, args, (error) => {
if (!error) {
resolve({ ok: true, strategy: `${bin} ${args.join(' ')}` })
return
}
run(index + 1)
})
}
run(0)
})
return Promise.resolve({ ok: true, note: 'focus disabled by design' })
}
async function handleRequest(message) {
@@ -119,7 +85,6 @@ async function handleRequest(message) {
proxy: proxy || undefined,
split: Number.isFinite(split) && split > 0 ? Math.round(split) : undefined,
})
await focusGdownApp()
return {
ok: true,