Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

feat(desktop): explore random port for IPv6 compat (#5311)

Shreyaseb2cc58dcab6
diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts
index 3392c2b4d..a34181a00 100644
--- a/packages/hoppscotch-common/src/components.d.ts
+++ b/packages/hoppscotch-common/src/components.d.ts
@@ -211,9 +211,7 @@ declare module 'vue' {
IconLucideArrowUpRight: typeof import('~icons/lucide/arrow-up-right')['default']
IconLucideBrush: typeof import('~icons/lucide/brush')['default']
IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default']
- IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default']
IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']
- IconLucideChevronUp: typeof import('~icons/lucide/chevron-up')['default']
IconLucideCircleCheck: typeof import('~icons/lucide/circle-check')['default']
IconLucideGlobe: typeof import('~icons/lucide/globe')['default']
IconLucideHelpCircle: typeof import('~icons/lucide/help-circle')['default']
@@ -223,6 +221,7 @@ declare module 'vue' {
IconLucideListEnd: typeof import('~icons/lucide/list-end')['default']
IconLucideMinus: typeof import('~icons/lucide/minus')['default']
IconLucidePlusCircle: typeof import('~icons/lucide/plus-circle')['default']
+ IconLucideRss: typeof import('~icons/lucide/rss')['default']
IconLucideSearch: typeof import('~icons/lucide/search')['default']
IconLucideTriangleAlert: typeof import('~icons/lucide/triangle-alert')['default']
IconLucideUsers: typeof import('~icons/lucide/users')['default']
diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.lock b/packages/hoppscotch-desktop/src-tauri/Cargo.lock
index 3289e06bf..6c06a5ab3 100644
--- a/packages/hoppscotch-desktop/src-tauri/Cargo.lock
+++ b/packages/hoppscotch-desktop/src-tauri/Cargo.lock
@@ -2222,7 +2222,7 @@ dependencies = [
"dirs 6.0.0",
"file-rotate",
"native-dialog",
- "portpicker",
+ "random-port",
"semver",
"serde",
"serde_json",
@@ -3151,6 +3151,18 @@ dependencies = [
"jni-sys",
]
+[[package]]
+name = "network-interface"
+version = "1.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4a43439bf756eed340bdf8feba761e2d50c7d47175d87545cd5cbe4a137c4d1"
+dependencies = [
+ "cc",
+ "libc",
+ "thiserror 1.0.69",
+ "winapi",
+]
+
[[package]]
name = "new_debug_unreachable"
version = "1.0.6"
@@ -3247,7 +3259,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56"
dependencies = [
- "proc-macro-crate 1.3.1",
+ "proc-macro-crate 3.3.0",
"proc-macro2",
"quote",
"syn 2.0.90",
@@ -3922,15 +3934,6 @@ dependencies = [
"windows-sys 0.59.0",
]
-[[package]]
-name = "portpicker"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9"
-dependencies = [
- "rand 0.8.5",
-]
-
[[package]]
name = "powerfmt"
version = "0.2.0"
@@ -4195,6 +4198,17 @@ dependencies = [
"rand_core 0.5.1",
]
+[[package]]
+name = "random-port"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d52b7d0e298a1b2f2f46c8d5da944c80ed1e5e6b032521cc44ee2b1dcbe2b94a"
+dependencies = [
+ "network-interface",
+ "rand 0.8.5",
+ "thiserror 1.0.69",
+]
+
[[package]]
name = "raw-window-handle"
version = "0.5.2"
diff --git a/packages/hoppscotch-desktop/src-tauri/Cargo.toml b/packages/hoppscotch-desktop/src-tauri/Cargo.toml
index d3dd515d1..2e5040035 100644
--- a/packages/hoppscotch-desktop/src-tauri/Cargo.toml
+++ b/packages/hoppscotch-desktop/src-tauri/Cargo.toml
@@ -33,7 +33,7 @@ tauri-plugin-appload = { git = "https://github.com/CuriousCorrelation/tauri-plug
tauri-plugin-relay = { git = "https://github.com/CuriousCorrelation/tauri-plugin-relay", rev = "0147ac1bb29d3b88d6652432a482bd86f0174506" }
axum = "0.8.1"
tower-http = { version = "0.6.2", features = ["cors"] }
-portpicker = "0.1.1"
+random-port = "0.1.1"
tokio = "1.43.0"
tauri-plugin-process = "2.2.0"
file-rotate = "0.8.0"
diff --git a/packages/hoppscotch-desktop/src-tauri/src/lib.rs b/packages/hoppscotch-desktop/src-tauri/src/lib.rs
index 00f9f18e9..572da8c2a 100644
--- a/packages/hoppscotch-desktop/src-tauri/src/lib.rs
+++ b/packages/hoppscotch-desktop/src-tauri/src/lib.rs
@@ -9,6 +9,8 @@ use tauri_plugin_appload::VendorConfigBuilder;
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_window_state::StateFlags;
+use random_port::{PortPicker, Protocol};
+
pub const HOPPSCOTCH_DESKTOP_IDENTIFIER: &'static str = "io.hoppscotch.desktop";
static SERVER_PORT: OnceLock<u16> = OnceLock::new();
@@ -40,7 +42,11 @@ fn quit_app(app: tauri::AppHandle) -> Result<(), String> {
pub fn run() {
tauri::Builder::default()
.setup(|app| {
- let server_port = portpicker::pick_unused_port().expect("Cannot find unused port");
+ let server_port: u16 = PortPicker::new()
+ .protocol(Protocol::Tcp)
+ .port_range(15000..=25000)
+ .pick()
+ .expect("Cannot find unused port");
tracing::info!("Selected server port: {}", server_port);
SERVER_PORT
.set(server_port)