@triflux/remote 10.35.0 → 10.35.2
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.
- package/hub/mac-tray.swift +11 -0
- package/hub/server.mjs +2 -2
- package/hub/tray.mjs +15 -1
- package/package.json +1 -1
package/hub/mac-tray.swift
CHANGED
|
@@ -47,6 +47,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate {
|
|
|
47
47
|
class WebViewController: NSViewController, WKNavigationDelegate, WKScriptMessageHandler {
|
|
48
48
|
var webView: WKWebView!
|
|
49
49
|
var port: String = "27888"
|
|
50
|
+
let canonicalPort = "27888"
|
|
51
|
+
var consecutiveFailures = 0
|
|
50
52
|
var retryWorkItem: DispatchWorkItem?
|
|
51
53
|
var onFocusComplete: (() -> Void)?
|
|
52
54
|
|
|
@@ -101,6 +103,14 @@ class WebViewController: NSViewController, WKNavigationDelegate, WKScriptMessage
|
|
|
101
103
|
|
|
102
104
|
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
|
103
105
|
logError("Failed to load: \(error.localizedDescription)")
|
|
106
|
+
consecutiveFailures += 1
|
|
107
|
+
if consecutiveFailures >= 3 && port != canonicalPort {
|
|
108
|
+
port = canonicalPort
|
|
109
|
+
consecutiveFailures = 0
|
|
110
|
+
logError("Switching to canonical port \(canonicalPort) after repeated failures")
|
|
111
|
+
loadTray()
|
|
112
|
+
return
|
|
113
|
+
}
|
|
104
114
|
let retry = DispatchWorkItem { [weak self] in
|
|
105
115
|
self?.loadTray()
|
|
106
116
|
}
|
|
@@ -111,6 +121,7 @@ class WebViewController: NSViewController, WKNavigationDelegate, WKScriptMessage
|
|
|
111
121
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
112
122
|
retryWorkItem?.cancel()
|
|
113
123
|
retryWorkItem = nil
|
|
124
|
+
consecutiveFailures = 0
|
|
114
125
|
logError("Successfully loaded URL")
|
|
115
126
|
}
|
|
116
127
|
|
package/hub/server.mjs
CHANGED
|
@@ -517,7 +517,7 @@ function getRequestPath(url = "/") {
|
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
-
function isLoopbackRemoteAddress(remoteAddress) {
|
|
520
|
+
export function isLoopbackRemoteAddress(remoteAddress) {
|
|
521
521
|
return (
|
|
522
522
|
typeof remoteAddress === "string" &&
|
|
523
523
|
LOOPBACK_REMOTE_ADDRESSES.has(remoteAddress)
|
|
@@ -563,7 +563,7 @@ function safeTokenCompare(a, b) {
|
|
|
563
563
|
return timingSafeEqual(ha, hb);
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
function isAuthorizedRequest(req, path, hubToken) {
|
|
566
|
+
export function isAuthorizedRequest(req, path, hubToken) {
|
|
567
567
|
if (!hubToken) {
|
|
568
568
|
return isLoopbackRemoteAddress(req.socket.remoteAddress);
|
|
569
569
|
}
|
package/hub/tray.mjs
CHANGED
|
@@ -9,12 +9,26 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
10
|
import { dirname, join, resolve } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { resolveHubPortForContext } from "./hub-lifecycle.mjs";
|
|
12
13
|
import { IS_MAC, IS_WINDOWS } from "@triflux/core/hub/platform.mjs";
|
|
13
14
|
import { ensureHubForTray } from "./tray-lifecycle.mjs";
|
|
14
15
|
|
|
15
16
|
const HUB_PID_FILE = join(homedir(), ".claude", "cache", "tfx-hub", "hub.pid");
|
|
16
17
|
const DEFAULT_HUB_PORT = "27888";
|
|
17
18
|
|
|
19
|
+
export function resolveTrayHubPort({
|
|
20
|
+
env = process.env,
|
|
21
|
+
cwd = process.cwd(),
|
|
22
|
+
} = {}) {
|
|
23
|
+
return String(
|
|
24
|
+
resolveHubPortForContext({
|
|
25
|
+
env,
|
|
26
|
+
cwd,
|
|
27
|
+
defaultPort: Number(DEFAULT_HUB_PORT),
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
function sleep(ms) {
|
|
19
33
|
return new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
|
|
20
34
|
}
|
|
@@ -416,7 +430,7 @@ async function shutdown(reason = "shutdown") {
|
|
|
416
430
|
export async function startTray() {
|
|
417
431
|
if (IS_MAC) {
|
|
418
432
|
const trayScript = fileURLToPath(import.meta.url);
|
|
419
|
-
const port =
|
|
433
|
+
const port = resolveTrayHubPort();
|
|
420
434
|
const serverPath = join(dirname(trayScript), "server.mjs");
|
|
421
435
|
await ensureHubForTray({ port, serverPath });
|
|
422
436
|
const reaped = reapExistingMacTrayProcesses({ scriptPath: trayScript });
|