Skip to content

Commit

Permalink
refactor: rename tauri::dev to is_dev and mark as constant fn (#9890
Browse files Browse the repository at this point in the history
)

* refactor: made `tauri::dev` as constant function

this enables the `tauri::dev()` can be used as const or static

* is_dev && change files

---------

Co-authored-by: Amr Bashir <[email protected]>
  • Loading branch information
Rajaniraiyn and amrbashir committed May 27, 2024
1 parent 27fd8cc commit aaecb6a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/tauri-build-dev-fn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": "patch:breaking"
---

Renamed `dev` function to `is_dev`
5 changes: 5 additions & 0 deletions .changes/tauri-dev-fn-const.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:breaking"
---

Renamed `dev` function to `is_dev` and marked it as `const fn`
2 changes: 1 addition & 1 deletion core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl CodegenContext {
);

let code = context_codegen(ContextData {
dev: crate::dev(),
dev: crate::is_dev(),
config,
config_parent,
// it's very hard to have a build script for unit tests, so assume this is always called from
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl Attributes {
}
}

pub fn dev() -> bool {
pub fn is_dev() -> bool {
std::env::var("DEP_TAURI_DEV")
.expect("missing `cargo:dev` instruction, please update tauri to latest")
== "true"
Expand Down Expand Up @@ -474,7 +474,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
mobile::generate_gradle_files(project_dir, &config)?;
}

cfg_alias("dev", dev());
cfg_alias("dev", is_dev());

let ws_path = get_workspace_dir()?;
let mut manifest =
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ macro_rules! tauri_build_context {
pub use pattern::Pattern;

/// Whether we are running in development mode or not.
pub fn dev() -> bool {
pub const fn is_dev() -> bool {
!cfg!(feature = "custom-protocol")
}

Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<R: Runtime> AppManager<R> {
}

fn csp(&self) -> Option<Csp> {
if !crate::dev() {
if !crate::is_dev() {
self.config.app.security.csp.clone()
} else {
self
Expand Down

0 comments on commit aaecb6a

Please sign in to comment.