fix: use webview's resources table (#1191)

* fix: use webview's resources table

* fix clipboard into_img usage

* fix mobile
This commit is contained in:
Amr Bashir
2024-04-18 03:19:24 +02:00
committed by GitHub
parent 8638740223
commit e3d41f4011
13 changed files with 152 additions and 102 deletions
+6 -6
View File
@@ -8,7 +8,7 @@ use serde::Deserialize;
use tauri::{
ipc::{Channel, CommandScope, GlobalScope},
path::{BaseDirectory, SafePathBuf},
AppHandle, Manager, Resource, ResourceId, Runtime,
Manager, Resource, ResourceId, Runtime, Webview,
};
use std::{
@@ -82,7 +82,7 @@ pub struct WatchOptions {
#[tauri::command]
pub async fn watch<R: Runtime>(
app: AppHandle<R>,
webview: Webview<R>,
paths: Vec<SafePathBuf>,
options: WatchOptions,
on_event: Channel,
@@ -92,7 +92,7 @@ pub async fn watch<R: Runtime>(
let mut resolved_paths = Vec::with_capacity(paths.capacity());
for path in paths {
resolved_paths.push(resolve_path(
&app,
&webview,
&global_scope,
&command_scope,
path,
@@ -124,7 +124,7 @@ pub async fn watch<R: Runtime>(
WatcherKind::Watcher(watcher)
};
let rid = app
let rid = webview
.resources_table()
.add(WatcherResource::new(kind, resolved_paths));
@@ -132,8 +132,8 @@ pub async fn watch<R: Runtime>(
}
#[tauri::command]
pub async fn unwatch<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> CommandResult<()> {
let watcher = app.resources_table().take::<WatcherResource>(rid)?;
pub async fn unwatch<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> CommandResult<()> {
let watcher = webview.resources_table().take::<WatcherResource>(rid)?;
WatcherResource::with_lock(&watcher, |watcher| {
match &mut watcher.kind {
WatcherKind::Debouncer(ref mut debouncer) => {