@quicktvui/web-cli 1.0.0-beta.38 → 1.0.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/qt-web-cli.js +60 -0
  2. package/package.json +1 -1
package/bin/qt-web-cli.js CHANGED
@@ -119,6 +119,9 @@ async function main() {
119
119
 
120
120
  // 入口候选列表
121
121
  const entryCandidates = [
122
+ { name: 'webMain (package.json)', path: pkg.webMain, type: 'web' },
123
+ { name: 'src/main-web.ts', path: './src/main-web.ts', type: 'web' },
124
+ { name: 'src/main-web.js', path: './src/main-web.js', type: 'web' },
122
125
  { name: 'src/main-native.ts', path: './src/main-native.ts', type: 'package' },
123
126
  { name: 'src/main-native.js', path: './src/main-native.js', type: 'package' },
124
127
  { name: 'src/main.ts', path: './src/main.ts', type: 'package' },
@@ -139,6 +142,8 @@ async function main() {
139
142
 
140
143
  if (!mainEntry) {
141
144
  signale.error('无法找到有效的入口文件,请检查以下路径:')
145
+ signale.error(' - package.json 中的 webMain 字段')
146
+ signale.error(' - src/main-web.ts 或 src/main-web.js')
142
147
  signale.error(' - src/main-native.ts 或 src/main-native.js')
143
148
  signale.error(' - src/main.ts 或 src/main.js')
144
149
  signale.error(' - package.json 中的 main 字段')
@@ -252,6 +257,10 @@ function waitForServer(url, timeout = 30000) {
252
257
  */
253
258
  function openBrowser(url) {
254
259
  const platform = process.platform
260
+ if (platform === 'darwin' && focusExistingBrowserPage(url)) {
261
+ signale.success('已切换到已打开的浏览器页面')
262
+ return
263
+ }
255
264
  const command =
256
265
  platform === 'darwin'
257
266
  ? `open "${url}"`
@@ -268,6 +277,57 @@ function openBrowser(url) {
268
277
  signale.warn(`自动打开浏览器失败,请手动访问: ${url}`)
269
278
  }
270
279
 
280
+ function focusExistingBrowserPage(url) {
281
+ const match = /^https?:\/\/[^/]+/.exec(url)
282
+ const targetPrefix = match ? match[0] : url
283
+ const browserApps = ['Google Chrome', 'Safari', 'Arc', 'Microsoft Edge', 'Brave Browser']
284
+ const script = `
285
+ set targetPrefix to "${escapeAppleScriptString(targetPrefix)}"
286
+ set browserApps to {${browserApps.map((app) => `"${escapeAppleScriptString(app)}"`).join(', ')}}
287
+ repeat with appName in browserApps
288
+ tell application "System Events"
289
+ set isRunning to (name of processes) contains (appName as text)
290
+ end tell
291
+ if isRunning then
292
+ if (appName as text) is "Safari" then
293
+ tell application "Safari"
294
+ repeat with w in windows
295
+ repeat with t in tabs of w
296
+ if URL of t starts with targetPrefix then
297
+ set current tab of w to t
298
+ set index of w to 1
299
+ activate
300
+ return "FOUND"
301
+ end if
302
+ end repeat
303
+ end repeat
304
+ end tell
305
+ else
306
+ tell application (appName as text)
307
+ repeat with w in windows
308
+ repeat with t in tabs of w
309
+ if URL of t starts with targetPrefix then
310
+ set active tab index of w to (index of t)
311
+ set index of w to 1
312
+ activate
313
+ return "FOUND"
314
+ end if
315
+ end repeat
316
+ end repeat
317
+ end tell
318
+ end if
319
+ end if
320
+ end repeat
321
+ return "NOT_FOUND"
322
+ `.trim()
323
+ const result = exec(`osascript <<'APPLESCRIPT'\n${script}\nAPPLESCRIPT`, { silent: true })
324
+ return result.code === 0 && String(result.stdout || '').includes('FOUND')
325
+ }
326
+
327
+ function escapeAppleScriptString(value) {
328
+ return String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"')
329
+ }
330
+
271
331
  function findProjectRoot(startDir = process.cwd()) {
272
332
  let currentDir = startDir
273
333
  while (currentDir !== path.dirname(currentDir)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quicktvui/web-cli",
3
- "version": "1.0.0-beta.38",
3
+ "version": "1.0.0-beta.39",
4
4
  "description": "CLI tool for QuickTVUI web development - zero configuration",
5
5
  "author": "QuickTVUI Team",
6
6
  "license": "Apache-2.0",