Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

chore: Separate configuration for android build in release mode

Vanalite21d0943aa43b
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 55067d98d..085cf278f 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -91,3 +91,11 @@ windows-sys = { version = "0.60.2", features = ["Win32_Storage_FileSystem"] }
tauri-plugin-updater = "2"
once_cell = "1.18"
tauri-plugin-single-instance = { version = "2.0.0", features = ["deep-link"] }
+
+# Release profile optimizations for minimal binary size
+[profile.release]
+opt-level = "z" # Optimize for size
+lto = true # Enable Link Time Optimization
+strip = true # Strip symbols for smaller binary
+codegen-units = 1 # Reduce parallel codegen for better optimization
+panic = "abort" # Don't unwind on panic, saves space
diff --git a/src-tauri/src/core/server/commands.rs b/src-tauri/src/core/server/commands.rs
index 85450bee5..286d40cc1 100644
--- a/src-tauri/src/core/server/commands.rs
+++ b/src-tauri/src/core/server/commands.rs
@@ -14,12 +14,12 @@ pub async fn start_server<R: Runtime>(
api_key: String,
trusted_hosts: Vec<String>,
proxy_timeout: u64,
-) -> Result<bool, String> {
+) -> Result<u16, String> {
let server_handle = state.server_handle.clone();
let plugin_state: State<LlamacppState> = app_handle.state();
let sessions = plugin_state.llama_server_process.clone();
- proxy::start_server(
+ let actual_port = proxy::start_server(
server_handle,
sessions,
host,
@@ -31,7 +31,7 @@ pub async fn start_server<R: Runtime>(
)
.await
.map_err(|e| e.to_string())?;
- Ok(true)
+ Ok(actual_port)
}
#[tauri::command]
diff --git a/src-tauri/src/core/server/proxy.rs b/src-tauri/src/core/server/proxy.rs
index 9b33d4ba5..74961790f 100644
--- a/src-tauri/src/core/server/proxy.rs
+++ b/src-tauri/src/core/server/proxy.rs
@@ -632,7 +632,7 @@ pub async fn start_server(
proxy_api_key: String,
trusted_hosts: Vec<Vec<String>>,
proxy_timeout: u64,
-) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
+) -> Result<u16, Box<dyn std::error::Error + Send + Sync>> {
let mut handle_guard = server_handle.lock().await;
if handle_guard.is_some() {
return Err("Server is already running".into());
@@ -667,7 +667,8 @@ pub async fn start_server(
});
let server = Server::bind(&addr).serve(make_svc);
- log::info!("Jan API server started on http://{}", addr);
+ let actual_addr = server.local_addr();
+ log::info!("Jan API server started on http://{}", actual_addr);
let server_task = tokio::spawn(async move {
if let Err(e) = server.await {
@@ -678,7 +679,9 @@ pub async fn start_server(
});
*handle_guard = Some(server_task);
- Ok(true)
+ let actual_port = actual_addr.port();
+ log::info!("Jan API server started successfully on port {}", actual_port);
+ Ok(actual_port)
}
pub async fn stop_server(
diff --git a/src-tauri/tauri.android.conf.json b/src-tauri/tauri.android.conf.json
new file mode 100644
index 000000000..04f09d973
--- /dev/null
+++ b/src-tauri/tauri.android.conf.json
@@ -0,0 +1,7 @@
+{
+ "app": {
+ "security": {
+ "capabilities": ["default"]
+ }
+ }
+}
\ No newline at end of file
diff --git a/src-tauri/tauri.ios.conf.json b/src-tauri/tauri.ios.conf.json
index fc99b5160..c5346846d 100644
--- a/src-tauri/tauri.ios.conf.json
+++ b/src-tauri/tauri.ios.conf.json
@@ -1,6 +1,12 @@
{
+ "app": {
+ "security": {
+ "capabilities": ["default"]
+ }
+ },
"bundle": {
"iOS": {
+ "developmentTeam": "<DEVELOPMENT_TEAM_ID>"
}
}
}
\ No newline at end of file
diff --git a/web-app/src/hooks/useLocalApiServer.ts b/web-app/src/hooks/useLocalApiServer.ts
index 712277425..44389272d 100644
--- a/web-app/src/hooks/useLocalApiServer.ts
+++ b/web-app/src/hooks/useLocalApiServer.ts
@@ -40,7 +40,8 @@ export const useLocalApiServer = create<LocalApiServerState>()(
setEnableOnStartup: (value) => set({ enableOnStartup: value }),
serverHost: '127.0.0.1',
setServerHost: (value) => set({ serverHost: value }),
- serverPort: 1337,
+ // Use port 0 (auto-assign) for mobile to avoid conflicts, 1337 for desktop
+ serverPort: (typeof window !== 'undefined' && (window as any).IS_ANDROID) || (typeof window !== 'undefined' && (window as any).IS_IOS) ? 0 : 1337,
setServerPort: (value) => set({ serverPort: value }),
apiPrefix: '/v1',
setApiPrefix: (value) => set({ apiPrefix: value }),
diff --git a/web-app/src/providers/DataProvider.tsx b/web-app/src/providers/DataProvider.tsx
index a734cd39f..b7d3a3581 100644
--- a/web-app/src/providers/DataProvider.tsx
+++ b/web-app/src/providers/DataProvider.tsx
@@ -31,6 +31,7 @@ export function DataProvider() {
enableOnStartup,
serverHost,
serverPort,
+ setServerPort,
apiPrefix,
apiKey,
trustedHosts,
@@ -173,7 +174,11 @@ export function DataProvider() {
proxyTimeout: proxyTimeout,
})
})
- .then(() => {
+ .then((actualPort: number) => {
+ // Store the actual port that was assigned (important for mobile with port 0)
+ if (actualPort && actualPort !== serverPort) {
+ setServerPort(actualPort)
+ }
setServerStatus('running')
})
.catch((error: unknown) => {
diff --git a/web-app/src/routes/settings/local-api-server.tsx b/web-app/src/routes/settings/local-api-server.tsx
index 9f2b2315b..c37ac75f2 100644
--- a/web-app/src/routes/settings/local-api-server.tsx
+++ b/web-app/src/routes/settings/local-api-server.tsx
@@ -48,6 +48,7 @@ function LocalAPIServerContent() {
setEnableOnStartup,
serverHost,
serverPort,
+ setServerPort,
apiPrefix,
apiKey,
trustedHosts,
@@ -162,7 +163,11 @@ function LocalAPIServerContent() {
proxyTimeout: proxyTimeout,
})
})
- .then(() => {
+ .then((actualPort: number) => {
+ // Store the actual port that was assigned (important for mobile with port 0)
+ if (actualPort && actualPort !== serverPort) {
+ setServerPort(actualPort)
+ }
setServerStatus('running')
})
.catch((error: unknown) => {