Selaa lähdekoodia

feat(core): add `tauri-wry` crate (#1756)

Lucas Fernandes Nogueira 4 vuotta sitten
vanhempi
sitoutus
45a7a111e0

+ 13 - 3
.changes/config.json

@@ -220,7 +220,16 @@
       "dependencies": [
         "tauri-utils"
       ],
-      "postversion": "node ../../.scripts/sync-prerelease.js ${ release.type }"
+      "postversion": "node ../../.scripts/sync-prerelease.js ${ pkg.pkg } ${ release.type }"
+    },
+    "tauri-runtime-wry": {
+      "path": "./core/tauri-runtime-wry",
+      "manager": "rust",
+      "dependencies": [
+        "tauri-utils",
+        "tauri-runtime"
+      ],
+      "postversion": "node ../../.scripts/sync-prerelease.js ${ pkg.pkg } ${ release.type }"
     },
     "tauri-codegen": {
       "path": "./core/tauri-codegen",
@@ -250,7 +259,8 @@
       "dependencies": [
         "tauri-macros",
         "tauri-utils",
-        "tauri-runtime"
+        "tauri-runtime",
+        "tauri-runtime-wry"
       ],
       "postversion": "node ../../.scripts/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
     },
@@ -285,4 +295,4 @@
       "manager": "javascript"
     }
   }
-}
+}

+ 1 - 1
.changes/runtime-crate.md

@@ -1,5 +1,5 @@
 ---
-"tauri-runtime": patch
+"tauri-runtime": minor
 "tauri": patch
 ---
 

+ 6 - 0
.changes/tauri-wry.md

@@ -0,0 +1,6 @@
+---
+"tauri": patch
+"tauri-runtime-wry": minor
+---
+
+`tauri-runtime-wry` initial release.

+ 20 - 7
.scripts/sync-prerelease.js

@@ -10,15 +10,28 @@ keep the `tauri-release` crate version without the `beta` or `beta-rc` suffix.
 
 const { readFileSync, writeFileSync } = require("fs")
 
-const runtimeManifestPath = '../../core/tauri-runtime/Cargo.toml'
-const dependencyManifestPaths = ['../../core/tauri/Cargo.toml']
-const changelogPath = '../../core/tauri-runtime/CHANGELOG.md'
+const packageNickname = process.argv[2]
+const bump = process.argv[3]
 
-const bump = process.argv[2]
+let manifestPath
+let dependencyManifestPaths
+let changelogPath
 
-let runtimeManifest = readFileSync(runtimeManifestPath, "utf-8")
-runtimeManifest = runtimeManifest.replace(/version = "(\d+\.\d+\.\d+)-[^0-9\.]+\.0"/, 'version = "$1"')
-writeFileSync(runtimeManifestPath, runtimeManifest)
+if (packageNickname === 'tauri-runtime') {
+  manifestPath = '../../core/tauri-runtime/Cargo.toml'
+  dependencyManifestPaths = ['../../core/tauri/Cargo.toml', '../../core/tauri-runtime-wry/Cargo.toml']
+  changelogPath = '../../core/tauri-runtime/CHANGELOG.md'
+} else if (packageNickname === 'tauri-runtime-wry') {
+  manifestPath = '../../core/tauri-runtime-wry/Cargo.toml'
+  dependencyManifestPaths = ['../../core/tauri/Cargo.toml']
+  changelogPath = '../../core/tauri-runtime-wry/CHANGELOG.md'
+} else {
+  throw new Error(`Unexpected package ${packageNickname}`)
+}
+
+let manifest = readFileSync(manifestPath, "utf-8")
+manifest = manifest.replace(/version = "(\d+\.\d+\.\d+)-[^0-9\.]+\.0"/, 'version = "$1"')
+writeFileSync(manifestPath, manifest)
 
 let changelog = readFileSync(changelogPath, "utf-8")
 changelog = changelog.replace(/(\d+\.\d+\.\d+)-[^0-9\.]+\.0/, '$1')

+ 1 - 0
Cargo.toml

@@ -3,6 +3,7 @@ members = [
   # core
   "core/tauri",
   "core/tauri-runtime",
+  "core/tauri-runtime-wry",
   "core/tauri-macros",
   "core/tauri-utils",
   "core/tauri-build",

+ 3 - 0
core/tauri-runtime-wry/.license_template

@@ -0,0 +1,3 @@
+// Copyright {20\d{2}(-20\d{2})?} Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT

+ 17 - 0
core/tauri-runtime-wry/Cargo.toml

@@ -0,0 +1,17 @@
+[package]
+name = "tauri-runtime-wry"
+version = "0.0.0"
+authors = [ "Tauri Programme within The Commons Conservancy" ]
+categories = [ "gui", "web-programming" ]
+license = "Apache-2.0 OR MIT"
+homepage = "https://tauri.studio"
+repository = "https://github.com/tauri-apps/tauri"
+description = "Wry bindings to the Tauri runtime"
+edition = "2018"
+
+[dependencies]
+wry = { git = "https://github.com/tauri-apps/wry", rev = "6bc97aff525644b83a3a00537316c46d7afb985b" }
+tauri-runtime = { version = "0.0.0", path = "../tauri-runtime" }
+tauri-utils = { version = "1.0.0-beta-rc.1", path = "../tauri-utils" }
+image = "0.23"
+uuid = { version = "0.8.2", features = [ "v4" ] }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 282 - 213
core/tauri-runtime-wry/src/lib.rs


+ 3 - 0
core/tauri-runtime/.license_template

@@ -0,0 +1,3 @@
+// Copyright {20\d{2}(-20\d{2})?} Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT

+ 1 - 3
core/tauri-runtime/Cargo.toml

@@ -13,7 +13,5 @@ edition = "2018"
 serde = { version = "1.0", features = [ "derive" ] }
 serde_json = "1.0"
 thiserror = "1.0"
-uuid = { version = "0.8.2", features = [ "v4" ] }
 tauri-utils = { version = "1.0.0-beta-rc.1", path = "../tauri-utils" }
-wry = { git = "https://github.com/tauri-apps/wry", rev = "6bc97aff525644b83a3a00537316c46d7afb985b" }
-image = "0.23"
+uuid = { version = "0.8.2", features = [ "v4" ] }

+ 0 - 7
core/tauri-runtime/src/flavors/mod.rs

@@ -1,7 +0,0 @@
-// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
-//! Officially supported webview runtimes.
-
-pub mod wry;

+ 0 - 1
core/tauri-runtime/src/lib.rs

@@ -9,7 +9,6 @@ use std::path::PathBuf;
 use tauri_utils::assets::Assets;
 use uuid::Uuid;
 
-pub mod flavors;
 /// Create window and system tray menus.
 pub mod menu;
 /// Types useful for interacting with a user's monitors.

+ 9 - 29
core/tauri-runtime/src/monitor.rs

@@ -3,37 +3,17 @@
 // SPDX-License-Identifier: MIT
 
 use super::window::dpi::{PhysicalPosition, PhysicalSize};
-use serde::Serialize;
 
 /// Monitor descriptor.
-#[derive(Debug, Clone, Serialize)]
-#[serde(rename_all = "camelCase")]
+#[derive(Debug, Clone)]
 pub struct Monitor {
-  pub(crate) name: Option<String>,
-  pub(crate) size: PhysicalSize<u32>,
-  pub(crate) position: PhysicalPosition<i32>,
-  pub(crate) scale_factor: f64,
-}
-
-impl Monitor {
-  /// Returns a human-readable name of the monitor.
-  /// Returns None if the monitor doesn't exist anymore.
-  pub fn name(&self) -> Option<&String> {
-    self.name.as_ref()
-  }
-
-  /// Returns the monitor's resolution.
-  pub fn size(&self) -> &PhysicalSize<u32> {
-    &self.size
-  }
-
-  /// Returns the top-left corner position of the monitor relative to the larger full screen area.
-  pub fn position(&self) -> &PhysicalPosition<i32> {
-    &self.position
-  }
-
+  /// A human-readable name of the monitor.
+  /// `None` if the monitor doesn't exist anymore.
+  pub name: Option<String>,
+  /// The monitor's resolution.
+  pub size: PhysicalSize<u32>,
+  /// The top-left corner position of the monitor relative to the larger full screen area.
+  pub position: PhysicalPosition<i32>,
   /// Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
-  pub fn scale_factor(&self) -> f64 {
-    self.scale_factor
-  }
+  pub scale_factor: f64,
 }

+ 0 - 1
core/tauri-runtime/src/window.rs

@@ -39,7 +39,6 @@ pub enum WindowEvent {
   /// - Changing the display's resolution.
   /// - Changing the display's scale factor (e.g. in Control Panel on Windows).
   /// - Moving the window to a display with a different scale factor.
-  #[non_exhaustive]
   ScaleFactorChanged {
     /// The new scale factor.
     scale_factor: f64,

+ 3 - 0
core/tauri/Cargo.toml

@@ -25,6 +25,7 @@ once_cell = "1.7.2"
 tauri-runtime = { version = "0.0.0", path = "../tauri-runtime" }
 tauri-macros = { version = "1.0.0-beta-rc.1", path = "../tauri-macros" }
 tauri-utils = { version = "1.0.0-beta-rc.1", path = "../tauri-utils" }
+tauri-runtime-wry = { version = "0.0.0", path = "../tauri-runtime-wry", optional = true }
 rand = "0.8"
 reqwest = { version = "0.11", features = [ "json", "multipart" ] }
 tempfile = "3"
@@ -64,6 +65,8 @@ tokio-test = "0.4.1"
 mockito = "0.30"
 
 [features]
+default = ["wry"]
+wry = ["tauri-runtime-wry"]
 cli = [ "clap" ]
 custom-protocol = [ "tauri-macros/custom-protocol" ]
 api-all = [ "notification-all", "global-shortcut-all", "updater" ]

+ 9 - 2
core/tauri/src/app.rs

@@ -9,7 +9,6 @@ use crate::{
   manager::{Args, WindowManager},
   plugin::{Plugin, PluginStore},
   runtime::{
-    flavors::wry::Wry,
     menu::{Menu, MenuId, SystemTrayMenuItem},
     tag::Tag,
     webview::{CustomProtocol, WebviewAttributes, WindowBuilder},
@@ -511,7 +510,15 @@ fn get_menu_ids<I: MenuId>(items: &[SystemTrayMenuItem<I>]) -> HashMap<u32, I> {
 }
 
 /// Make `Wry` the default `Runtime` for `Builder`
-impl<A: Assets> Default for Builder<String, String, String, String, A, Wry> {
+#[cfg(feature = "wry")]
+impl<A: Assets> Default for Builder<String, String, String, String, A, crate::Wry> {
+  fn default() -> Self {
+    Self::new()
+  }
+}
+
+#[cfg(not(feature = "wry"))]
+impl<A: Assets, R: Runtime> Default for Builder<String, String, String, String, A, R> {
   fn default() -> Self {
     Self::new()
   }

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

@@ -36,6 +36,9 @@ mod state;
 #[cfg(feature = "updater")]
 pub mod updater;
 
+#[cfg(feature = "wry")]
+pub use tauri_runtime_wry::Wry;
+
 /// `Result<T, ::tauri::Error>`
 pub type Result<T> = std::result::Result<T, Error>;
 
@@ -59,9 +62,7 @@ pub use {
     PageLoadPayload, SetupHook,
   },
   self::runtime::{
-    flavors::wry::Wry,
     menu::{CustomMenuItem, Menu, MenuId, MenuItem, SystemTrayMenuItem},
-    monitor::Monitor,
     tag::{Tag, TagRef},
     webview::{WebviewAttributes, WindowBuilder},
     window::{
@@ -71,7 +72,7 @@ pub use {
     Params,
   },
   self::state::{State, StateManager},
-  self::window::{MenuEvent, Window},
+  self::window::{MenuEvent, Monitor, Window},
   tauri_utils::platform,
 };
 

+ 1 - 1
core/tauri/src/manager.rs

@@ -453,7 +453,7 @@ impl<P: Params> WindowManager<P> {
 #[cfg(test)]
 mod test {
   use super::{Args, WindowManager};
-  use crate::{generate_context, plugin::PluginStore, runtime::flavors::wry::Wry, StateManager};
+  use crate::{generate_context, plugin::PluginStore, StateManager, Wry};
 
   #[test]
   fn check_get_url() {

+ 58 - 3
core/tauri/src/window.rs

@@ -9,7 +9,7 @@ use crate::{
   manager::WindowManager,
   runtime::{
     menu::MenuId,
-    monitor::Monitor,
+    monitor::Monitor as RuntimeMonitor,
     tag::{TagRef, ToJsString},
     webview::{InvokePayload, WebviewAttributes, WindowBuilder},
     window::{
@@ -44,6 +44,50 @@ impl<I: MenuId> MenuEvent<I> {
   }
 }
 
+/// Monitor descriptor.
+#[derive(Debug, Clone, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct Monitor {
+  pub(crate) name: Option<String>,
+  pub(crate) size: PhysicalSize<u32>,
+  pub(crate) position: PhysicalPosition<i32>,
+  pub(crate) scale_factor: f64,
+}
+
+impl From<RuntimeMonitor> for Monitor {
+  fn from(monitor: RuntimeMonitor) -> Self {
+    Self {
+      name: monitor.name,
+      size: monitor.size,
+      position: monitor.position,
+      scale_factor: monitor.scale_factor,
+    }
+  }
+}
+
+impl Monitor {
+  /// Returns a human-readable name of the monitor.
+  /// Returns None if the monitor doesn't exist anymore.
+  pub fn name(&self) -> Option<&String> {
+    self.name.as_ref()
+  }
+
+  /// Returns the monitor's resolution.
+  pub fn size(&self) -> &PhysicalSize<u32> {
+    &self.size
+  }
+
+  /// Returns the top-left corner position of the monitor relative to the larger full screen area.
+  pub fn position(&self) -> &PhysicalPosition<i32> {
+    &self.position
+  }
+
+  /// Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
+  pub fn scale_factor(&self) -> f64 {
+    self.scale_factor
+  }
+}
+
 /// A webview window managed by Tauri.
 ///
 /// This type also implements [`Manager`] which allows you to manage other windows attached to
@@ -316,14 +360,24 @@ impl<P: Params> Window<P> {
   ///
   /// Returns None if current monitor can't be detected.
   pub fn current_monitor(&self) -> crate::Result<Option<Monitor>> {
-    self.window.dispatcher.current_monitor().map_err(Into::into)
+    self
+      .window
+      .dispatcher
+      .current_monitor()
+      .map(|m| m.map(Into::into))
+      .map_err(Into::into)
   }
 
   /// Returns the primary monitor of the system.
   ///
   /// Returns None if it can't identify any monitor as a primary one.
   pub fn primary_monitor(&self) -> crate::Result<Option<Monitor>> {
-    self.window.dispatcher.primary_monitor().map_err(Into::into)
+    self
+      .window
+      .dispatcher
+      .primary_monitor()
+      .map(|m| m.map(Into::into))
+      .map_err(Into::into)
   }
 
   /// Returns the list of all the monitors available on the system.
@@ -332,6 +386,7 @@ impl<P: Params> Window<P> {
       .window
       .dispatcher
       .available_monitors()
+      .map(|m| m.into_iter().map(Into::into).collect())
       .map_err(Into::into)
   }
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä