Fix Add Server menu does not recognize servers not using HTTPS or using the :8096 port. #74

This commit is contained in:
prayag17 committed 2023-05-13 22:18:42 +05:30
1 parent 027cf93492
commit 9f4c2f990a
5 files changed
+87 -125

No files matched your search

+34 -2
View File
@@ -2,6 +2,8 @@
use tauri::Manager;
use tauri::{utils::config::AppUrl, WindowUrl};
// Create the command:
// This command must be async so that it doesn't run on the main thread.
#[tauri::command]
@@ -14,10 +16,40 @@ async fn close_splashscreen(window: tauri::Window) {
window.get_window("main").unwrap().show().unwrap();
}
// Tauri by default uses HTTPS, so use the localhost plugin to downgrade back to
// HTTP. However, when running tauri dev, we already have a localhost server
// provided by vite, so don't enable it
#[cfg(debug_assertions)]
const USE_LOCALHOST_SERVER: bool = false;
#[cfg(not(debug_assertions))]
const USE_LOCALHOST_SERVER: bool = true;
fn main() {
tauri::Builder::default()
let port = portpicker::pick_unused_port().expect("failed to find unused port");
let window_url = if USE_LOCALHOST_SERVER {
WindowUrl::External(format!("http://localhost:{}", port).parse().unwrap())
} else {
WindowUrl::App("index.html".into())
};
let mut context = tauri::generate_context!();
let mut builder = tauri::Builder::default();
if USE_LOCALHOST_SERVER {
// rewrite the config so the IPC is enabled on this URL
context.config_mut().build.dist_dir = AppUrl::Url(window_url.clone());
context.config_mut().build.dev_path = AppUrl::Url(window_url.clone());
builder = builder.plugin(tauri_plugin_localhost::Builder::new(port).build());
}
builder
.invoke_handler(tauri::generate_handler![close_splashscreen])
.plugin(tauri_plugin_store::Builder::default().build())
.run(tauri::generate_context!())
.run(context)
.expect("error while running tauri application");
// tauri::Builder::default()
// .run(tauri::generate_context!())
// .expect("error while running tauri application");
}