mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 21:03:01 -03:00
Compare commits
13 Commits
v3.8.1
...
feat/LBX-4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46154fa49a | ||
|
|
aae35b591d | ||
|
|
7293afb618 | ||
|
|
194e7918ca | ||
|
|
979958aca6 | ||
|
|
6e92e0f79f | ||
|
|
aef069d4c7 | ||
|
|
1f447cc478 | ||
|
|
5d2dc3616c | ||
|
|
1f9972f74e | ||
|
|
3344f68408 | ||
|
|
65be11cc07 | ||
|
|
96140e614c |
1
.github/workflows/build-renderer.yml
vendored
1
.github/workflows/build-renderer.yml
vendored
@@ -42,6 +42,7 @@ jobs:
|
||||
run: yarn build
|
||||
env:
|
||||
RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.EXTERNAL_RESOURCES_URL }}
|
||||
RENDERER_VITE_SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
||||
|
||||
- name: Deploy to Cloudflare Pages
|
||||
env:
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
"@primer/octicons-react": "^19.9.0",
|
||||
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
||||
"@reduxjs/toolkit": "^2.2.3",
|
||||
"@sentry/react": "^10.33.0",
|
||||
"@tiptap/extension-bold": "^3.6.2",
|
||||
"@tiptap/extension-italic": "^3.6.2",
|
||||
"@tiptap/extension-link": "^3.6.2",
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
from flask import Flask, request, jsonify
|
||||
import sys, json, urllib.parse, psutil
|
||||
import sys, json, urllib.parse, psutil, socket
|
||||
from torrent_downloader import TorrentDownloader
|
||||
from http_downloader import HttpDownloader
|
||||
from profile_image_processor import ProfileImageProcessor
|
||||
import libtorrent as lt
|
||||
|
||||
RPC_PORT_MIN = 8080
|
||||
RPC_PORT_MAX = 9000
|
||||
|
||||
def find_available_port(preferred_port, start=RPC_PORT_MIN, end=RPC_PORT_MAX):
|
||||
"""Find an available port, trying the preferred port first."""
|
||||
# Try preferred port first
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind(('0.0.0.0', preferred_port))
|
||||
return preferred_port
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Try ports in range
|
||||
for port in range(start, end + 1):
|
||||
if port == preferred_port:
|
||||
continue
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind(('0.0.0.0', port))
|
||||
return port
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
raise RuntimeError(f"No available ports in range {start}-{end}")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Retrieve command line arguments
|
||||
@@ -192,4 +218,7 @@ def action():
|
||||
return "", 200
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=int(http_port))
|
||||
actual_port = find_available_port(int(http_port))
|
||||
# Print port for Node.js to capture - must be flushed immediately
|
||||
print(f"RPC_PORT:{actual_port}", flush=True)
|
||||
app.run(host="0.0.0.0", port=actual_port)
|
||||
|
||||
@@ -25,7 +25,7 @@ const getLibrary = async (): Promise<LibraryGame[]> => {
|
||||
const achievements = await gameAchievementsSublevel.get(key);
|
||||
|
||||
unlockedAchievementCount =
|
||||
achievements?.unlockedAchievements.length ?? 0;
|
||||
achievements?.unlockedAchievements?.length ?? 0;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -27,11 +27,19 @@ const binaryNameByPlatform: Partial<Record<NodeJS.Platform, string>> = {
|
||||
win32: "hydra-python-rpc.exe",
|
||||
};
|
||||
|
||||
const RPC_PORT_PREFIX = "RPC_PORT:";
|
||||
const PORT_DISCOVERY_TIMEOUT_MS = 30000;
|
||||
const HEALTH_CHECK_INTERVAL_MS = 100;
|
||||
const HEALTH_CHECK_TIMEOUT_MS = 10000;
|
||||
|
||||
export class PythonRPC {
|
||||
public static readonly BITTORRENT_PORT = "5881";
|
||||
public static readonly RPC_PORT = "8084";
|
||||
public static readonly DEFAULT_RPC_PORT = "8084";
|
||||
|
||||
private static currentPort: string = this.DEFAULT_RPC_PORT;
|
||||
|
||||
public static readonly rpc = axios.create({
|
||||
baseURL: `http://localhost:${this.RPC_PORT}`,
|
||||
baseURL: `http://localhost:${this.DEFAULT_RPC_PORT}`,
|
||||
httpAgent: new http.Agent({
|
||||
family: 4, // Force IPv4
|
||||
}),
|
||||
@@ -62,6 +70,102 @@ export class PythonRPC {
|
||||
return newPassword;
|
||||
}
|
||||
|
||||
private static updateBaseURL(port: string) {
|
||||
this.currentPort = port;
|
||||
this.rpc.defaults.baseURL = `http://localhost:${port}`;
|
||||
pythonRpcLogger.log(`RPC baseURL updated to port ${port}`);
|
||||
}
|
||||
|
||||
private static parsePortFromStdout(data: string): string | null {
|
||||
const lines = data.split("\n");
|
||||
for (const line of lines) {
|
||||
if (line.startsWith(RPC_PORT_PREFIX)) {
|
||||
return line.slice(RPC_PORT_PREFIX.length).trim();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static async waitForHealthCheck(): Promise<void> {
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < HEALTH_CHECK_TIMEOUT_MS) {
|
||||
try {
|
||||
const response = await this.rpc.get("/healthcheck", { timeout: 1000 });
|
||||
if (response.status === 200) {
|
||||
pythonRpcLogger.log("RPC health check passed");
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Server not ready yet, continue polling
|
||||
}
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, HEALTH_CHECK_INTERVAL_MS)
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error("RPC health check timed out");
|
||||
}
|
||||
|
||||
private static waitForPort(
|
||||
childProcess: cp.ChildProcess
|
||||
): Promise<string | null> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let resolved = false;
|
||||
let stdoutBuffer = "";
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
reject(
|
||||
new Error(
|
||||
`Port discovery timed out after ${PORT_DISCOVERY_TIMEOUT_MS}ms`
|
||||
)
|
||||
);
|
||||
}
|
||||
}, PORT_DISCOVERY_TIMEOUT_MS);
|
||||
|
||||
const cleanup = () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
|
||||
if (childProcess.stdout) {
|
||||
childProcess.stdout.setEncoding("utf-8");
|
||||
childProcess.stdout.on("data", (data: string) => {
|
||||
stdoutBuffer += data;
|
||||
pythonRpcLogger.log(data);
|
||||
|
||||
const port = this.parsePortFromStdout(stdoutBuffer);
|
||||
if (port && !resolved) {
|
||||
resolved = true;
|
||||
cleanup();
|
||||
resolve(port);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
childProcess.on("error", (err) => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
cleanup();
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
childProcess.on("exit", (code) => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
cleanup();
|
||||
if (code === 0) {
|
||||
resolve(null);
|
||||
} else {
|
||||
reject(new Error(`Python RPC process exited with code ${code}`));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static async spawn(
|
||||
initialDownload?: GamePayload,
|
||||
initialSeeding?: GamePayload[]
|
||||
@@ -70,12 +174,14 @@ export class PythonRPC {
|
||||
|
||||
const commonArgs = [
|
||||
this.BITTORRENT_PORT,
|
||||
this.RPC_PORT,
|
||||
this.DEFAULT_RPC_PORT,
|
||||
rpcPassword,
|
||||
initialDownload ? JSON.stringify(initialDownload) : "",
|
||||
initialSeeding ? JSON.stringify(initialSeeding) : "",
|
||||
];
|
||||
|
||||
let childProcess: cp.ChildProcess;
|
||||
|
||||
if (app.isPackaged) {
|
||||
const binaryName = binaryNameByPlatform[process.platform]!;
|
||||
const binaryPath = path.join(
|
||||
@@ -91,16 +197,13 @@ export class PythonRPC {
|
||||
);
|
||||
|
||||
app.quit();
|
||||
return;
|
||||
}
|
||||
|
||||
const childProcess = cp.spawn(binaryPath, commonArgs, {
|
||||
childProcess = cp.spawn(binaryPath, commonArgs, {
|
||||
windowsHide: true,
|
||||
stdio: ["inherit", "inherit"],
|
||||
stdio: ["inherit", "pipe", "pipe"],
|
||||
});
|
||||
|
||||
this.logStderr(childProcess.stderr);
|
||||
|
||||
this.pythonProcess = childProcess;
|
||||
} else {
|
||||
const scriptPath = path.join(
|
||||
__dirname,
|
||||
@@ -110,16 +213,44 @@ export class PythonRPC {
|
||||
"main.py"
|
||||
);
|
||||
|
||||
const childProcess = cp.spawn("python", [scriptPath, ...commonArgs], {
|
||||
stdio: ["inherit", "inherit"],
|
||||
childProcess = cp.spawn("python", [scriptPath, ...commonArgs], {
|
||||
stdio: ["inherit", "pipe", "pipe"],
|
||||
});
|
||||
|
||||
this.logStderr(childProcess.stderr);
|
||||
|
||||
this.pythonProcess = childProcess;
|
||||
}
|
||||
|
||||
this.rpc.defaults.headers.common["x-hydra-rpc-password"] = rpcPassword;
|
||||
this.logStderr(childProcess.stderr);
|
||||
this.pythonProcess = childProcess;
|
||||
|
||||
try {
|
||||
const port = await this.waitForPort(childProcess);
|
||||
|
||||
if (port) {
|
||||
this.updateBaseURL(port);
|
||||
} else {
|
||||
pythonRpcLogger.log(
|
||||
`No port received, using default port ${this.DEFAULT_RPC_PORT}`
|
||||
);
|
||||
this.updateBaseURL(this.DEFAULT_RPC_PORT);
|
||||
}
|
||||
|
||||
this.rpc.defaults.headers.common["x-hydra-rpc-password"] = rpcPassword;
|
||||
|
||||
await this.waitForHealthCheck();
|
||||
|
||||
pythonRpcLogger.log(
|
||||
`Python RPC started successfully on port ${this.currentPort}`
|
||||
);
|
||||
} catch (err) {
|
||||
pythonRpcLogger.log(`Failed to start Python RPC: ${err}`);
|
||||
|
||||
dialog.showErrorBox(
|
||||
"RPC Error",
|
||||
`Failed to start download service. ${err instanceof Error ? err.message : String(err)}\n\nPlease ensure no other application is using ports 8080-9000 and try restarting Hydra.`
|
||||
);
|
||||
|
||||
this.kill();
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
public static kill() {
|
||||
|
||||
@@ -138,12 +138,21 @@ export class WindowManager {
|
||||
(details, callback) => {
|
||||
if (
|
||||
details.webContentsId !== this.mainWindow?.webContents.id ||
|
||||
details.url.includes("chatwoot") ||
|
||||
details.url.includes("workwonders")
|
||||
details.url.includes("chatwoot")
|
||||
) {
|
||||
return callback(details);
|
||||
}
|
||||
|
||||
if (details.url.includes("workwonders")) {
|
||||
return callback({
|
||||
...details,
|
||||
requestHeaders: {
|
||||
Origin: "https://workwonders.app",
|
||||
...details.requestHeaders,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const userAgent = new UserAgent();
|
||||
|
||||
callback({
|
||||
|
||||
@@ -134,7 +134,10 @@ export function App() {
|
||||
|
||||
await workwondersRef.current.initChangelogWidget();
|
||||
workwondersRef.current.initChangelogWidgetMini();
|
||||
workwondersRef.current.initFeedbackWidget();
|
||||
|
||||
if (token) {
|
||||
workwondersRef.current.initFeedbackWidget();
|
||||
}
|
||||
},
|
||||
[workwondersRef]
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ import resources from "@locales";
|
||||
|
||||
import { logger } from "./logger";
|
||||
import { addCookieInterceptor } from "./cookies";
|
||||
import * as Sentry from "@sentry/react";
|
||||
import { levelDBService } from "./services/leveldb.service";
|
||||
import Catalogue from "./pages/catalogue/catalogue";
|
||||
import Home from "./pages/home/home";
|
||||
@@ -36,6 +37,18 @@ import { AchievementNotification } from "./pages/achievements/notification/achie
|
||||
|
||||
console.log = logger.log;
|
||||
|
||||
Sentry.init({
|
||||
dsn: import.meta.env.RENDERER_VITE_SENTRY_DSN,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration(),
|
||||
Sentry.replayIntegration(),
|
||||
],
|
||||
tracesSampleRate: 0.5,
|
||||
replaysSessionSampleRate: 0,
|
||||
replaysOnErrorSampleRate: 0,
|
||||
release: "hydra-launcher@" + (await window.electron.getVersion()),
|
||||
});
|
||||
|
||||
const isStaging = await window.electron.isStaging();
|
||||
addCookieInterceptor(isStaging);
|
||||
|
||||
|
||||
54
yarn.lock
54
yarn.lock
@@ -2174,6 +2174,60 @@
|
||||
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.52.4.tgz#5b2dd648a960b8fa00d76f2cc4eea2f03daa80f4"
|
||||
integrity sha512-bf9PtUa0u8IXDVxzRToFQKsNCRz9qLYfR/MpECxl4mRoWYjAeFjgxj1XdZr2M/GNVpT05p+LgQOHopYDlUu6/w==
|
||||
|
||||
"@sentry-internal/browser-utils@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry-internal/browser-utils/-/browser-utils-10.33.0.tgz#4a5d98352267b63fcc449efe14627c0fc082089e"
|
||||
integrity sha512-nDJFHAfiFifBfJB0OF6DV6BIsIV5uah4lDsV4UBAgPBf+YAHclO10y1gi2U/JMh58c+s4lXi9p+PI1TFXZ0c6w==
|
||||
dependencies:
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sentry-internal/feedback@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-10.33.0.tgz#5865b4a68d607bb48d8159a100464ae640a638e7"
|
||||
integrity sha512-sN/VLWtEf0BeV6w6wldIpTxUQxNVc9o9tjLRQa8je1ZV2FCgXA124Iff/zsowsz82dLqtg7qp6GA5zYXVq+JMA==
|
||||
dependencies:
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sentry-internal/replay-canvas@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-10.33.0.tgz#9ea15b320618ad220e5d8f7c804a0d9ca55b04af"
|
||||
integrity sha512-MTmP6uoAVzw4CCPeqCgCLsRSiOfGLxgyMFjGTCW3E7t62MJ9S0H5sLsQ34sHxXUa1gFU9UNAjEvRRpZ0JvWrPw==
|
||||
dependencies:
|
||||
"@sentry-internal/replay" "10.33.0"
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sentry-internal/replay@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry-internal/replay/-/replay-10.33.0.tgz#8cfe3a353731fcd81e7afb646b6befeb0f9feb0f"
|
||||
integrity sha512-UOU9PYxuXnPop3HoQ3l4Q7SZUXJC3Vmfm0Adgad8U03UcrThWIHYc5CxECSrVzfDFNOT7w9o7HQgRAgWxBPMXg==
|
||||
dependencies:
|
||||
"@sentry-internal/browser-utils" "10.33.0"
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sentry/browser@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-10.33.0.tgz#33284952a1cdf43cdac15ac144c85e81e7cbaa93"
|
||||
integrity sha512-iWiPjik9zetM84jKfk01UveW1J0+X7w8XmJ8+IrhTyNDBVUWCRJWD8FrksiN1dRSg5mFWgfMRzKMz27hAScRwg==
|
||||
dependencies:
|
||||
"@sentry-internal/browser-utils" "10.33.0"
|
||||
"@sentry-internal/feedback" "10.33.0"
|
||||
"@sentry-internal/replay" "10.33.0"
|
||||
"@sentry-internal/replay-canvas" "10.33.0"
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sentry/core@10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-10.33.0.tgz#ea4964fbec290503b419ccaf1a313924d30ad1c8"
|
||||
integrity sha512-ehH1VSUclIHZKEZVdv+klofsFIh8FFzqA6AAV23RtLepptzA8wqQzUGraEuSN25sYcNmYJ0jti5U0Ys+WZv5Dw==
|
||||
|
||||
"@sentry/react@^10.33.0":
|
||||
version "10.33.0"
|
||||
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-10.33.0.tgz#89a3be88d43e49de90943ad2ac86ee1664048097"
|
||||
integrity sha512-iMdC2Iw54ibAccatJ5TjoLlIy3VotFteied7JFvOudgj1/2eBBeWthRobZ5p6/nAOpj4p9vJk0DeLrc012sd2g==
|
||||
dependencies:
|
||||
"@sentry/browser" "10.33.0"
|
||||
"@sentry/core" "10.33.0"
|
||||
|
||||
"@sindresorhus/is@^4.0.0":
|
||||
version "4.6.0"
|
||||
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f"
|
||||
|
||||
Reference in New Issue
Block a user