Skip to content

Fix: Add CLI port override and dynamic fallback to avoid conflicts on Windows #1746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ http-cache-reqwest = "0.15.0"
reqwest = { version = "=0.12.12", features = ["blocking", "multipart", "json"] }
reqwest-middleware = "0.4.1"

clap = {version = "4.0",features = ["derive"]}
rocket = "0.5.0-rc.2"


[patch.crates-io]
# enables chinese mirror (hf is banned in china) and native-tls
Expand Down
35 changes: 35 additions & 0 deletions screenpipe-server/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use clap::Parser;
use std::net::TcpListener;

use std::{path::PathBuf, sync::Arc};

use clap::{Parser, Subcommand, ValueHint};
Expand All @@ -9,6 +12,38 @@ use clap::ValueEnum;
use screenpipe_core::Language;
use screenpipe_db::OcrEngine as DBOcrEngine;
use screenpipe_db::CustomOcrConfig as DBCustomOcrConfig;

#[derive(Parser)]
#[command(name = "Screenpipe Server",about = "Launch Screenpipe with optional custom port")]
struct Args {
// Port to run the server on
#[arg(short, long, default_value_t = 3030)]
port: u16,
}
fn
find_available_port(start_port:u16) -> u16{
for port in
start_port..start_port + 50 {
if
TcpListener::bind(("127.0.0.1",port)).is_ok(){
return port;
}
}
panic!("No available port found in range!");
}
fn main(){
let args = Args::parse();
let port = if
TcpListener::bind(("127.0.0.1",args.port)).is_ok(){
args.port
}else{
find_available_port(3030)
};

println!("Starting Screenpipe on port {}",port);
}


#[derive(Clone, Debug, ValueEnum, PartialEq)]
pub enum CliAudioTranscriptionEngine {
#[clap(name = "deepgram")]
Expand Down