mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
refactor(cli): use temp file to communicate IPC websocket address (#6219)
This commit is contained in:
parent
481d9de739
commit
894a8d060c
6
.changes/cli-refactor-ipc-mobile.md
Normal file
6
.changes/cli-refactor-ipc-mobile.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"cli.rs": patch
|
||||||
|
"cli.js": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use temp file instead of environment variable to pass CLI IPC websocket address to the IDE.
|
@ -161,7 +161,8 @@ pub fn with_config<T>(
|
|||||||
let tauri_config = get_tauri_config(None)?;
|
let tauri_config = get_tauri_config(None)?;
|
||||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||||
let cli_options = cli_options.unwrap_or_else(read_options);
|
let cli_options =
|
||||||
|
cli_options.unwrap_or_else(|| read_options(&tauri_config_.tauri.bundle.identifier));
|
||||||
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
|
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
|
||||||
(app, config, metadata, cli_options)
|
(app, config, metadata, cli_options)
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
build::Options as BuildOptions,
|
build::Options as BuildOptions,
|
||||||
helpers::flock,
|
helpers::{config::get as get_config, flock},
|
||||||
interface::{AppSettings, Interface, Options as InterfaceOptions},
|
interface::{AppSettings, Interface, Options as InterfaceOptions},
|
||||||
mobile::{write_options, CliOptions},
|
mobile::{write_options, CliOptions},
|
||||||
Result,
|
Result,
|
||||||
@ -139,7 +139,17 @@ fn run_build(
|
|||||||
noise_level,
|
noise_level,
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
};
|
};
|
||||||
let _handle = write_options(cli_options, &mut env.base)?;
|
let _handle = write_options(
|
||||||
|
&get_config(options.config.as_deref())?
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.tauri
|
||||||
|
.bundle
|
||||||
|
.identifier,
|
||||||
|
cli_options,
|
||||||
|
)?;
|
||||||
|
|
||||||
options
|
options
|
||||||
.features
|
.features
|
||||||
|
@ -4,7 +4,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::Options as DevOptions,
|
dev::Options as DevOptions,
|
||||||
helpers::flock,
|
helpers::{config::get as get_config, flock},
|
||||||
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
|
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
|
||||||
mobile::{write_options, CliOptions, DevChild, DevProcess},
|
mobile::{write_options, CliOptions, DevChild, DevProcess},
|
||||||
Result,
|
Result,
|
||||||
@ -148,14 +148,23 @@ fn run_dev(
|
|||||||
no_watch: options.no_watch,
|
no_watch: options.no_watch,
|
||||||
},
|
},
|
||||||
|options| {
|
|options| {
|
||||||
let mut env = env.clone();
|
|
||||||
let cli_options = CliOptions {
|
let cli_options = CliOptions {
|
||||||
features: options.features.clone(),
|
features: options.features.clone(),
|
||||||
args: options.args.clone(),
|
args: options.args.clone(),
|
||||||
noise_level,
|
noise_level,
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
};
|
};
|
||||||
let _handle = write_options(cli_options, &mut env.base)?;
|
let _handle = write_options(
|
||||||
|
&get_config(options.config.as_deref())?
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.tauri
|
||||||
|
.bundle
|
||||||
|
.identifier,
|
||||||
|
cli_options,
|
||||||
|
)?;
|
||||||
|
|
||||||
if open {
|
if open {
|
||||||
open_and_wait(config, &env)
|
open_and_wait(config, &env)
|
||||||
|
@ -149,7 +149,8 @@ fn with_config<T>(
|
|||||||
let tauri_config = get_tauri_config(None)?;
|
let tauri_config = get_tauri_config(None)?;
|
||||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||||
let cli_options = cli_options.unwrap_or_else(read_options);
|
let cli_options =
|
||||||
|
cli_options.unwrap_or_else(|| read_options(&tauri_config_.tauri.bundle.identifier));
|
||||||
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
|
let (app, config, metadata) = get_config(None, tauri_config_, &cli_options);
|
||||||
(app, config, metadata, cli_options)
|
(app, config, metadata, cli_options)
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
build::Options as BuildOptions,
|
build::Options as BuildOptions,
|
||||||
helpers::flock,
|
helpers::{config::get as get_config, flock},
|
||||||
interface::{AppSettings, Interface, Options as InterfaceOptions},
|
interface::{AppSettings, Interface, Options as InterfaceOptions},
|
||||||
mobile::{write_options, CliOptions},
|
mobile::{write_options, CliOptions},
|
||||||
Result,
|
Result,
|
||||||
@ -122,7 +122,17 @@ fn run_build(
|
|||||||
noise_level,
|
noise_level,
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
};
|
};
|
||||||
let _handle = write_options(cli_options, env)?;
|
let _handle = write_options(
|
||||||
|
&get_config(options.config.as_deref())?
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.tauri
|
||||||
|
.bundle
|
||||||
|
.identifier,
|
||||||
|
cli_options,
|
||||||
|
)?;
|
||||||
|
|
||||||
options
|
options
|
||||||
.features
|
.features
|
||||||
|
@ -4,7 +4,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::Options as DevOptions,
|
dev::Options as DevOptions,
|
||||||
helpers::flock,
|
helpers::{config::get as get_config, flock},
|
||||||
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
|
interface::{AppSettings, Interface, MobileOptions, Options as InterfaceOptions},
|
||||||
mobile::{write_options, CliOptions, DevChild, DevProcess},
|
mobile::{write_options, CliOptions, DevChild, DevProcess},
|
||||||
Result,
|
Result,
|
||||||
@ -156,14 +156,23 @@ fn run_dev(
|
|||||||
no_watch: options.no_watch,
|
no_watch: options.no_watch,
|
||||||
},
|
},
|
||||||
|options| {
|
|options| {
|
||||||
let mut env = env.clone();
|
|
||||||
let cli_options = CliOptions {
|
let cli_options = CliOptions {
|
||||||
features: options.features.clone(),
|
features: options.features.clone(),
|
||||||
args: options.args.clone(),
|
args: options.args.clone(),
|
||||||
noise_level,
|
noise_level,
|
||||||
vars: Default::default(),
|
vars: Default::default(),
|
||||||
};
|
};
|
||||||
let _handle = write_options(cli_options, &mut env)?;
|
let _handle = write_options(
|
||||||
|
&get_config(options.config.as_deref())?
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.tauri
|
||||||
|
.bundle
|
||||||
|
.identifier,
|
||||||
|
cli_options,
|
||||||
|
)?;
|
||||||
|
|
||||||
if open {
|
if open {
|
||||||
open_and_wait(config, &env)
|
open_and_wait(config, &env)
|
||||||
|
@ -22,11 +22,10 @@ use shared_child::SharedChild;
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
env::set_var,
|
env::{set_var, temp_dir},
|
||||||
env::var,
|
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
fmt::Write,
|
fmt::Write,
|
||||||
fs::{create_dir_all, remove_dir_all},
|
fs::{create_dir_all, read_to_string, remove_dir_all, write},
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::ExitStatus,
|
process::ExitStatus,
|
||||||
@ -196,8 +195,8 @@ fn env() -> Result<Env, EnvError> {
|
|||||||
|
|
||||||
/// Writes CLI options to be used later on the Xcode and Android Studio build commands
|
/// Writes CLI options to be used later on the Xcode and Android Studio build commands
|
||||||
pub fn write_options(
|
pub fn write_options(
|
||||||
|
identifier: &str,
|
||||||
mut options: CliOptions,
|
mut options: CliOptions,
|
||||||
env: &mut Env,
|
|
||||||
) -> crate::Result<(Runtime, ServerHandle)> {
|
) -> crate::Result<(Runtime, ServerHandle)> {
|
||||||
options.vars.extend(env_vars());
|
options.vars.extend(env_vars());
|
||||||
|
|
||||||
@ -215,12 +214,15 @@ pub fn write_options(
|
|||||||
});
|
});
|
||||||
let (handle, addr) = r?;
|
let (handle, addr) = r?;
|
||||||
|
|
||||||
env.insert_env_var("TAURI_OPTIONS_SERVER_ADDR".into(), addr.to_string().into());
|
write(
|
||||||
|
temp_dir().join(format!("{identifier}-server-addr")),
|
||||||
|
addr.to_string(),
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok((runtime, handle))
|
Ok((runtime, handle))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_options() -> CliOptions {
|
fn read_options(identifier: &str) -> CliOptions {
|
||||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||||
let options = runtime
|
let options = runtime
|
||||||
.block_on(async move {
|
.block_on(async move {
|
||||||
@ -228,7 +230,8 @@ fn read_options() -> CliOptions {
|
|||||||
.build(
|
.build(
|
||||||
format!(
|
format!(
|
||||||
"ws://{}",
|
"ws://{}",
|
||||||
var("TAURI_OPTIONS_SERVER_ADDR").expect("missing addr environment variable")
|
read_to_string(temp_dir().join(format!("{identifier}-server-addr")))
|
||||||
|
.expect("missing addr file")
|
||||||
)
|
)
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
Loading…
Reference in New Issue
Block a user