chenbhao commited on
Commit
a02afe0
·
1 Parent(s): f148531

fix: friend render

Browse files
src/components/friend/frontend/main.tsx CHANGED
@@ -1,9 +1,20 @@
1
  import React from 'react'
2
  import ReactDOM from 'react-dom/client'
3
  import App from './App'
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  ReactDOM.createRoot(document.getElementById('root')!).render(
6
  <React.StrictMode>
7
  <App />
8
  </React.StrictMode>,
9
- )
 
1
  import React from 'react'
2
  import ReactDOM from 'react-dom/client'
3
  import App from './App'
4
+ import { listen } from '@tauri-apps/api/event'
5
+
6
+ // Ensure correct URL when loaded via Tauri (WebGL requires HTTP server)
7
+ if (typeof window !== 'undefined' && !window.location.href.includes('/friend/')) {
8
+ window.location.replace('http://127.0.0.1:3456/friend/')
9
+ }
10
+
11
+ // Listen for Tauri close event and notify backend
12
+ listen('friend-window-close', () => {
13
+ fetch('http://127.0.0.1:3456/friend/api/window-close', { method: 'POST' }).catch(() => {})
14
+ })
15
 
16
  ReactDOM.createRoot(document.getElementById('root')!).render(
17
  <React.StrictMode>
18
  <App />
19
  </React.StrictMode>,
20
+ )
src/components/friend/frontend/src-tauri/Cargo.lock CHANGED
@@ -4030,6 +4030,7 @@ dependencies = [
4030
  "tauri",
4031
  "tauri-build",
4032
  "tauri-plugin-opener",
 
4033
  ]
4034
 
4035
  [[package]]
 
4030
  "tauri",
4031
  "tauri-build",
4032
  "tauri-plugin-opener",
4033
+ "url",
4034
  ]
4035
 
4036
  [[package]]
src/components/friend/frontend/src-tauri/Cargo.toml CHANGED
@@ -17,6 +17,7 @@ tauri = { version = "2", features = [] }
17
  tauri-plugin-opener = "2"
18
  serde = { version = "1", features = ["derive"] }
19
  serde_json = "1"
 
20
 
21
  [features]
22
  default = ["custom-protocol"]
 
17
  tauri-plugin-opener = "2"
18
  serde = { version = "1", features = ["derive"] }
19
  serde_json = "1"
20
+ url = "2.5.8"
21
 
22
  [features]
23
  default = ["custom-protocol"]
src/components/friend/frontend/src-tauri/src/lib.rs CHANGED
@@ -1,22 +1,20 @@
1
- use tauri::{Manager, WindowEvent};
2
 
3
  #[cfg_attr(mobile, tauri::mobile_entry_point)]
4
  pub fn run() {
5
  let builder = tauri::Builder::default()
6
  .plugin(tauri_plugin_opener::init())
7
  .setup(|app| {
8
- let window = app.get_webview_window("main").unwrap();
9
- // Force load from HTTP server so WebGL works properly in webkit2gtk
10
- window.eval("window.location.replace('http://127.0.0.1:3456/friend/')")
11
- .map_err(|e| eprintln!("Failed to set URL: {e}")).ok();
 
12
  Ok(())
13
  })
14
  .on_window_event(|window, event| {
15
  if let WindowEvent::CloseRequested { .. } = event {
16
- // Notify backend that Friend window is closing
17
- let _ = window.eval(
18
- "fetch('http://127.0.0.1:3456/friend/api/window-close', {method:'POST'})",
19
- );
20
  }
21
  });
22
 
 
1
+ use tauri::{Emitter, Manager, WindowEvent};
2
 
3
  #[cfg_attr(mobile, tauri::mobile_entry_point)]
4
  pub fn run() {
5
  let builder = tauri::Builder::default()
6
  .plugin(tauri_plugin_opener::init())
7
  .setup(|app| {
8
+ if let Some(window) = app.get_webview_window("main") {
9
+ let url = url::Url::parse("http://127.0.0.1:3456/friend/").unwrap();
10
+ let _ = window.navigate(url);
11
+ let _ = window.set_focus();
12
+ }
13
  Ok(())
14
  })
15
  .on_window_event(|window, event| {
16
  if let WindowEvent::CloseRequested { .. } = event {
17
+ window.emit("friend-window-close", ()).ok();
 
 
 
18
  }
19
  });
20