feat: refine download UX and native host flow
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
EXTENSION_ID="${1:-alaohbbicffclloghmknhlmfdbobcigc}"
|
||||
EXTENSION_ID="${1:-makoclohjdpempbndoaljeadpngefhcf}"
|
||||
HOST_NAME="org.gdown.nativehost"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
RUNNER_PATH="$SCRIPT_DIR/.runtime/run-host-macos.sh"
|
||||
|
||||
Reference in New Issue
Block a user