resolve TODOs

pull/355/head
Lucas Nogueira 2 years ago
parent 02bfbc5ee3
commit 5f386442e9
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7

@ -12,8 +12,7 @@ pub fn name<R: Runtime>(app: AppHandle<R>) -> String {
#[tauri::command] #[tauri::command]
pub fn tauri_version() -> &'static str { pub fn tauri_version() -> &'static str {
// TODO: return actual tauri version with `tauri::VERSION` tauri::VERSION
env!("CARGO_PKG_VERSION")
} }
#[tauri::command] #[tauri::command]

@ -11,12 +11,11 @@ use config::{Arg, Config};
pub use error::Error; pub use error::Error;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
// TODO: use PluginApi#app when 2.0.0-alpha.9 is released pub struct Cli<R: Runtime>(PluginApi<R, Config>);
pub struct Cli<R: Runtime>(PluginApi<R, Config>, AppHandle<R>);
impl<R: Runtime> Cli<R> { impl<R: Runtime> Cli<R> {
pub fn matches(&self) -> Result<parser::Matches> { pub fn matches(&self) -> Result<parser::Matches> {
parser::get_matches(self.0.config(), self.1.package_info()) parser::get_matches(self.0.config(), self.0.app().package_info())
} }
} }
@ -39,7 +38,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
Builder::new("cli") Builder::new("cli")
.invoke_handler(tauri::generate_handler![cli_matches]) .invoke_handler(tauri::generate_handler![cli_matches])
.setup(|app, api| { .setup(|app, api| {
app.manage(Cli(api, app.clone())); app.manage(Cli(api));
Ok(()) Ok(())
}) })
.build() .build()

@ -10,6 +10,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use tauri::{plugin::PluginApi, AppHandle, Runtime}; use tauri::{plugin::PluginApi, AppHandle, Runtime};
@ -101,6 +102,14 @@ impl From<MessageDialogKind> for rfd::MessageLevel {
} }
} }
struct WindowHandle(RawWindowHandle);
unsafe impl HasRawWindowHandle for WindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
self.0
}
}
impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog { impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
fn from(d: FileDialogBuilder<R>) -> Self { fn from(d: FileDialogBuilder<R>) -> Self {
let mut builder = FileDialog::new(); let mut builder = FileDialog::new();
@ -119,8 +128,8 @@ impl<R: Runtime> From<FileDialogBuilder<R>> for FileDialog {
builder = builder.add_filter(&filter.name, &v); builder = builder.add_filter(&filter.name, &v);
} }
#[cfg(desktop)] #[cfg(desktop)]
if let Some(_parent) = d.parent { if let Some(parent) = d.parent {
// TODO builder = builder.set_parent(&parent); builder = builder.set_parent(&WindowHandle(parent));
} }
builder builder
@ -144,8 +153,8 @@ impl<R: Runtime> From<MessageDialogBuilder<R>> for rfd::MessageDialog {
dialog = dialog.set_buttons(buttons); dialog = dialog.set_buttons(buttons);
} }
if let Some(_parent) = d.parent { if let Some(parent) = d.parent {
// TODO dialog.set_parent(parent); dialog = dialog.set_parent(&WindowHandle(parent));
} }
dialog dialog

@ -25,6 +25,7 @@ struct PendingUpdate<R: Runtime>(Mutex<Option<UpdateResponse<R>>>);
#[derive(Default)] #[derive(Default)]
pub struct Builder { pub struct Builder {
target: Option<String>, target: Option<String>,
installer_args: Option<Vec<String>>,
} }
/// Extension trait to use the updater on [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`]. /// Extension trait to use the updater on [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`].
@ -63,14 +64,26 @@ impl Builder {
self self
} }
pub fn installer_args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.installer_args
.replace(args.into_iter().map(Into::into).collect());
self
}
pub fn build<R: Runtime>(self) -> TauriPlugin<R, Config> { pub fn build<R: Runtime>(self) -> TauriPlugin<R, Config> {
let target = self.target; let target = self.target;
let installer_args = self.installer_args;
PluginBuilder::<R, Config>::new("updater") PluginBuilder::<R, Config>::new("updater")
.setup(move |app, api| { .setup(move |app, api| {
app.manage(UpdaterState { let mut config = api.config().clone();
target, if let Some(installer_args) = installer_args {
config: api.config().clone(), config.installer_args = installer_args;
}); }
app.manage(UpdaterState { target, config });
app.manage(PendingUpdate::<R>(Default::default())); app.manage(PendingUpdate::<R>(Default::default()));
Ok(()) Ok(())
}) })

@ -9,6 +9,8 @@ use tauri_plugin_updater::UpdaterExt;
fn main() { fn main() {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut context = tauri::generate_context!(); let mut context = tauri::generate_context!();
let mut updater = tauri_plugin_updater::Builder::new();
if std::env::var("TARGET").unwrap_or_default() == "nsis" { if std::env::var("TARGET").unwrap_or_default() == "nsis" {
// /D sets the default installation directory ($INSTDIR), // /D sets the default installation directory ($INSTDIR),
// overriding InstallDir and InstallDirRegKey. // overriding InstallDir and InstallDirRegKey.
@ -16,23 +18,18 @@ fn main() {
// Only absolute paths are supported. // Only absolute paths are supported.
// NOTE: we only need this because this is an integration test and we don't want to install the app in the programs folder // NOTE: we only need this because this is an integration test and we don't want to install the app in the programs folder
// TODO mutate plugin config // TODO mutate plugin config
/*context updater = updater.installer_args(vec![format!(
.config_mut()
.tauri
.bundle
.updater
.windows
.installer_args = vec![format!(
"/D={}", "/D={}",
tauri::utils::platform::current_exe() tauri::utils::platform::current_exe()
.unwrap() .unwrap()
.parent() .parent()
.unwrap() .unwrap()
.display() .display()
)];*/ )]);
} }
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build()) .plugin(updater.build())
.setup(|app| { .setup(|app| {
let handle = app.handle(); let handle = app.handle();
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {

Loading…
Cancel
Save