Skip to content

Commit 0df4374

Browse files
authored
Merge pull request #9 from Cut0x/patch-0_3_3-p1
Patch 0 3 3 p1
2 parents d4708eb + 1a9869c commit 0df4374

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

src-tauri/src/webview.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
use tauri::{AppHandle, Emitter, Manager, WebviewUrl};
22
use crate::{sentinel, title, tab_label};
33

4+
/// Recherche un WebView enfant par son tab_id dans la fenêtre principale.
5+
/// `app.get_webview()` ne trouve PAS les WebViews ajoutés via Window::add_child —
6+
/// ils sont stockés dans la liste de la fenêtre parente, pas dans le registre global.
7+
fn find_tab_webview<R: tauri::Runtime>(app: &AppHandle<R>, tab_id: &str) -> Option<tauri::Webview<R>> {
8+
let label = tab_label(tab_id);
9+
let win = app.get_window("main")?;
10+
win.webviews().into_iter().find(|w| w.label() == label.as_str())
11+
}
12+
413
#[tauri::command]
514
pub fn tab_webview_create(app: AppHandle, tab_id: String, url: String) -> Result<(), String> {
615
let label = tab_label(&tab_id);
@@ -48,13 +57,13 @@ pub fn tab_webview_create(app: AppHandle, tab_id: String, url: String) -> Result
4857
}
4958
}),
5059
tauri::LogicalPosition::new(-9999.0, -9999.0),
51-
tauri::LogicalSize::new(1.0, 1.0),
60+
tauri::LogicalSize::new(1280.0, 800.0),
5261
).map(|_| ()).map_err(|e| e.to_string())
5362
}
5463

5564
#[tauri::command]
5665
pub fn tab_webview_show(app: AppHandle, tab_id: String, top: f64, width: f64, height: f64) -> Result<(), String> {
57-
let wv = app.get_webview(&tab_label(&tab_id)).ok_or("webview introuvable")?;
66+
let wv = find_tab_webview(&app, &tab_id).ok_or_else(|| format!("webview introuvable: {tab_id}"))?;
5867
wv.set_bounds(tauri::Rect {
5968
position: tauri::Position::Logical(tauri::LogicalPosition::new(0.0, top)),
6069
size: tauri::Size::Logical(tauri::LogicalSize::new(width, height)),
@@ -63,40 +72,40 @@ pub fn tab_webview_show(app: AppHandle, tab_id: String, top: f64, width: f64, he
6372

6473
#[tauri::command]
6574
pub fn tab_webview_hide(app: AppHandle, tab_id: String) -> Result<(), String> {
66-
if let Some(wv) = app.get_webview(&tab_label(&tab_id)) {
75+
if let Some(wv) = find_tab_webview(&app, &tab_id) {
6776
wv.set_bounds(tauri::Rect {
6877
position: tauri::Position::Logical(tauri::LogicalPosition::new(-9999.0, -9999.0)),
69-
size: tauri::Size::Logical(tauri::LogicalSize::new(1.0, 1.0)),
78+
size: tauri::Size::Logical(tauri::LogicalSize::new(1280.0, 800.0)),
7079
}).map_err(|e| e.to_string())?;
7180
}
7281
Ok(())
7382
}
7483

7584
#[tauri::command]
7685
pub fn tab_webview_close(app: AppHandle, tab_id: String) -> Result<(), String> {
77-
if let Some(wv) = app.get_webview(&tab_label(&tab_id)) {
86+
if let Some(wv) = find_tab_webview(&app, &tab_id) {
7887
wv.close().map_err(|e| e.to_string())?;
7988
}
8089
Ok(())
8190
}
8291

8392
#[tauri::command]
8493
pub fn tab_webview_navigate(app: AppHandle, tab_id: String, url: String) -> Result<(), String> {
85-
let wv = app.get_webview(&tab_label(&tab_id)).ok_or("webview introuvable")?;
94+
let wv = find_tab_webview(&app, &tab_id).ok_or_else(|| format!("webview introuvable: {tab_id}"))?;
8695
wv.navigate(tauri::Url::parse(&url).map_err(|e| e.to_string())?).map_err(|e| e.to_string())
8796
}
8897

8998
#[tauri::command]
9099
pub fn tab_webview_eval(app: AppHandle, tab_id: String, js: String) -> Result<(), String> {
91-
if let Some(wv) = app.get_webview(&tab_label(&tab_id)) {
100+
if let Some(wv) = find_tab_webview(&app, &tab_id) {
92101
wv.eval(&js).map_err(|e| e.to_string())?;
93102
}
94103
Ok(())
95104
}
96105

97106
#[tauri::command]
98107
pub fn tab_webview_reload(app: AppHandle, tab_id: String) -> Result<(), String> {
99-
if let Some(wv) = app.get_webview(&tab_label(&tab_id)) {
108+
if let Some(wv) = find_tab_webview(&app, &tab_id) {
100109
wv.eval("window.location.reload()").map_err(|e| e.to_string())?;
101110
}
102111
Ok(())

src/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export class BrowserEngine {
153153
this._webviewVisible = visible;
154154
const tabId = this._activeTabId;
155155
if (!tabId || !this._created.has(tabId)) return;
156-
if (!visible) { await invoke<void>('tab_webview_hide', { tabId }).catch(() => {}); return; }
156+
if (!visible) { await invoke<void>('tab_webview_hide', { tabId }).catch(e => console.error('[Auralis] hide:', e)); return; }
157157
const top = chrome.getBoundingClientRect().bottom;
158-
await invoke<void>('tab_webview_show', { tabId, top, width: window.innerWidth, height: Math.max(1, window.innerHeight - top) }).catch(() => {});
158+
await invoke<void>('tab_webview_show', { tabId, top, width: window.innerWidth, height: Math.max(1, window.innerHeight - top) }).catch(e => console.error('[Auralis] show:', e));
159159
}
160160
}

0 commit comments

Comments
 (0)