Skip to content

Commit 26eb17d

Browse files
authored
refactor: remove the mobile argument (#748)
* refactor: remove the mobile argument when using the `--rc` flag, we'll always generate a cross platform app (supporting both desktop and mobile) * fix vanilla template
1 parent d34ff53 commit 26eb17d

23 files changed

Lines changed: 42 additions & 101 deletions

File tree

.changes/remove-mobile-arg.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-tauri-app": minor
3+
"create-tauri-app-js": minor
4+
---
5+
6+
Removed the `--mobile` and `--no-mobile` arguments. When using `--rc` we will always generate a template that supports both desktop and mobile using Tauri v2.

src/args.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub struct Args {
1616
pub skip: bool,
1717
pub force: bool,
1818
pub rc: bool,
19-
pub mobile: Option<bool>,
20-
pub no_mobile: Option<bool>,
2119
}
2220

2321
impl Default for Args {
@@ -29,8 +27,6 @@ impl Default for Args {
2927
skip: false,
3028
force: false,
3129
rc: false,
32-
mobile: Some(false), // default for this value must be Some(false), as we use it as fallback when -y is used
33-
no_mobile: None,
3430
}
3531
}
3632
}
@@ -57,8 +53,6 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
5753
{GREEN}-y{RESET}, {GREEN}--yes{RESET} Skip prompts and use defaults where applicable
5854
{GREEN}-f{RESET}, {GREEN}--force{RESET} Force create the directory even if it is not empty.
5955
{GREEN}--rc{RESET} Bootstraps a project using tauri@2.0-rc.
60-
{GREEN}--mobile{RESET} Bootstraps a mobile project too. Only availabe with `--rc` option.
61-
{GREEN}--no-mobile{RESET} Skip bootstraping a mobile project. Only availabe with `--rc` option.
6256
{GREEN}-h{RESET}, {GREEN}--help{RESET} Prints help information
6357
{GREEN}-v{RESET}, {GREEN}--version{RESET} Prints version information
6458
"#,
@@ -107,16 +101,6 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
107101
skip: pargs.contains(["-y", "--yes"]),
108102
force: pargs.contains(["-f", "--force"]),
109103
rc,
110-
mobile: if pargs.contains("--mobile") {
111-
Some(true)
112-
} else {
113-
None
114-
},
115-
no_mobile: if pargs.contains("--no-mobile") {
116-
Some(true)
117-
} else {
118-
None
119-
},
120104
project_name: pargs.opt_free_from_str()?,
121105
};
122106

src/lib.rs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ where
6666
let defaults = args::Args::default();
6767
let args::Args {
6868
skip,
69-
mut mobile,
70-
no_mobile,
7169
rc,
7270
manager,
7371
project_name,
@@ -76,18 +74,6 @@ where
7674
} = args;
7775
let cwd = std::env::current_dir()?;
7876

79-
// Allow `--mobile` to only be used with `--rc` for now
80-
// TODO: remove this limitation once tauri@v2 is stable
81-
if (mobile.is_some() || no_mobile.is_some()) && !rc {
82-
let flag = if mobile.is_some() {
83-
"--mobile"
84-
} else {
85-
"--no-mobile"
86-
};
87-
eprintln!("{BOLD}{RED}error{RESET}: `{GREEN}{}{RESET}` option is only available if `{GREEN}--rc{RESET}` option is also used", flag);
88-
exit(1);
89-
}
90-
9177
// Project name used for the project directory name and productName in tauri.conf.json
9278
// and if valid, it will also be used in Cargo.toml, Package.json ...etc
9379
let project_name = match project_name {
@@ -281,28 +267,6 @@ where
281267
}
282268
};
283269

284-
// if --no-mobile is specified, ignore --mobile and force it to fale
285-
if no_mobile.is_some() {
286-
mobile = Some(false);
287-
};
288-
289-
// Prompt for wether to bootstrap a mobile-friendly tauri project
290-
// This should only be prompted if `--rc` is used on the command line and `--mobile` wasn't.
291-
// TODO: remove this limitation once tauri@v2 is stable
292-
let mobile = match mobile {
293-
Some(mobile) => mobile,
294-
None => {
295-
if skip || !rc {
296-
defaults.mobile.context("default mobile not set")?
297-
} else {
298-
Confirm::with_theme(&ColorfulTheme::default())
299-
.with_prompt("Would you like to setup the project for mobile as well?")
300-
.default(false)
301-
.interact()?
302-
}
303-
}
304-
};
305-
306270
// If the package manager and the template are specified on the command line
307271
// then almost all prompts are skipped so we need to make sure that the combination
308272
// is valid, otherwise, we error and exit
@@ -339,14 +303,7 @@ where
339303
}
340304

341305
// Render the template
342-
template.render(
343-
&target_dir,
344-
pkg_manager,
345-
&project_name,
346-
&package_name,
347-
rc,
348-
mobile,
349-
)?;
306+
template.render(&target_dir, pkg_manager, &project_name, &package_name, rc)?;
350307

351308
// Print post-render instructions
352309
println!();
@@ -370,7 +327,7 @@ where
370327
if let Some(cmd) = pkg_manager.install_cmd() {
371328
println!(" {cmd}");
372329
}
373-
if !mobile {
330+
if !rc {
374331
println!(" {} tauri dev", pkg_manager.run_cmd());
375332
} else {
376333
println!(" {} tauri android init", pkg_manager.run_cmd());

src/template.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,14 @@ impl<'a> Template {
257257
project_name: &str,
258258
package_name: &str,
259259
rc: bool,
260-
mobile: bool,
261260
) -> anyhow::Result<()> {
262261
let manifest_bytes =
263262
EMBEDDED_TEMPLATES::get(&format!("template-{self}/{CTA_MANIFEST_FILENAME}"))
264263
.with_context(|| "Failed to get manifest bytes")?
265264
.data
266265
.to_vec();
267266
let manifest_str = String::from_utf8(manifest_bytes)?;
268-
let manifest = Manifest::parse(&manifest_str, mobile)?;
267+
let manifest = Manifest::parse(&manifest_str, rc)?;
269268

270269
let lib_name = format!("{}_lib", package_name.replace('-', "_"));
271270
let project_name_pascal_case = Self::transform_to_pascal_case(project_name.to_string());
@@ -299,7 +298,6 @@ impl<'a> Template {
299298
let template_data: HashMap<&str, String> = [
300299
("stable", (!rc).to_string()),
301300
("rc", rc_str.clone()),
302-
("mobile", mobile.to_string()),
303301
("project_name", project_name.to_string()),
304302
(
305303
"project_name_pascal_case",
@@ -376,7 +374,7 @@ impl<'a> Template {
376374
// conditional files:
377375
// are files that start with a special syntax
378376
// "%(<list of flags separated by `-`>%)<file_name>"
379-
// flags are supported package managers, stable, rc and mobile.
377+
// flags are supported package managers, stable and rc.
380378
// example: "%(pnpm-npm-yarn-stable-rc)%package.json"
381379
name if name.starts_with("%(") && name[1..].contains(")%") => {
382380
let mut s = name.strip_prefix("%(").unwrap().split(")%");
@@ -387,15 +385,11 @@ impl<'a> Template {
387385

388386
let for_stable = flags.contains(&"stable");
389387
let for_rc = flags.contains(&"rc");
390-
let for_mobile = flags.contains(&"mobile");
391388

392389
// remove these flags to only keep package managers flags
393-
flags.retain(|e| !["stable", "rc", "mobile"].contains(e));
390+
flags.retain(|e| !["stable", "rc"].contains(e));
394391

395-
if ((for_stable && !rc)
396-
|| (for_rc && rc && !mobile)
397-
|| (for_mobile && rc && mobile)
398-
|| (!for_stable && !for_rc && !for_mobile))
392+
if ((for_stable && !rc) || (for_rc && rc) || (!for_stable && !for_rc))
399393
&& (flags.contains(&pkg_manager.to_string().as_str()) || flags.is_empty())
400394
{
401395
name

templates/_base_/src-tauri/%(rc-mobile)%tauri.conf.json.lte renamed to templates/_base_/src-tauri/%(rc)%tauri.conf.json.lte

File renamed without changes.

templates/_base_/src-tauri/Cargo.toml.lte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

10-
{% if mobile %}[lib]
10+
{% if rc %}[lib]
1111
name = "{% lib_name %}"
1212
crate-type = ["lib", "cdylib", "staticlib"]
1313

templates/_base_/src-tauri/capabilities/%(rc-mobile)%default.json.lte renamed to templates/_base_/src-tauri/capabilities/%(rc)%default.json.lte

File renamed without changes.
File renamed without changes.

templates/_base_/src-tauri/src/main.rs.lte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

4-
{% if mobile %}fn main() {
4+
{% if rc %}fn main() {
55
{% lib_name %}::run()
66
}{% else %}// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
77
#[tauri::command]

templates/template-leptos/Trunk.toml.lte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ target = "./index.html"
55
ignore = ["./src-tauri"]
66

77
[serve]
8-
address = "{% if mobile %}0.0.0.0{% else %}127.0.0.1{% endif %}"
8+
address = "{% if rc %}0.0.0.0{% else %}127.0.0.1{% endif %}"
99
port = 1420
10-
open = false{% if mobile %}
10+
open = false{% if rc %}
1111
ws_protocol = "ws"{% endif %}

0 commit comments

Comments
 (0)