mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(os): add locale API (#391)
This commit is contained in:
committed by
GitHub
parent
5676e77209
commit
7e3034904c
@@ -1 +1 @@
|
||||
if("__TAURI__"in window){var __TAURI_OS__=function(n){"use strict";const _=navigator.appVersion.includes("Win")?"\r\n":"\n";return n.EOL=_,n.arch=async function(){return window.__TAURI_INVOKE__("plugin:os|arch")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.tempdir=async function(){return window.__TAURI_INVOKE__("plugin:os|tempdir")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|kind")},n.version=async function(){return window.__TAURI_INVOKE__("plugin:os|version")},n}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})}
|
||||
if("__TAURI__"in window){var __TAURI_OS__=function(n){"use strict";const _=navigator.appVersion.includes("Win")?"\r\n":"\n";return n.EOL=_,n.arch=async function(){return window.__TAURI_INVOKE__("plugin:os|arch")},n.locale=async function(){return window.__TAURI_INVOKE__("plugin:os|locale")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.tempdir=async function(){return window.__TAURI_INVOKE__("plugin:os|tempdir")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|kind")},n.version=async function(){return window.__TAURI_INVOKE__("plugin:os|version")},n}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})}
|
||||
|
||||
@@ -28,3 +28,8 @@ pub fn arch() -> &'static str {
|
||||
pub fn tempdir() -> PathBuf {
|
||||
crate::tempdir()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn locale() -> Option<String> {
|
||||
crate::locale()
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ pub fn tempdir() -> PathBuf {
|
||||
std::env::temp_dir()
|
||||
}
|
||||
|
||||
/// Returns the locale with the `BCP-47` language tag. If the locale couldn’t be obtained, `None` is returned instead.
|
||||
pub fn locale() -> Option<String> {
|
||||
sys_locale::get_locale()
|
||||
}
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("os")
|
||||
.js_init_script(include_str!("api-iife.js").to_string())
|
||||
@@ -76,7 +81,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
commands::version,
|
||||
commands::kind,
|
||||
commands::arch,
|
||||
commands::tempdir
|
||||
commands::tempdir,
|
||||
commands::locale
|
||||
])
|
||||
.build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user