Переглянути джерело

refactor(core): move `os` endpoints to a dedicated plugin (#6902)

Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
Lucas Fernandes Nogueira 2 роки тому
батько
коміт
29ce9ce2ce

+ 6 - 0
.changes/move-os.md

@@ -0,0 +1,6 @@
+---
+"api": patch
+"tauri": patch
+---
+
+Moved the `os` feature to its own plugin in the plugins-workspace repository.

+ 1 - 2
core/tauri/Cargo.toml

@@ -66,7 +66,6 @@ bytes = { version = "1", features = [ "serde" ] }
 raw-window-handle = "0.5"
 minisign-verify = { version = "0.2", optional = true }
 time = { version = "0.3", features = [ "parsing", "formatting" ], optional = true }
-os_info = { version = "3", optional = true }
 glob = "0.3"
 data-url = { version = "0.2", optional = true }
 serialize-to-javascript = "=0.1.1"
@@ -198,7 +197,7 @@ global-shortcut-all = [ ]
 http-all = [ "http-request" ]
 http-request = [ ]
 notification-all = [ ]
-os-all = [ "os_info" ]
+os-all = [ ]
 path-all = [ ]
 process-all = [ "process-relaunch", "process-exit" ]
 process-exit = [ ]

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
core/tauri/scripts/bundle.global.js


+ 0 - 11
core/tauri/src/endpoints.rs

@@ -13,8 +13,6 @@ use serde_json::Value as JsonValue;
 use std::sync::Arc;
 
 mod event;
-#[cfg(os_any)]
-mod operating_system;
 #[cfg(process_any)]
 mod process;
 mod window;
@@ -55,8 +53,6 @@ impl<T: Serialize> From<T> for InvokeResponse {
 enum Module {
   #[cfg(process_any)]
   Process(process::Cmd),
-  #[cfg(os_any)]
-  Os(operating_system::Cmd),
   Window(Box<window::Cmd>),
   Event(event::Cmd),
 }
@@ -82,13 +78,6 @@ impl Module {
           .and_then(|r| r.json)
           .map_err(InvokeError::from_anyhow)
       }),
-      #[cfg(os_any)]
-      Self::Os(cmd) => resolver.respond_async(async move {
-        cmd
-          .run(context)
-          .and_then(|r| r.json)
-          .map_err(InvokeError::from_anyhow)
-      }),
       Self::Window(cmd) => resolver.respond_async(async move {
         cmd
           .run(context)

+ 0 - 115
core/tauri/src/endpoints/operating_system.rs

@@ -1,115 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-#![allow(unused_imports)]
-
-use super::InvokeContext;
-use crate::Runtime;
-use serde::Deserialize;
-use std::path::PathBuf;
-use tauri_macros::{command_enum, module_command_handler, CommandModule};
-
-/// The API descriptor.
-#[command_enum]
-#[derive(Deserialize, CommandModule)]
-#[serde(tag = "cmd", rename_all = "camelCase")]
-pub enum Cmd {
-  Platform,
-  Version,
-  OsType,
-  Arch,
-  Tempdir,
-}
-
-#[cfg(os_all)]
-impl Cmd {
-  fn platform<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Ok(os_platform())
-  }
-
-  fn version<R: Runtime>(_context: InvokeContext<R>) -> super::Result<String> {
-    Ok(os_info::get().version().to_string())
-  }
-
-  fn os_type<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Ok(os_type())
-  }
-
-  fn arch<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Ok(std::env::consts::ARCH)
-  }
-
-  fn tempdir<R: Runtime>(_context: InvokeContext<R>) -> super::Result<PathBuf> {
-    Ok(std::env::temp_dir())
-  }
-}
-
-#[cfg(not(os_all))]
-impl Cmd {
-  fn platform<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Err(crate::Error::ApiNotAllowlisted("os > all".into()).into_anyhow())
-  }
-
-  fn version<R: Runtime>(_context: InvokeContext<R>) -> super::Result<String> {
-    Err(crate::Error::ApiNotAllowlisted("os > all".into()).into_anyhow())
-  }
-
-  fn os_type<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Err(crate::Error::ApiNotAllowlisted("os > all".into()).into_anyhow())
-  }
-
-  fn arch<R: Runtime>(_context: InvokeContext<R>) -> super::Result<&'static str> {
-    Err(crate::Error::ApiNotAllowlisted("os > all".into()).into_anyhow())
-  }
-
-  fn tempdir<R: Runtime>(_context: InvokeContext<R>) -> super::Result<PathBuf> {
-    Err(crate::Error::ApiNotAllowlisted("os > all".into()).into_anyhow())
-  }
-}
-
-#[cfg(os_all)]
-fn os_type() -> &'static str {
-  #[cfg(target_os = "linux")]
-  return "Linux";
-  #[cfg(target_os = "windows")]
-  return "Windows_NT";
-  #[cfg(target_os = "macos")]
-  return "Darwin";
-  #[cfg(target_os = "ios")]
-  return "iOS";
-  #[cfg(target_os = "android")]
-  return "Android";
-}
-
-#[cfg(os_all)]
-fn os_platform() -> &'static str {
-  match std::env::consts::OS {
-    "windows" => "win32",
-    "macos" => "darwin",
-    _ => std::env::consts::OS,
-  }
-}
-
-#[cfg(test)]
-mod tests {
-  #[tauri_macros::module_command_test(os_all, "os > all", runtime)]
-  #[quickcheck_macros::quickcheck]
-  fn platform() {}
-
-  #[tauri_macros::module_command_test(os_all, "os > all", runtime)]
-  #[quickcheck_macros::quickcheck]
-  fn version() {}
-
-  #[tauri_macros::module_command_test(os_all, "os > all", runtime)]
-  #[quickcheck_macros::quickcheck]
-  fn os_type() {}
-
-  #[tauri_macros::module_command_test(os_all, "os > all", runtime)]
-  #[quickcheck_macros::quickcheck]
-  fn arch() {}
-
-  #[tauri_macros::module_command_test(os_all, "os > all", runtime)]
-  #[quickcheck_macros::quickcheck]
-  fn tempdir() {}
-}

+ 1 - 5
examples/api/src/App.svelte

@@ -1,7 +1,6 @@
 <script>
   import { writable } from 'svelte/store'
   import { appWindow, getCurrent } from '@tauri-apps/api/window'
-  import * as os from '@tauri-apps/api/os'
 
   import Welcome from './views/Welcome.svelte'
   import Cli from './views/Cli.svelte'
@@ -154,10 +153,7 @@
     document.addEventListener('mousemove', moveHandler)
   }
 
-  let isWindows
-  onMount(async () => {
-    isWindows = (await os.platform()) === 'win32'
-  })
+  const isWindows = navigator.appVersion.includes('Win')
 
   // mobile
   let isSideBarOpen = false

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
tooling/api/docs/js-api.json


+ 1 - 2
tooling/api/src/index.ts

@@ -19,9 +19,8 @@ import * as process from './process'
 import * as tauri from './tauri'
 import * as updater from './updater'
 import * as window from './window'
-import * as os from './os'
 
 /** @ignore */
 const invoke = tauri.invoke
 
-export { invoke, event, path, process, tauri, updater, window, os }
+export { invoke, event, path, process, tauri, updater, window }

+ 0 - 164
tooling/api/src/os.ts

@@ -1,164 +0,0 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-/**
- * Provides operating system-related utility methods and properties.
- *
- * This package is also accessible with `window.__TAURI__.os` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
- *
- * The APIs must be added to [`tauri.allowlist.os`](https://tauri.app/v1/api/config/#allowlistconfig.os) in `tauri.conf.json`:
- * ```json
- * {
- *   "tauri": {
- *     "allowlist": {
- *       "os": {
- *         "all": true, // enable all Os APIs
- *       }
- *     }
- *   }
- * }
- * ```
- * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
- * @module
- */
-
-import { isWindows } from './helpers/os-check'
-import { invokeTauriCommand } from './helpers/tauri'
-
-type Platform =
-  | 'linux'
-  | 'darwin'
-  | 'ios'
-  | 'freebsd'
-  | 'dragonfly'
-  | 'netbsd'
-  | 'openbsd'
-  | 'solaris'
-  | 'android'
-  | 'win32'
-
-type OsType = 'Linux' | 'Darwin' | 'Windows_NT'
-
-type Arch =
-  | 'x86'
-  | 'x86_64'
-  | 'arm'
-  | 'aarch64'
-  | 'mips'
-  | 'mips64'
-  | 'powerpc'
-  | 'powerpc64'
-  | 'riscv64'
-  | 's390x'
-  | 'sparc64'
-
-/**
- * The operating system-specific end-of-line marker.
- * - `\n` on POSIX
- * - `\r\n` on Windows
- *
- * @since 1.0.0
- * */
-const EOL = isWindows() ? '\r\n' : '\n'
-
-/**
- * Returns a string identifying the operating system platform.
- * The value is set at compile time. Possible values are `'linux'`, `'darwin'`, `'ios'`, `'freebsd'`, `'dragonfly'`, `'netbsd'`, `'openbsd'`, `'solaris'`, `'android'`, `'win32'`
- * @example
- * ```typescript
- * import { platform } from '@tauri-apps/api/os';
- * const platformName = await platform();
- * ```
- *
- * @since 1.0.0
- *
- */
-async function platform(): Promise<Platform> {
-  return invokeTauriCommand<Platform>({
-    __tauriModule: 'Os',
-    message: {
-      cmd: 'platform'
-    }
-  })
-}
-
-/**
- * Returns a string identifying the kernel version.
- * @example
- * ```typescript
- * import { version } from '@tauri-apps/api/os';
- * const osVersion = await version();
- * ```
- *
- * @since 1.0.0
- */
-async function version(): Promise<string> {
-  return invokeTauriCommand<string>({
-    __tauriModule: 'Os',
-    message: {
-      cmd: 'version'
-    }
-  })
-}
-
-/**
- * Returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
- * @example
- * ```typescript
- * import { type } from '@tauri-apps/api/os';
- * const osType = await type();
- * ```
- *
- * @since 1.0.0
- */
-async function type(): Promise<OsType> {
-  return invokeTauriCommand<OsType>({
-    __tauriModule: 'Os',
-    message: {
-      cmd: 'osType'
-    }
-  })
-}
-
-/**
- * Returns the operating system CPU architecture for which the tauri app was compiled.
- * Possible values are `'x86'`, `'x86_64'`, `'arm'`, `'aarch64'`, `'mips'`, `'mips64'`, `'powerpc'`, `'powerpc64'`, `'riscv64'`, `'s390x'`, `'sparc64'`.
- * @example
- * ```typescript
- * import { arch } from '@tauri-apps/api/os';
- * const archName = await arch();
- * ```
- *
- * @since 1.0.0
- */
-async function arch(): Promise<Arch> {
-  return invokeTauriCommand<Arch>({
-    __tauriModule: 'Os',
-    message: {
-      cmd: 'arch'
-    }
-  })
-}
-
-/**
- * Returns the operating system's default directory for temporary files as a string.
- * @example
- * ```typescript
- * import { tempdir } from '@tauri-apps/api/os';
- * const tempdirPath = await tempdir();
- * ```
- *
- * @since 1.0.0
- */
-async function tempdir(): Promise<string> {
-  return invokeTauriCommand<string>({
-    __tauriModule: 'Os',
-    message: {
-      cmd: 'tempdir'
-    }
-  })
-}
-
-export { EOL, platform, version, type, arch, tempdir }
-export type { Platform, OsType, Arch }

Деякі файли не було показано, через те що забагато файлів було змінено