mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-04 17:18:56 +03:00
refactor(core): clear uri_scheme_protocol
registration function names (#1617)
* refactor(core): clear `custom_protocol` registration function names * fix * fix clippy * improve docs * clippy * renames
This commit is contained in:
parent
d623d95fcb
commit
a868cb7176
@ -2,4 +2,4 @@
|
|||||||
"tauri": patch
|
"tauri": patch
|
||||||
---
|
---
|
||||||
|
|
||||||
Adds APIs to determine global and window-specific custom protocol handlers.
|
Adds APIs to determine global and webview-specific URI scheme handlers.
|
||||||
|
@ -120,22 +120,22 @@ mod test {
|
|||||||
if first.path.extension() == Some(OsStr::new("txt")) {
|
if first.path.extension() == Some(OsStr::new("txt")) {
|
||||||
// check the fields for the first DiskEntry
|
// check the fields for the first DiskEntry
|
||||||
assert_eq!(first.path, file_one);
|
assert_eq!(first.path, file_one);
|
||||||
assert_eq!(first.children.is_some(), false);
|
assert!(first.children.is_none());
|
||||||
assert_eq!(first.name, name_from_path(file_one));
|
assert_eq!(first.name, name_from_path(file_one));
|
||||||
|
|
||||||
// check the fields for the third DiskEntry
|
// check the fields for the third DiskEntry
|
||||||
assert_eq!(second.path, file_two);
|
assert_eq!(second.path, file_two);
|
||||||
assert_eq!(second.children.is_some(), false);
|
assert!(second.children.is_none());
|
||||||
assert_eq!(second.name, name_from_path(file_two));
|
assert_eq!(second.name, name_from_path(file_two));
|
||||||
} else {
|
} else {
|
||||||
// check the fields for the second DiskEntry
|
// check the fields for the second DiskEntry
|
||||||
assert_eq!(first.path, file_two);
|
assert_eq!(first.path, file_two);
|
||||||
assert_eq!(first.children.is_some(), false);
|
assert!(first.children.is_none());
|
||||||
assert_eq!(first.name, name_from_path(file_two));
|
assert_eq!(first.name, name_from_path(file_two));
|
||||||
|
|
||||||
// check the fields for the third DiskEntry
|
// check the fields for the third DiskEntry
|
||||||
assert_eq!(second.path, file_one);
|
assert_eq!(second.path, file_one);
|
||||||
assert_eq!(second.children.is_some(), false);
|
assert!(second.children.is_none());
|
||||||
assert_eq!(second.name, name_from_path(file_one));
|
assert_eq!(second.name, name_from_path(file_one));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,22 +165,22 @@ mod test {
|
|||||||
if first.path.extension() == Some(OsStr::new("txt")) {
|
if first.path.extension() == Some(OsStr::new("txt")) {
|
||||||
// check the fields for the first DiskEntry
|
// check the fields for the first DiskEntry
|
||||||
assert_eq!(first.path, PathBuf::from("test/api/test.txt"));
|
assert_eq!(first.path, PathBuf::from("test/api/test.txt"));
|
||||||
assert_eq!(first.children.is_some(), false);
|
assert!(first.children.is_none());
|
||||||
assert_eq!(first.name, Some("test.txt".to_string()));
|
assert_eq!(first.name, Some("test.txt".to_string()));
|
||||||
|
|
||||||
// check the fields for the second DiskEntry
|
// check the fields for the second DiskEntry
|
||||||
assert_eq!(second.path, PathBuf::from("test/api/test_binary"));
|
assert_eq!(second.path, PathBuf::from("test/api/test_binary"));
|
||||||
assert_eq!(second.children.is_some(), false);
|
assert!(second.children.is_none());
|
||||||
assert_eq!(second.name, Some("test_binary".to_string()));
|
assert_eq!(second.name, Some("test_binary".to_string()));
|
||||||
} else {
|
} else {
|
||||||
// check the fields for the first DiskEntry
|
// check the fields for the first DiskEntry
|
||||||
assert_eq!(second.path, PathBuf::from("test/api/test.txt"));
|
assert_eq!(second.path, PathBuf::from("test/api/test.txt"));
|
||||||
assert_eq!(second.children.is_some(), false);
|
assert!(second.children.is_none());
|
||||||
assert_eq!(second.name, Some("test.txt".to_string()));
|
assert_eq!(second.name, Some("test.txt".to_string()));
|
||||||
|
|
||||||
// check the fields for the second DiskEntry
|
// check the fields for the second DiskEntry
|
||||||
assert_eq!(first.path, PathBuf::from("test/api/test_binary"));
|
assert_eq!(first.path, PathBuf::from("test/api/test_binary"));
|
||||||
assert_eq!(first.children.is_some(), false);
|
assert!(first.children.is_none());
|
||||||
assert_eq!(first.name, Some("test_binary".to_string()));
|
assert_eq!(first.name, Some("test_binary".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ mod test {
|
|||||||
let l = listeners.inner.handlers.lock().unwrap();
|
let l = listeners.inner.handlers.lock().unwrap();
|
||||||
|
|
||||||
// check if the generated key is in the map
|
// check if the generated key is in the map
|
||||||
assert_eq!(l.contains_key(&key), true);
|
assert!(l.contains_key(&key));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if listen inputs a handler function properly into the LISTENERS map.
|
// check to see if listen inputs a handler function properly into the LISTENERS map.
|
||||||
|
@ -49,7 +49,7 @@ use std::path::PathBuf;
|
|||||||
// Export types likely to be used by the application.
|
// Export types likely to be used by the application.
|
||||||
pub use {
|
pub use {
|
||||||
api::config::WindowUrl,
|
api::config::WindowUrl,
|
||||||
hooks::{InvokeMessage, PageLoadPayload},
|
hooks::{InvokeHandler, InvokeMessage, OnPageLoad, PageLoadPayload, SetupHook},
|
||||||
runtime::app::{App, Builder},
|
runtime::app::{App, Builder},
|
||||||
runtime::webview::Attributes,
|
runtime::webview::Attributes,
|
||||||
runtime::window::export::Window,
|
runtime::window::export::Window,
|
||||||
|
@ -124,8 +124,8 @@ where
|
|||||||
/// All passed plugins
|
/// All passed plugins
|
||||||
plugins: PluginStore<Args<E, L, A, R>>,
|
plugins: PluginStore<Args<E, L, A, R>>,
|
||||||
|
|
||||||
/// The custom protocols available to all windows.
|
/// The webview protocols available to all windows.
|
||||||
custom_protocols: HashMap<String, Arc<CustomProtocol>>,
|
uri_scheme_protocols: HashMap<String, Arc<CustomProtocol>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E, L, A, R> Builder<E, L, A, R>
|
impl<E, L, A, R> Builder<E, L, A, R>
|
||||||
@ -143,7 +143,7 @@ where
|
|||||||
on_page_load: Box::new(|_, _| ()),
|
on_page_load: Box::new(|_, _| ()),
|
||||||
pending_windows: Default::default(),
|
pending_windows: Default::default(),
|
||||||
plugins: PluginStore::default(),
|
plugins: PluginStore::default(),
|
||||||
custom_protocols: Default::default(),
|
uri_scheme_protocols: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,19 +192,27 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a custom protocol available to all windows.
|
/// Registers a URI scheme protocol available to all webviews.
|
||||||
pub fn custom_protocol<
|
/// Leverages [setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler) on macOS,
|
||||||
|
/// [AddWebResourceRequestedFilter](https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addwebresourcerequestedfilter?view=webview2-dotnet-1.0.774.44) on Windows
|
||||||
|
/// and [webkit-web-context-register-uri-scheme](https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-register-uri-scheme) on Linux.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `uri_scheme` The URI scheme to register, such as `example`.
|
||||||
|
/// * `protocol` the protocol associated with the given URI scheme. It's a function that takes an URL such as `example://localhost/asset.css`.
|
||||||
|
pub fn register_global_uri_scheme_protocol<
|
||||||
N: Into<String>,
|
N: Into<String>,
|
||||||
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
||||||
>(
|
>(
|
||||||
mut self,
|
mut self,
|
||||||
name: N,
|
uri_scheme: N,
|
||||||
handler: H,
|
protocol: H,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.custom_protocols.insert(
|
self.uri_scheme_protocols.insert(
|
||||||
name.into(),
|
uri_scheme.into(),
|
||||||
Arc::new(CustomProtocol {
|
Arc::new(CustomProtocol {
|
||||||
handler: Box::new(handler),
|
protocol: Box::new(protocol),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
@ -217,7 +225,7 @@ where
|
|||||||
self.plugins,
|
self.plugins,
|
||||||
self.invoke_handler,
|
self.invoke_handler,
|
||||||
self.on_page_load,
|
self.on_page_load,
|
||||||
self.custom_protocols,
|
self.uri_scheme_protocols,
|
||||||
);
|
);
|
||||||
|
|
||||||
// set up all the windows defined in the config
|
// set up all the windows defined in the config
|
||||||
|
@ -44,7 +44,7 @@ impl TryFrom<Icon> for WryIcon {
|
|||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct WryAttributes {
|
pub struct WryAttributes {
|
||||||
attributes: wry::Attributes,
|
attributes: wry::Attributes,
|
||||||
custom_protocols: Arc<Mutex<HashMap<String, wry::CustomProtocol>>>,
|
uri_scheme_protocols: Arc<Mutex<HashMap<String, wry::CustomProtocol>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AttributesBase for WryAttributes {}
|
impl AttributesBase for WryAttributes {}
|
||||||
@ -197,24 +197,24 @@ impl Attributes for WryAttributes {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_custom_protocol(&self, name: &str) -> bool {
|
fn has_uri_scheme_protocol(&self, name: &str) -> bool {
|
||||||
self.custom_protocols.lock().unwrap().contains_key(name)
|
self.uri_scheme_protocols.lock().unwrap().contains_key(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn custom_protocol<
|
fn register_uri_scheme_protocol<
|
||||||
N: Into<String>,
|
N: Into<String>,
|
||||||
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
||||||
>(
|
>(
|
||||||
self,
|
self,
|
||||||
name: N,
|
uri_scheme: N,
|
||||||
handler: H,
|
protocol: H,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let name = name.into();
|
let uri_scheme = uri_scheme.into();
|
||||||
self.custom_protocols.lock().unwrap().insert(
|
self.uri_scheme_protocols.lock().unwrap().insert(
|
||||||
name.clone(),
|
uri_scheme.clone(),
|
||||||
wry::CustomProtocol {
|
wry::CustomProtocol {
|
||||||
name,
|
name: uri_scheme,
|
||||||
handler: Box::new(move |data| (handler)(data).map_err(|_| wry::Error::InitScriptError)),
|
handler: Box::new(move |data| (protocol)(data).map_err(|_| wry::Error::InitScriptError)),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
@ -276,9 +276,9 @@ impl Dispatch for WryDispatcher {
|
|||||||
let file_drop_handler = file_drop_handler
|
let file_drop_handler = file_drop_handler
|
||||||
.map(|handler| create_file_drop_handler(proxy.clone(), label.clone(), handler));
|
.map(|handler| create_file_drop_handler(proxy.clone(), label.clone(), handler));
|
||||||
|
|
||||||
let custom_protocols = {
|
let uri_scheme_protocols = {
|
||||||
let mut lock = attributes
|
let mut lock = attributes
|
||||||
.custom_protocols
|
.uri_scheme_protocols
|
||||||
.lock()
|
.lock()
|
||||||
.expect("poisoned custom protocols");
|
.expect("poisoned custom protocols");
|
||||||
std::mem::take(&mut *lock)
|
std::mem::take(&mut *lock)
|
||||||
@ -289,7 +289,7 @@ impl Dispatch for WryDispatcher {
|
|||||||
.add_window_with_configs(
|
.add_window_with_configs(
|
||||||
attributes.attributes,
|
attributes.attributes,
|
||||||
rpc_handler,
|
rpc_handler,
|
||||||
custom_protocols.into_iter().map(|(_, p)| p).collect(),
|
uri_scheme_protocols.into_iter().map(|(_, p)| p).collect(),
|
||||||
file_drop_handler,
|
file_drop_handler,
|
||||||
)
|
)
|
||||||
.map_err(|e| crate::Error::CreateWebview(e.to_string()))?;
|
.map_err(|e| crate::Error::CreateWebview(e.to_string()))?;
|
||||||
@ -490,9 +490,9 @@ impl Runtime for Wry {
|
|||||||
let file_drop_handler = file_drop_handler
|
let file_drop_handler = file_drop_handler
|
||||||
.map(|handler| create_file_drop_handler(proxy.clone(), label.clone(), handler));
|
.map(|handler| create_file_drop_handler(proxy.clone(), label.clone(), handler));
|
||||||
|
|
||||||
let custom_protocols = {
|
let uri_scheme_protocols = {
|
||||||
let mut lock = attributes
|
let mut lock = attributes
|
||||||
.custom_protocols
|
.uri_scheme_protocols
|
||||||
.lock()
|
.lock()
|
||||||
.expect("poisoned custom protocols");
|
.expect("poisoned custom protocols");
|
||||||
std::mem::take(&mut *lock)
|
std::mem::take(&mut *lock)
|
||||||
@ -503,7 +503,7 @@ impl Runtime for Wry {
|
|||||||
.add_window_with_configs(
|
.add_window_with_configs(
|
||||||
attributes.attributes,
|
attributes.attributes,
|
||||||
rpc_handler,
|
rpc_handler,
|
||||||
custom_protocols.into_iter().map(|(_, p)| p).collect(),
|
uri_scheme_protocols.into_iter().map(|(_, p)| p).collect(),
|
||||||
file_drop_handler,
|
file_drop_handler,
|
||||||
)
|
)
|
||||||
.map_err(|e| crate::Error::CreateWebview(e.to_string()))?;
|
.map_err(|e| crate::Error::CreateWebview(e.to_string()))?;
|
||||||
|
@ -51,8 +51,8 @@ pub struct InnerWindowManager<P: Params> {
|
|||||||
/// A list of salts that are valid for the current application.
|
/// A list of salts that are valid for the current application.
|
||||||
salts: Mutex<HashSet<Uuid>>,
|
salts: Mutex<HashSet<Uuid>>,
|
||||||
package_info: PackageInfo,
|
package_info: PackageInfo,
|
||||||
/// The custom protocols available to all windows.
|
/// The webview protocols protocols available to all windows.
|
||||||
custom_protocols: HashMap<String, std::sync::Arc<CustomProtocol>>,
|
uri_scheme_protocols: HashMap<String, std::sync::Arc<CustomProtocol>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [Zero Sized Type] marker representing a full [`Params`].
|
/// A [Zero Sized Type] marker representing a full [`Params`].
|
||||||
@ -104,7 +104,7 @@ impl<P: Params> WindowManager<P> {
|
|||||||
plugins: PluginStore<P>,
|
plugins: PluginStore<P>,
|
||||||
invoke_handler: Box<InvokeHandler<P>>,
|
invoke_handler: Box<InvokeHandler<P>>,
|
||||||
on_page_load: Box<OnPageLoad<P>>,
|
on_page_load: Box<OnPageLoad<P>>,
|
||||||
custom_protocols: HashMap<String, std::sync::Arc<CustomProtocol>>,
|
uri_scheme_protocols: HashMap<String, std::sync::Arc<CustomProtocol>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: Arc::new(InnerWindowManager {
|
inner: Arc::new(InnerWindowManager {
|
||||||
@ -118,7 +118,7 @@ impl<P: Params> WindowManager<P> {
|
|||||||
default_window_icon: context.default_window_icon,
|
default_window_icon: context.default_window_icon,
|
||||||
salts: Mutex::default(),
|
salts: Mutex::default(),
|
||||||
package_info: context.package_info,
|
package_info: context.package_info,
|
||||||
custom_protocols,
|
uri_scheme_protocols,
|
||||||
}),
|
}),
|
||||||
_marker: Args::default(),
|
_marker: Args::default(),
|
||||||
}
|
}
|
||||||
@ -179,15 +179,17 @@ impl<P: Params> WindowManager<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, protocol) in &self.inner.custom_protocols {
|
for (uri_scheme, protocol) in &self.inner.uri_scheme_protocols {
|
||||||
if !attributes.has_custom_protocol(name) {
|
if !attributes.has_uri_scheme_protocol(uri_scheme) {
|
||||||
let protocol = protocol.clone();
|
let protocol = protocol.clone();
|
||||||
attributes = attributes.custom_protocol(name.clone(), move |p| (protocol.handler)(p));
|
attributes = attributes
|
||||||
|
.register_uri_scheme_protocol(uri_scheme.clone(), move |p| (protocol.protocol)(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attributes.has_custom_protocol("tauri") {
|
if !attributes.has_uri_scheme_protocol("tauri") {
|
||||||
attributes = attributes.custom_protocol("tauri", self.prepare_custom_protocol().handler);
|
attributes = attributes
|
||||||
|
.register_uri_scheme_protocol("tauri", self.prepare_uri_scheme_protocol().protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
let local_app_data = resolve_path(
|
let local_app_data = resolve_path(
|
||||||
@ -233,10 +235,10 @@ impl<P: Params> WindowManager<P> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_custom_protocol(&self) -> CustomProtocol {
|
fn prepare_uri_scheme_protocol(&self) -> CustomProtocol {
|
||||||
let assets = self.inner.assets.clone();
|
let assets = self.inner.assets.clone();
|
||||||
CustomProtocol {
|
CustomProtocol {
|
||||||
handler: Box::new(move |path| {
|
protocol: Box::new(move |path| {
|
||||||
let mut path = path
|
let mut path = path
|
||||||
.split('?')
|
.split('?')
|
||||||
// ignore query string
|
// ignore query string
|
||||||
|
@ -92,17 +92,25 @@ pub trait Attributes: AttributesBase {
|
|||||||
/// Sets the webview url.
|
/// Sets the webview url.
|
||||||
fn url(self, url: String) -> Self;
|
fn url(self, url: String) -> Self;
|
||||||
|
|
||||||
/// Whether the custom protocol handler is defined or not.
|
/// Whether the webview URI scheme protocol is defined or not.
|
||||||
fn has_custom_protocol(&self, name: &str) -> bool;
|
fn has_uri_scheme_protocol(&self, name: &str) -> bool;
|
||||||
|
|
||||||
/// Adds a custom protocol handler.
|
/// Registers a webview protocol handler.
|
||||||
fn custom_protocol<
|
/// Leverages [setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler) on macOS,
|
||||||
|
/// [AddWebResourceRequestedFilter](https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addwebresourcerequestedfilter?view=webview2-dotnet-1.0.774.44) on Windows
|
||||||
|
/// and [webkit-web-context-register-uri-scheme](https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-register-uri-scheme) on Linux.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `uri_scheme` The URI scheme to register, such as `example`.
|
||||||
|
/// * `protocol` the protocol associated with the given URI scheme. It's a function that takes an URL such as `example://localhost/asset.css`.
|
||||||
|
fn register_uri_scheme_protocol<
|
||||||
N: Into<String>,
|
N: Into<String>,
|
||||||
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
H: Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync + 'static,
|
||||||
>(
|
>(
|
||||||
self,
|
self,
|
||||||
name: N,
|
uri_scheme: N,
|
||||||
handler: H,
|
protocol: H,
|
||||||
) -> Self;
|
) -> Self;
|
||||||
|
|
||||||
/// The full attributes.
|
/// The full attributes.
|
||||||
@ -117,10 +125,10 @@ pub struct RpcRequest {
|
|||||||
pub params: Option<JsonValue>,
|
pub params: Option<JsonValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uses a custom handler to resolve file requests
|
/// Uses a custom URI scheme handler to resolve file requests
|
||||||
pub struct CustomProtocol {
|
pub struct CustomProtocol {
|
||||||
/// Handler for protocol
|
/// Handler for protocol
|
||||||
pub handler: Box<dyn Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync>,
|
pub protocol: Box<dyn Fn(&str) -> crate::Result<Vec<u8>> + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The file drop event payload.
|
/// The file drop event payload.
|
||||||
|
@ -790,10 +790,10 @@ mod test {
|
|||||||
.url(mockito::server_url())
|
.url(mockito::server_url())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -809,10 +809,10 @@ mod test {
|
|||||||
.url(mockito::server_url())
|
.url(mockito::server_url())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -829,10 +829,10 @@ mod test {
|
|||||||
.url(mockito::server_url())
|
.url(mockito::server_url())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
assert_eq!(updater.version, "2.0.0");
|
assert_eq!(updater.version, "2.0.0");
|
||||||
assert_eq!(updater.signature, Some("dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUldUTE5QWWxkQnlZOVJHMWlvTzRUSlQzTHJOMm5waWpic0p0VVI2R0hUNGxhQVMxdzBPRndlbGpXQXJJakpTN0toRURtVzBkcm15R0VaNTJuS1lZRWdzMzZsWlNKUVAzZGdJPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNTkyOTE1NTIzCWZpbGU6RDpcYVx0YXVyaVx0YXVyaVx0YXVyaVxleGFtcGxlc1xjb21tdW5pY2F0aW9uXHNyYy10YXVyaVx0YXJnZXRcZGVidWdcYXBwLng2NC5tc2kuemlwCitXa1lQc3A2MCs1KzEwZnVhOGxyZ2dGMlZqbjBaVUplWEltYUdyZ255eUF6eVF1dldWZzFObStaVEQ3QU1RS1lzcjhDVU4wWFovQ1p1QjJXbW1YZUJ3PT0K".into()));
|
assert_eq!(updater.signature, Some("dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUldUTE5QWWxkQnlZOVJHMWlvTzRUSlQzTHJOMm5waWpic0p0VVI2R0hUNGxhQVMxdzBPRndlbGpXQXJJakpTN0toRURtVzBkcm15R0VaNTJuS1lZRWdzMzZsWlNKUVAzZGdJPQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNTkyOTE1NTIzCWZpbGU6RDpcYVx0YXVyaVx0YXVyaVx0YXVyaVxleGFtcGxlc1xjb21tdW5pY2F0aW9uXHNyYy10YXVyaVx0YXJnZXRcZGVidWdcYXBwLng2NC5tc2kuemlwCitXa1lQc3A2MCs1KzEwZnVhOGxyZ2dGMlZqbjBaVUplWEltYUdyZ255eUF6eVF1dldWZzFObStaVEQ3QU1RS1lzcjhDVU4wWFovQ1p1QjJXbW1YZUJ3PT0K".into()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -854,10 +854,10 @@ mod test {
|
|||||||
.url(mockito::server_url())
|
.url(mockito::server_url())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, false);
|
assert!(!updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -880,10 +880,10 @@ mod test {
|
|||||||
))
|
))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -906,10 +906,10 @@ mod test {
|
|||||||
))
|
))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check update");
|
let updater = check_update.expect("Can't check update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, false);
|
assert!(!updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -926,10 +926,10 @@ mod test {
|
|||||||
.current_version("0.0.1")
|
.current_version("0.0.1")
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check remote update");
|
let updater = check_update.expect("Can't check remote update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -945,10 +945,10 @@ mod test {
|
|||||||
.current_version("0.0.1")
|
.current_version("0.0.1")
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_ok(), true);
|
assert!(check_update.is_ok());
|
||||||
let updater = check_update.expect("Can't check remote update");
|
let updater = check_update.expect("Can't check remote update");
|
||||||
|
|
||||||
assert_eq!(updater.should_update, true);
|
assert!(updater.should_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -964,7 +964,7 @@ mod test {
|
|||||||
.current_version("0.0.1")
|
.current_version("0.0.1")
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assert_eq!(check_update.is_err(), true);
|
assert!(check_update.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
// run complete process on mac only for now as we don't have
|
// run complete process on mac only for now as we don't have
|
||||||
|
@ -387,48 +387,37 @@ pub(crate) async fn check_update_with_dialog<M: Params>(
|
|||||||
package_info: crate::api::PackageInfo,
|
package_info: crate::api::PackageInfo,
|
||||||
window: Window<M>,
|
window: Window<M>,
|
||||||
) {
|
) {
|
||||||
if !updater_config.active || updater_config.endpoints.is_none() {
|
if let Some(endpoints) = updater_config.endpoints.clone() {
|
||||||
return;
|
// check updates
|
||||||
}
|
match self::core::builder()
|
||||||
|
.urls(&endpoints[..])
|
||||||
|
.current_version(&package_info.version)
|
||||||
|
.build()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(updater) => {
|
||||||
|
let pubkey = updater_config.pubkey.clone();
|
||||||
|
|
||||||
// prepare our endpoints
|
// if dialog enabled only
|
||||||
let endpoints = updater_config
|
if updater.should_update && updater_config.dialog {
|
||||||
.endpoints
|
let body = updater.body.clone().unwrap_or_else(|| String::from(""));
|
||||||
.as_ref()
|
let dialog =
|
||||||
// this expect can lead to a panic
|
prompt_for_install(&updater.clone(), &package_info.name, &body.clone(), pubkey).await;
|
||||||
// we should have a better handling here
|
|
||||||
.expect("Something wrong with endpoints")
|
|
||||||
.clone();
|
|
||||||
|
|
||||||
// check updates
|
if dialog.is_err() {
|
||||||
match self::core::builder()
|
send_status_update(
|
||||||
.urls(&endpoints[..])
|
window.clone(),
|
||||||
.current_version(&package_info.version)
|
EVENT_STATUS_ERROR,
|
||||||
.build()
|
Some(dialog.err().unwrap().to_string()),
|
||||||
.await
|
);
|
||||||
{
|
|
||||||
Ok(updater) => {
|
|
||||||
let pubkey = updater_config.pubkey.clone();
|
|
||||||
|
|
||||||
// if dialog enabled only
|
return;
|
||||||
if updater.should_update && updater_config.dialog {
|
}
|
||||||
let body = updater.body.clone().unwrap_or_else(|| String::from(""));
|
|
||||||
let dialog =
|
|
||||||
prompt_for_install(&updater.clone(), &package_info.name, &body.clone(), pubkey).await;
|
|
||||||
|
|
||||||
if dialog.is_err() {
|
|
||||||
send_status_update(
|
|
||||||
window.clone(),
|
|
||||||
EVENT_STATUS_ERROR,
|
|
||||||
Some(dialog.err().unwrap().to_string()),
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
Err(e) => {
|
send_status_update(window.clone(), EVENT_STATUS_ERROR, Some(e.to_string()));
|
||||||
send_status_update(window.clone(), EVENT_STATUS_ERROR, Some(e.to_string()));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user