Эх сурвалжийг харах

feat(core): use native window dialogs on Android (#5137)

Lucas Fernandes Nogueira 2 жил өмнө
parent
commit
bc1622c5ab

+ 0 - 7
.github/workflows/test-core.yml

@@ -18,9 +18,6 @@ env:
   RUST_BACKTRACE: 1
   CARGO_INCREMENTAL: 0 # This is set to 0 by the https://github.com/Swatinem/rust-cache
   CARGO_PROFILE_DEV_DEBUG: 0 # This would add unnecessary bloat to the target folder, decreasing cache efficiency.
-  WRY_ANDROID_REVERSED_DOMAIN: 'app.tauri'
-  WRY_ANDROID_APP_NAME_SNAKE_CASE: 'dev'
-  WRY_ANDROID_KOTLIN_FILES_OUT_DIR: 'out'
 
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}
@@ -123,10 +120,6 @@ jobs:
             ${{ matrix.platform.os }}-${{ matrix.platform.toolchain }}-
             ${{ matrix.platform.os }}-
 
-      - name: create kotlin out dir
-        if: contains(matrix.platform.target, 'android')
-        run: mkdir out
-
       - name: pin time
         run: |
           cargo update -p time --precise 0.3.13

+ 0 - 37
core/tauri/scripts/core.js

@@ -245,41 +245,4 @@
       setNotificationPermission(response ? 'granted' : 'denied')
     }
   })
-
-  window.alert = function (message) {
-    window.__TAURI_INVOKE__('tauri', {
-      __tauriModule: 'Dialog',
-      message: {
-        cmd: 'messageDialog',
-        message: message.toString()
-      }
-    })
-  }
-
-  window.confirm = function (message) {
-    return window.__TAURI_INVOKE__('tauri', {
-      __tauriModule: 'Dialog',
-      message: {
-        cmd: 'confirmDialog',
-        message: message.toString()
-      }
-    })
-  }
-
-  // window.print works on Linux/Windows; need to use the API on macOS
-  if (navigator.userAgent.includes('Mac')) {
-    window.print = function () {
-      return window.__TAURI_INVOKE__('tauri', {
-        __tauriModule: 'Window',
-        message: {
-          cmd: 'manage',
-          data: {
-            cmd: {
-              type: 'print'
-            }
-          }
-        }
-      })
-    }
-  }
 })()

+ 4 - 0
core/tauri/scripts/init.js

@@ -17,6 +17,10 @@
 
     __RAW_core_script__
 
+    __RAW_window_dialogs_script__
+
+    __RAW_window_print_script__
+
     __RAW_event_initialization_script__
 
     if (window.ipc) {

+ 19 - 0
core/tauri/scripts/window_dialogs.js

@@ -0,0 +1,19 @@
+window.alert = function (message) {
+  window.__TAURI_INVOKE__('tauri', {
+    __tauriModule: 'Dialog',
+    message: {
+      cmd: 'messageDialog',
+      message: message.toString()
+    }
+  })
+}
+
+window.confirm = function (message) {
+  return window.__TAURI_INVOKE__('tauri', {
+    __tauriModule: 'Dialog',
+    message: {
+      cmd: 'confirmDialog',
+      message: message.toString()
+    }
+  })
+}

+ 13 - 0
core/tauri/scripts/window_print.js

@@ -0,0 +1,13 @@
+window.print = function () {
+  return window.__TAURI_INVOKE__('tauri', {
+    __tauriModule: 'Window',
+    message: {
+      cmd: 'manage',
+      data: {
+        cmd: {
+          type: 'print'
+        }
+      }
+    }
+  })
+}

+ 17 - 0
core/tauri/src/manager.rs

@@ -917,6 +917,10 @@ impl<R: Runtime> WindowManager<R> {
       #[raw]
       core_script: &'a str,
       #[raw]
+      window_dialogs_script: &'a str,
+      #[raw]
+      window_print_script: &'a str,
+      #[raw]
       event_initialization_script: &'a str,
       #[raw]
       plugin_initialization_script: &'a str,
@@ -982,6 +986,19 @@ impl<R: Runtime> WindowManager<R> {
         )
       ),
       core_script: include_str!("../scripts/core.js"),
+
+      // window.print works on Linux/Windows; need to use the API on macOS
+      #[cfg(any(target_os = "macos", target_os = "ios"))]
+      window_print_script: include_str!("../scripts/window_print.js"),
+      #[cfg(not(any(target_os = "macos", target_os = "ios")))]
+      window_print_script: "",
+
+      // dialogs are implemented natively on Android
+      #[cfg(not(target_os = "android"))]
+      window_dialogs_script: include_str!("../scripts/window_dialogs.js"),
+      #[cfg(target_os = "android")]
+      window_dialogs_script: "",
+
       event_initialization_script: &self.event_initialization_script(),
       plugin_initialization_script,
       freeze_prototype,

+ 11 - 28
examples/api/src-tauri/Cargo.lock

@@ -2030,9 +2030,9 @@ dependencies = [
 
 [[package]]
 name = "once_cell"
-version = "1.13.0"
+version = "1.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
+checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
 
 [[package]]
 name = "opaque-debug"
@@ -3107,7 +3107,7 @@ dependencies = [
 [[package]]
 name = "tao"
 version = "0.13.3"
-source = "git+https://github.com/tauri-apps/tao?branch=dev#816ca49dc648a5286eab943c6fc936629fd3a596"
+source = "git+https://github.com/tauri-apps/tao?branch=dev#0ae71fc887f0cbc498f7a2f5053201b4546f5a4d"
 dependencies = [
  "bitflags",
  "cairo-rs",
@@ -3146,8 +3146,8 @@ dependencies = [
  "serde",
  "unicode-segmentation",
  "uuid 1.1.2",
- "windows 0.37.0",
- "windows-implement 0.37.0",
+ "windows 0.39.0",
+ "windows-implement",
  "x11-dl",
 ]
 
@@ -3893,7 +3893,7 @@ dependencies = [
  "webview2-com-macros",
  "webview2-com-sys",
  "windows 0.39.0",
- "windows-implement 0.39.0",
+ "windows-implement",
 ]
 
 [[package]]
@@ -4024,7 +4024,6 @@ version = "0.37.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647"
 dependencies = [
- "windows-implement 0.37.0",
  "windows_aarch64_msvc 0.37.0",
  "windows_i686_gnu 0.37.0",
  "windows_i686_msvc 0.37.0",
@@ -4038,7 +4037,7 @@ version = "0.39.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a"
 dependencies = [
- "windows-implement 0.39.0",
+ "windows-implement",
  "windows_aarch64_msvc 0.39.0",
  "windows_i686_gnu 0.39.0",
  "windows_i686_msvc 0.39.0",
@@ -4053,17 +4052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "68003dbd0e38abc0fb85b939240f4bce37c43a5981d3df37ccbaaa981b47cb41"
 dependencies = [
  "windows-metadata",
- "windows-tokens 0.39.0",
-]
-
-[[package]]
-name = "windows-implement"
-version = "0.37.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67a1062e555f7d9d66fd1130ed4f7c6ec41a47529ee0850cd0e926d95b26bb14"
-dependencies = [
- "syn",
- "windows-tokens 0.37.0",
+ "windows-tokens",
 ]
 
 [[package]]
@@ -4073,7 +4062,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ba01f98f509cb5dc05f4e5fc95e535f78260f15fea8fe1a8abdd08f774f1cee7"
 dependencies = [
  "syn",
- "windows-tokens 0.39.0",
+ "windows-tokens",
 ]
 
 [[package]]
@@ -4095,12 +4084,6 @@ dependencies = [
  "windows_x86_64_msvc 0.36.1",
 ]
 
-[[package]]
-name = "windows-tokens"
-version = "0.37.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3263d25f1170419995b78ff10c06b949e8a986c35c208dc24333c64753a87169"
-
 [[package]]
 name = "windows-tokens"
 version = "0.39.0"
@@ -4283,7 +4266,7 @@ dependencies = [
 [[package]]
 name = "wry"
 version = "0.20.2"
-source = "git+https://github.com/tauri-apps/wry?branch=dev#854d2226f4161d4fc783f64e79b6a8add31ac4eb"
+source = "git+https://github.com/tauri-apps/wry?branch=dev#3624414faa53386660b9d066c00e91e240b7681d"
 dependencies = [
  "base64",
  "block",
@@ -4312,7 +4295,7 @@ dependencies = [
  "webkit2gtk-sys",
  "webview2-com",
  "windows 0.39.0",
- "windows-implement 0.39.0",
+ "windows-implement",
 ]
 
 [[package]]