mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
refactor(tauri-cli): remove trait implemented only once (#14840)
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::{
|
||||
config::{get_config, ConfigMetadata, FrontendDist},
|
||||
},
|
||||
info::plugins::check_mismatched_packages,
|
||||
interface::{rust::get_cargo_target_dir, AppInterface, Interface},
|
||||
interface::{rust::get_cargo_target_dir, AppInterface},
|
||||
ConfigValue, Result,
|
||||
};
|
||||
use clap::{ArgAction, Parser};
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::{
|
||||
config::{get_config, ConfigMetadata},
|
||||
updater_signature,
|
||||
},
|
||||
interface::{AppInterface, AppSettings, Interface},
|
||||
interface::{AppInterface, AppSettings},
|
||||
ConfigValue,
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
config::{get_config, reload_config, BeforeDevCommand, ConfigMetadata, FrontendDist},
|
||||
},
|
||||
info::plugins::check_mismatched_packages,
|
||||
interface::{AppInterface, ExitReason, Interface},
|
||||
interface::{AppInterface, ExitReason},
|
||||
CommandExt, ConfigValue, Error, Result,
|
||||
};
|
||||
|
||||
|
||||
@@ -30,10 +30,7 @@ use tauri_utils::config::HookCommand;
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use crate::Error;
|
||||
use crate::{
|
||||
interface::{AppInterface, Interface},
|
||||
CommandExt,
|
||||
};
|
||||
use crate::{interface::AppInterface, CommandExt};
|
||||
|
||||
pub fn command_env(debug: bool) -> HashMap<&'static str, String> {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::path::Path;
|
||||
use crate::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::interface::{AppInterface, AppSettings, Interface};
|
||||
use crate::interface::{AppInterface, AppSettings};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(about = "Inspect values used by Tauri")]
|
||||
|
||||
@@ -5,16 +5,11 @@
|
||||
pub mod rust;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
process::ExitStatus,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
error::Context, helpers::app_paths::Dirs, helpers::config::Config,
|
||||
helpers::config::ConfigMetadata,
|
||||
};
|
||||
use crate::{error::Context, helpers::config::Config};
|
||||
use tauri_bundler::bundle::{PackageType, Settings, SettingsBuilder};
|
||||
|
||||
pub use rust::{MobileOptions, Options, Rust as AppInterface, WatcherOptions};
|
||||
@@ -104,35 +99,3 @@ pub enum ExitReason {
|
||||
/// Regular exit.
|
||||
NormalExit,
|
||||
}
|
||||
|
||||
pub trait Interface: Sized {
|
||||
type AppSettings: AppSettings;
|
||||
|
||||
fn new(config: &Config, target: Option<String>, tauri_dir: &Path) -> crate::Result<Self>;
|
||||
fn app_settings(&self) -> Arc<Self::AppSettings>;
|
||||
fn env(&self) -> HashMap<&str, String>;
|
||||
fn build(&mut self, options: Options, dirs: &Dirs) -> crate::Result<PathBuf>;
|
||||
fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
config: &mut ConfigMetadata,
|
||||
options: Options,
|
||||
on_exit: F,
|
||||
dirs: &Dirs,
|
||||
) -> crate::Result<()>;
|
||||
fn mobile_dev<
|
||||
R: Fn(MobileOptions, &ConfigMetadata) -> crate::Result<Box<dyn DevProcess + Send>>,
|
||||
>(
|
||||
&mut self,
|
||||
config: &mut ConfigMetadata,
|
||||
options: MobileOptions,
|
||||
runner: R,
|
||||
dirs: &Dirs,
|
||||
) -> crate::Result<()>;
|
||||
fn watch<R: Fn(&ConfigMetadata) -> crate::Result<Box<dyn DevProcess + Send>>>(
|
||||
&mut self,
|
||||
config: &mut ConfigMetadata,
|
||||
options: WatcherOptions,
|
||||
runner: R,
|
||||
dirs: &Dirs,
|
||||
) -> crate::Result<()>;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use tauri_bundler::{
|
||||
};
|
||||
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol, RunnerConfig, Updater};
|
||||
|
||||
use super::{AppSettings, DevProcess, ExitReason, Interface};
|
||||
use super::{AppSettings, DevProcess, ExitReason};
|
||||
use crate::{
|
||||
error::{Context, Error, ErrorExt},
|
||||
helpers::{
|
||||
@@ -134,10 +134,8 @@ pub struct Rust {
|
||||
main_binary_name: Option<String>,
|
||||
}
|
||||
|
||||
impl Interface for Rust {
|
||||
type AppSettings = RustAppSettings;
|
||||
|
||||
fn new(config: &Config, target: Option<String>, tauri_dir: &Path) -> crate::Result<Self> {
|
||||
impl Rust {
|
||||
pub fn new(config: &Config, target: Option<String>, tauri_dir: &Path) -> crate::Result<Self> {
|
||||
let manifest = {
|
||||
let (tx, rx) = sync_channel(1);
|
||||
let mut watcher = new_debouncer(Duration::from_secs(1), None, move |r| {
|
||||
@@ -177,11 +175,11 @@ impl Interface for Rust {
|
||||
})
|
||||
}
|
||||
|
||||
fn app_settings(&self) -> Arc<Self::AppSettings> {
|
||||
pub fn app_settings(&self) -> Arc<RustAppSettings> {
|
||||
self.app_settings.clone()
|
||||
}
|
||||
|
||||
fn build(&mut self, options: Options, dirs: &Dirs) -> crate::Result<PathBuf> {
|
||||
pub fn build(&mut self, options: Options, dirs: &Dirs) -> crate::Result<PathBuf> {
|
||||
desktop::build(
|
||||
options,
|
||||
&self.app_settings,
|
||||
@@ -192,7 +190,7 @@ impl Interface for Rust {
|
||||
)
|
||||
}
|
||||
|
||||
fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
pub fn dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
|
||||
&mut self,
|
||||
config: &mut ConfigMetadata,
|
||||
mut options: Options,
|
||||
@@ -236,7 +234,7 @@ impl Interface for Rust {
|
||||
}
|
||||
}
|
||||
|
||||
fn mobile_dev<
|
||||
pub fn mobile_dev<
|
||||
R: Fn(MobileOptions, &ConfigMetadata) -> crate::Result<Box<dyn DevProcess + Send>>,
|
||||
>(
|
||||
&mut self,
|
||||
@@ -270,7 +268,7 @@ impl Interface for Rust {
|
||||
}
|
||||
}
|
||||
|
||||
fn watch<R: Fn(&ConfigMetadata) -> crate::Result<Box<dyn DevProcess + Send>>>(
|
||||
pub fn watch<R: Fn(&ConfigMetadata) -> crate::Result<Box<dyn DevProcess + Send>>>(
|
||||
&mut self,
|
||||
config: &mut ConfigMetadata,
|
||||
options: WatcherOptions,
|
||||
@@ -287,7 +285,7 @@ impl Interface for Rust {
|
||||
)
|
||||
}
|
||||
|
||||
fn env(&self) -> HashMap<&str, String> {
|
||||
pub fn env(&self) -> HashMap<&str, String> {
|
||||
let mut env = HashMap::new();
|
||||
env.insert(
|
||||
"TAURI_ENV_TARGET_TRIPLE",
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{detect_target_ok, ensure_init, env, get_app, get_config, read_option
|
||||
use crate::{
|
||||
error::{Context, ErrorExt},
|
||||
helpers::config::{get_config as get_tauri_config, reload_config as reload_tauri_config},
|
||||
interface::{AppInterface, Interface},
|
||||
interface::AppInterface,
|
||||
mobile::CliOptions,
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
config::{get_config as get_tauri_config, ConfigMetadata},
|
||||
flock,
|
||||
},
|
||||
interface::{AppInterface, Interface, Options as InterfaceOptions},
|
||||
interface::{AppInterface, Options as InterfaceOptions},
|
||||
mobile::{android::generate_tauri_properties, write_options, CliOptions, TargetDevice},
|
||||
ConfigValue, Error, Result,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::{
|
||||
config::{get_config as get_tauri_config, ConfigMetadata},
|
||||
flock,
|
||||
},
|
||||
interface::{AppInterface, Interface, MobileOptions, Options as InterfaceOptions},
|
||||
interface::{AppInterface, MobileOptions, Options as InterfaceOptions},
|
||||
mobile::{
|
||||
android::generate_tauri_properties, use_network_address_for_dev_url, write_options, CliOptions,
|
||||
DevChild, DevHost, DevProcess, TargetDevice,
|
||||
|
||||
@@ -14,7 +14,7 @@ use super::{configure_cargo, device_prompt, env};
|
||||
use crate::{
|
||||
error::Context,
|
||||
helpers::config::ConfigMetadata,
|
||||
interface::{DevProcess, Interface, WatcherOptions},
|
||||
interface::{DevProcess, WatcherOptions},
|
||||
mobile::{DevChild, TargetDevice},
|
||||
ConfigValue, Result,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{get_app, Target};
|
||||
use crate::{
|
||||
helpers::app_paths::Dirs,
|
||||
helpers::{config::get_config as get_tauri_config, template::JsonMap},
|
||||
interface::{AppInterface, Interface},
|
||||
interface::AppInterface,
|
||||
ConfigValue, Result,
|
||||
};
|
||||
use cargo_mobile2::{
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{
|
||||
flock,
|
||||
plist::merge_plist,
|
||||
},
|
||||
interface::{AppInterface, Interface, Options as InterfaceOptions},
|
||||
interface::{AppInterface, Options as InterfaceOptions},
|
||||
mobile::{ios::ensure_ios_runtime_installed, write_options, CliOptions, TargetDevice},
|
||||
ConfigValue, Error, Result,
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
flock,
|
||||
plist::merge_plist,
|
||||
},
|
||||
interface::{AppInterface, Interface, MobileOptions, Options as InterfaceOptions},
|
||||
interface::{AppInterface, MobileOptions, Options as InterfaceOptions},
|
||||
mobile::{
|
||||
ios::ensure_ios_runtime_installed, use_network_address_for_dev_url, write_options, CliOptions,
|
||||
DevChild, DevHost, DevProcess,
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::{device_prompt, env};
|
||||
use crate::{
|
||||
error::Context,
|
||||
helpers::config::{get_config as get_tauri_config, ConfigMetadata},
|
||||
interface::{DevProcess, Interface, WatcherOptions},
|
||||
interface::{DevProcess, WatcherOptions},
|
||||
mobile::{DevChild, TargetDevice},
|
||||
ConfigValue, Result,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{ensure_init, env, get_app, get_config, read_options, MobileTarget};
|
||||
use crate::{
|
||||
error::{Context, ErrorExt},
|
||||
helpers::config::{get_config as get_tauri_config, reload_config as reload_tauri_config},
|
||||
interface::{AppInterface, Interface, Options as InterfaceOptions},
|
||||
interface::{AppInterface, Options as InterfaceOptions},
|
||||
mobile::ios::LIB_OUTPUT_FILE_NAME,
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::{
|
||||
error::{Context, ErrorExt},
|
||||
helpers::config::{reload_config, Config as TauriConfig, ConfigMetadata},
|
||||
interface::{AppInterface, AppSettings, DevProcess, Interface, Options as InterfaceOptions},
|
||||
interface::{AppInterface, AppSettings, DevProcess, Options as InterfaceOptions},
|
||||
ConfigValue, Error, Result,
|
||||
};
|
||||
use heck::ToSnekCase;
|
||||
|
||||
Reference in New Issue
Block a user