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]
pub fn tauri_version() -> &'static str {
// TODO: return actual tauri version with `tauri::VERSION`
env!("CARGO_PKG_VERSION")
tauri::VERSION
}
#[tauri::command]

@ -11,12 +11,11 @@ use config::{Arg, Config};
pub use error::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>, AppHandle<R>);
pub struct Cli<R: Runtime>(PluginApi<R, Config>);
impl<R: Runtime> Cli<R> {
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")
.invoke_handler(tauri::generate_handler![cli_matches])
.setup(|app, api| {
app.manage(Cli(api, app.clone()));
app.manage(Cli(api));
Ok(())
})
.build()

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

@ -25,6 +25,7 @@ struct PendingUpdate<R: Runtime>(Mutex<Option<UpdateResponse<R>>>);
#[derive(Default)]
pub struct Builder {
target: Option<String>,
installer_args: Option<Vec<String>>,
}
/// Extension trait to use the updater on [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`].
@ -63,14 +64,26 @@ impl Builder {
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> {
let target = self.target;
let installer_args = self.installer_args;
PluginBuilder::<R, Config>::new("updater")
.setup(move |app, api| {
app.manage(UpdaterState {
target,
config: api.config().clone(),
});
let mut config = api.config().clone();
if let Some(installer_args) = installer_args {
config.installer_args = installer_args;
}
app.manage(UpdaterState { target, config });
app.manage(PendingUpdate::<R>(Default::default()));
Ok(())
})

@ -9,6 +9,8 @@ use tauri_plugin_updater::UpdaterExt;
fn main() {
#[allow(unused_mut)]
let mut context = tauri::generate_context!();
let mut updater = tauri_plugin_updater::Builder::new();
if std::env::var("TARGET").unwrap_or_default() == "nsis" {
// /D sets the default installation directory ($INSTDIR),
// overriding InstallDir and InstallDirRegKey.
@ -16,23 +18,18 @@ fn main() {
// 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
// TODO mutate plugin config
/*context
.config_mut()
.tauri
.bundle
.updater
.windows
.installer_args = vec![format!(
updater = updater.installer_args(vec![format!(
"/D={}",
tauri::utils::platform::current_exe()
.unwrap()
.parent()
.unwrap()
.display()
)];*/
)]);
}
tauri::Builder::default()
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(updater.build())
.setup(|app| {
let handle = app.handle();
tauri::async_runtime::spawn(async move {

Loading…
Cancel
Save