Browse Source

refactor: use const instead of a function (#6958)

Amr Bashir 2 years ago
parent
commit
e0c30a7e8b

+ 2 - 2
.changes/add-tauri-get-version.md

@@ -1,5 +1,5 @@
 ---
-"tauri": "patch"
+'tauri': 'patch'
 ---
 
-Added `tauri::version` function to retrieve Tauri's version from Rust.
+Added `tauri::VERSION` const to get Tauri's version from Rust.

+ 1 - 1
core/tauri-config-schema/schema.json

@@ -221,7 +221,7 @@
           "pattern": "^[^/\\:*?\"<>|]+$"
         },
         "version": {
-          "description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field.",
+          "description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.",
           "default": null,
           "type": [
             "string",

+ 1 - 1
core/tauri/src/endpoints/app.rs

@@ -37,7 +37,7 @@ impl Cmd {
   }
 
   fn get_tauri_version<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Ok(env!("CARGO_PKG_VERSION"))
+    Ok(crate::VERSION)
   }
 
   #[module_command_handler(app_show)]

+ 3 - 5
core/tauri/src/lib.rs

@@ -264,6 +264,9 @@ pub use self::runtime::ClipboardManager;
 #[cfg_attr(doc_cfg, doc(cfg(feature = "global-shortcut")))]
 pub use self::runtime::GlobalShortcutManager;
 
+/// The Tauri version.
+pub const VERSION: &str = env!("CARGO_PKG_VERSION");
+
 /// Updater events.
 #[cfg(updater)]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "updater")))]
@@ -326,11 +329,6 @@ pub trait Runtime: runtime::Runtime<EventLoopMessage> {}
 
 impl<W: runtime::Runtime<EventLoopMessage>> Runtime for W {}
 
-/// Returns Tauri version.
-pub fn version() -> &'static str {
-  env!("CARGO_PKG_VERSION")
-}
-
 /// Reads the config file at compile time and generates a [`Context`] based on its content.
 ///
 /// The default config file path is a `tauri.conf.json` file inside the Cargo manifest directory of

+ 1 - 1
tooling/cli/schema.json

@@ -221,7 +221,7 @@
           "pattern": "^[^/\\:*?\"<>|]+$"
         },
         "version": {
-          "description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field.",
+          "description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.",
           "default": null,
           "type": [
             "string",