Ver código fonte

feat(tauri) lazy loading for the no-server mode (#161)

* feat(tauri) WIP on iframe wrapper

* fix(tauri) iframe communication working

* refactor(tauri) iframe injection on all modes

* feat(event): update tauri.js injection

* fix(tauri) rework on iframe/devServer

* feat(tauri.js) use load event to notify tauri ready

* fix(cargo.lock): remove erroneous lockfile

* WIP

* remove iframe

* feat(tauri) inline assets, inject tauri.js

* fix(example) tauri init

* fix(api) load bundled asset

* chore(api) remove println

* chore(template) remove deprecated event listener

* chore(example) gitignore tauri.js

* chore(package.json) update email

* fix(tauri) embedded-server's server_url definition

* chore(api) use salt on event listener again

* chore(webpack) add eslint

* remove forward slash

* perf(tauri) do not bundle inlined assets

* chore(tauri) macros and platform only when using the updater feature

* fix(tauri) proper feature check for the loadAsset API

* chore(tauri) add "forked from" reference

* chore(example) use @tauri-apps/tauri-webpack

* fix(tauri) dev-server mode fixes

* chore(example) use tauri-webpack 0.1.3

* feat(webpack) rewrite lazy loading only on the no-server mode

* fix(no-server) lazy load images

* chore(tauri) use forked includedir_codegen

* fix deps

* fix(tauri) use the right version for includedir deps

* chore(tauri) println rerun-if-changed on dev
Lucas Fernandes Nogueira 5 anos atrás
pai
commit
1951fc88c9

+ 1 - 1
.github/workflows/build-smoke-tests.yml

@@ -131,7 +131,7 @@ jobs:
       run: cargo build
       env:
         TAURI_DIST_DIR: ../../test/fixture/dist
-        TAURI_CONFIG_DIR: ../test/fixture/
+        TAURI_DIR: ../test/fixture
     - run: cargo install --path ./cli/tauri-cli --force
     - name: install cli deps via yarn
       run: |

+ 1 - 1
.github/workflows/test-on-pr.yml

@@ -30,7 +30,7 @@ jobs:
            cargo build
       env:
         TAURI_DIST_DIR: ../../test/fixture/dist
-        TAURI_CONFIG_DIR: ../test/fixture/
+        TAURI_DIR: ../test/fixture/
 
   build-tauri-cli:
     runs-on: ${{ matrix.platform }}

+ 70 - 37
Cargo.lock

@@ -105,6 +105,11 @@ dependencies = [
  "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "base64"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "bitflags"
 version = "1.2.1"
@@ -249,7 +254,6 @@ dependencies = [
  "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -525,7 +529,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -859,25 +863,6 @@ dependencies = [
  "tiff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "includedir"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "includedir_codegen"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "indexmap"
 version = "1.3.0"
@@ -1281,7 +1266,7 @@ dependencies = [
  "pest_meta 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1311,6 +1296,15 @@ dependencies = [
  "phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "phf_codegen"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf_generator 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "phf_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "phf_generator"
 version = "0.7.24"
@@ -1320,6 +1314,15 @@ dependencies = [
  "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "phf_generator"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "phf_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "phf_shared"
 version = "0.7.24"
@@ -1328,6 +1331,14 @@ dependencies = [
  "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "phf_shared"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "siphasher 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "pkg-config"
 version = "0.3.17"
@@ -1454,6 +1465,7 @@ dependencies = [
  "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1551,6 +1563,14 @@ dependencies = [
  "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "rand_pcg"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "rand_xorshift"
 version = "0.1.1"
@@ -1787,7 +1807,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1854,6 +1874,11 @@ name = "siphasher"
 version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "siphasher"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
 [[package]]
 name = "slab"
 version = "0.4.2"
@@ -1902,7 +1927,7 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.8"
+version = "1.0.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1917,7 +1942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1964,14 +1989,12 @@ dependencies = [
 name = "tauri"
 version = "0.1.3"
 dependencies = [
- "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "hyper-old-types 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "includedir 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "includedir_codegen 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "pbr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1983,6 +2006,7 @@ dependencies = [
  "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
  "sysinfo 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
+ "tauri_includedir_codegen 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2026,6 +2050,16 @@ dependencies = [
  "zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "tauri_includedir_codegen"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
+ "phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "tempdir"
 version = "0.3.7"
@@ -2506,11 +2540,6 @@ dependencies = [
  "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "yaml-rust"
-version = "0.3.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
 [[package]]
 name = "zip"
 version = "0.5.3"
@@ -2537,6 +2566,7 @@ dependencies = [
 "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea"
 "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491"
 "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
+"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
 "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
 "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
 "checksum blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0"
@@ -2623,8 +2653,6 @@ dependencies = [
 "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
 "checksum ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ec16832258409d571aaef8273f3c3cc5b060d784e159d1a0f3b0017308f84a7"
 "checksum image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4be8aaefbe7545dc42ae925afb55a0098f226a3fe5ef721872806f44f57826"
-"checksum includedir 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e97402f770a519ebea51b27131c3b6558cfd2375aff21294bad806bad91bf0b6"
-"checksum includedir_codegen 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af7d542be113fd84855692fb536c16cc4c09527724d1dca8953047d71cccadef"
 "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2"
 "checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff"
 "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e"
@@ -2677,8 +2705,11 @@ dependencies = [
 "checksum pest_meta 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df43fd99896fd72c485fe47542c7b500e4ac1e8700bf995544d1317a60ded547"
 "checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18"
 "checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e"
+"checksum phf_codegen 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815"
 "checksum phf_generator 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662"
+"checksum phf_generator 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526"
 "checksum phf_shared 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
+"checksum phf_shared 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7"
 "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
 "checksum png 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "99c43e2159aafbfccf7b1e13f420d028a6b9384c72544ac3b829c14d48dcb002"
 "checksum png 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f00ec9242f8e01119e83117dbadf34c5228ac2f1c4ddcd92bffa340d52291de"
@@ -2704,6 +2735,7 @@ dependencies = [
 "checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
 "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
 "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
+"checksum rand_pcg 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
 "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
 "checksum rayon 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43739f8831493b276363637423d3622d4bd6394ab6f0a9c4a552e208aeb7fddd"
 "checksum rayon-core 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8bf17de6f23b05473c437eb958b9c850bfc8af0961fe17b4cc92d5a627b4791"
@@ -2739,6 +2771,7 @@ dependencies = [
 "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
 "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
 "checksum siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"
+"checksum siphasher 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "83da420ee8d1a89e640d0948c646c1c088758d3a3c538f943bfa97bdac17929d"
 "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
 "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
 "checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86"
@@ -2746,12 +2779,13 @@ dependencies = [
 "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
 "checksum strsim 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "032c03039aae92b350aad2e3779c352e104d919cb192ba2fabbd7b831ce4f0f6"
 "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
-"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92"
+"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
 "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
 "checksum sysinfo 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6102624bff8a9810e91593afbd5b3f589c1df50a048908b49fae919231ad6145"
 "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
 "checksum tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)" = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3"
 "checksum target_build_utils 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "013d134ae4a25ee744ad6129db589018558f620ddfa44043887cdd45fa08e75c"
+"checksum tauri_includedir_codegen 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ce0832eb4da6f615c948ae27d34033653a0032c9d7cfde9f62770b8a8e6e38f"
 "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
 "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
 "checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5"
@@ -2809,5 +2843,4 @@ dependencies = [
 "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
 "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
 "checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c"
-"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"
 "checksum zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3c21bb410afa2bd823a047f5bda3adb62f51074ac7e06263b2c97ecdd47e9fc6"

+ 2 - 1
cli/tauri.js/api/dev.js

@@ -7,7 +7,8 @@ module.exports = config => {
     merge(
       {
         ctx: {
-          debug: true
+          debug: true,
+          dev: true
         }
       },
       config

+ 3 - 4
cli/tauri.js/entry.js

@@ -1,5 +1,5 @@
 const compileTemplate = require('lodash.template')
-const { readFileSync, writeFileSync, ensureDir } = require('fs-extra')
+const { readFileSync, writeFileSync, ensureDirSync } = require('fs-extra')
 const path = require('path')
 
 module.exports.generate = (outDir, cfg) => {
@@ -7,7 +7,6 @@ module.exports.generate = (outDir, cfg) => {
   const apiTemplate = readFileSync(path.resolve(__dirname, './templates/tauri.js'), 'utf-8')
   const apiContent = compileTemplate(apiTemplate)(cfg)
 
-  ensureDir(outDir).then(() => {
-    writeFileSync(path.join(outDir, 'tauri.js'), apiContent, 'utf-8')
-  })
+  ensureDirSync(outDir)
+  writeFileSync(path.join(outDir, 'tauri.js'), apiContent, 'utf-8')
 }

+ 2 - 9
cli/tauri.js/helpers/tauri-config.js

@@ -18,9 +18,7 @@ module.exports = cfg => {
   const pkg = require(pkgPath)
 
   const config = merge({
-    build: {
-      distDir: './dist'
-    },
+    build: {},
     ctx: {},
     tauri: {
       embeddedServer: {
@@ -38,11 +36,6 @@ module.exports = cfg => {
       security: {
         csp: 'default-src data: filesystem: ws: http: https: \'unsafe-eval\' \'unsafe-inline\''
       },
-      automaticStart: {
-        active: false,
-        devArgs: [],
-        buildArgs: []
-      },
       edge: {
         active: true
       }
@@ -50,7 +43,7 @@ module.exports = cfg => {
   }, tauriConf, cfg)
 
   process.env.TAURI_DIST_DIR = appPaths.resolve.app(config.build.distDir)
-  process.env.TAURI_CONFIG_DIR = appPaths.tauriDir
+  process.env.TAURI_DIR = appPaths.tauriDir
 
   return config
 }

+ 2 - 2
cli/tauri.js/package.json

@@ -40,19 +40,19 @@
   },
   "dependencies": {
     "@tauri-apps/toml": "2.2.4",
-    "babel-plugin-system-import-transformer": "4.0.0",
     "chalk": "3.0.0",
     "chokidar": "3.3.0",
     "cross-spawn": "7.0.1",
     "fast-glob": "3.1.1",
     "fs-extra": "8.1.0",
-    "html-webpack-inline-source-plugin": "0.0.10",
     "imagemin": "7.0.1",
     "imagemin-optipng": "7.1.0",
     "imagemin-pngquant": "8.0.0",
     "imagemin-zopfli": "6.0.0",
+    "inliner": "^1.13.1",
     "is-png": "2.0.0",
     "isbinaryfile": "4.0.2",
+    "jsdom": "^15.2.1",
     "lodash.debounce": "4.0.8",
     "lodash.template": "4.5.0",
     "minimist": "1.2.0",

+ 65 - 15
cli/tauri.js/runner.js

@@ -8,6 +8,7 @@ const
   { spawn } = require('./helpers/spawn')
 const onShutdown = require('./helpers/on-shutdown')
 const generator = require('./generator')
+const entry = require('./entry')
 const { appDir, tauriDir } = require('./helpers/app-paths')
 
 const logger = require('./helpers/logger')
@@ -38,17 +39,28 @@ class Runner {
       this.__whitelistApi(cfg, toml)
     })
 
-    generator.generate(cfg.tauri)
+    const runningDevServer = devPath.startsWith('http')
+    let inlinedAssets = []
+
+    if (!runningDevServer) {
+      inlinedAssets = await this.__parseHtml(path.resolve(appDir, devPath))
+    }
+
+    generator.generate({
+      devPath: runningDevServer ? devPath : path.resolve(appDir, devPath),
+      inlinedAssets,
+      ...cfg.tauri
+    })
+    entry.generate(tauriDir, cfg)
 
     this.devPath = devPath
 
-    const args = ['--path', devPath.startsWith('http') ? devPath : path.resolve(appDir, devPath)]
-    const features = ['dev']
+    const features = runningDevServer ? ['dev-server'] : []
 
     const startDevTauri = () => {
       return this.__runCargoCommand({
-        cargoArgs: ['run', '--features', ...features],
-        extraArgs: args
+        cargoArgs: ['run'].concat(features.length ? ['--features', ...features] : []),
+        dev: true
       })
     }
 
@@ -69,7 +81,7 @@ class Runner {
       .on('change', debounce(async (path) => {
         await this.__stopCargo()
         if (path.includes('tauri.conf.js')) {
-          this.run(require('./helpers/tauri-config')(cfg.ctx))
+          this.run(require('./helpers/tauri-config')({ ctx: cfg.ctx }))
         } else {
           startDevTauri()
         }
@@ -83,16 +95,21 @@ class Runner {
       this.__whitelistApi(cfg, toml)
     })
 
-    generator.generate(cfg.tauri)
+    const inlinedAssets = await this.__parseHtml(cfg.build.distDir)
 
-    const features = []
-    if (cfg.tauri.embeddedServer.active) {
-      features.push('embedded-server')
-    }
+    generator.generate({
+      inlinedAssets,
+      ...cfg.tauri
+    })
+    entry.generate(tauriDir, cfg)
+    
+
+    const features = [
+      cfg.tauri.embeddedServer.active ? 'embedded-server' : 'no-server'
+    ]
 
     const buildFn = target => this.__runCargoCommand({
-      cargoArgs: [cfg.tauri.bundle.active ? 'tauri-cli' : 'build']
-        .concat(features.length ? ['--features', ...features] : [])
+      cargoArgs: [cfg.tauri.bundle.active ? 'tauri-cli' : 'build', '--features', ...features]
         .concat(cfg.ctx.debug ? [] : ['--release'])
         .concat(target ? ['--target', target] : [])
     })
@@ -110,6 +127,38 @@ class Runner {
     }
   }
 
+  __parseHtml (indexDir) {
+    const Inliner = require('inliner')
+    const jsdom = require('jsdom')
+    const { JSDOM } = jsdom
+    const inlinedAssets = []
+    
+    return new Promise((resolve, reject) => {
+      new Inliner(path.join(indexDir, 'index.html'), (err, html) => {
+        if (err) {
+          reject(err)
+        } else {
+          const dom = new JSDOM(html)
+          const document = dom.window.document
+          document.querySelectorAll('link').forEach(link => {
+            link.removeAttribute('rel')
+            link.removeAttribute('as')
+          })
+
+          const tauriScript = document.createElement('script')
+          tauriScript.text = readFileSync(path.join(tauriDir, 'tauri.js'))
+          document.body.insertBefore(tauriScript, document.body.firstChild)
+          
+          writeFileSync(path.join(indexDir, 'index.tauri.html'), dom.serialize())
+          resolve(inlinedAssets)
+        }
+      }).on('progress', event => {
+        const match = event.match(/([\S\d]+)\.([\S\d]+)/g)
+        match && inlinedAssets.push(match[0])
+      })
+    })
+  }
+
   stop () {
     return new Promise((resolve, reject) => {
       this.tauriWatcher && this.tauriWatcher.close()
@@ -119,7 +168,8 @@ class Runner {
 
   __runCargoCommand ({
     cargoArgs,
-    extraArgs
+    extraArgs,
+    dev = false
   }) {
     return new Promise(resolve => {
       this.pid = spawn(
@@ -142,7 +192,7 @@ class Runner {
           if (this.killPromise) {
             this.killPromise()
             this.killPromise = null
-          } else if (cargoArgs.some(arg => arg === 'dev')) { // else it wasn't killed by us
+          } else if (dev) {
             warn()
             warn('Cargo process was killed. Exiting...')
             warn()

+ 3 - 2
cli/tauri.js/templates/src-tauri/Cargo.toml

@@ -20,8 +20,9 @@ includedir = "0.5.0"
 tauri = <%= tauriDep || `{ version = "0.1.0" }` %>
 
 [features]
-dev = ["tauri/dev"] # has no explicit dependencies
-embedded-server = ["tauri/embedded-server"] # has no explicit dependencies
+dev-server = [ "tauri/dev-server" ]
+embedded-server = [ "tauri/embedded-server" ]
+no-server = [ "tauri/no-server" ]
 
 [package.metadata.bundle]
 identifier = "com.tauri.dev"

+ 1 - 1
cli/tauri.js/templates/tauri.conf.js

@@ -5,7 +5,7 @@ module.exports = function () {
   return {
     build: {
       distDir: distDir,
-      devPath: 'http://localhost:4000' // devServer URL or path to html file
+      devPath: 'http://localhost:4000' // devServer URL or html dir
     },
     ctx: {},
     tauri: {

+ 45 - 27
cli/tauri.js/templates/tauri.js

@@ -8,8 +8,6 @@
  *
  **/
 
-// open <a href="..."> links with the Tauri API
-
 /**
  * @module tauri
  * @description This API interface makes powerful interactions available
@@ -26,7 +24,7 @@ function s4() {
     .substring(1)
 }
 
-const uid = function () {
+var uid = function () {
   return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
     s4() + '-' + s4() + s4() + s4()
 }
@@ -63,7 +61,6 @@ window.tauri = {
      */
   <% } %>
   invoke: function invoke(args) {
-    Object.freeze(args);
     window.external.invoke(JSON.stringify(args));
   },
 
@@ -81,7 +78,7 @@ window.tauri = {
     this.invoke({
       cmd: 'listen',
       event: event,
-      handler: this.transformCallback(handler, once),
+      handler: window.tauri.transformCallback(handler, once),
       once: once
     });
   },
@@ -366,28 +363,49 @@ window.tauri = {
     <% } %>
   },
 
-  <% if (ctx.dev) { %>
-  /**
-   * @name setup
-   * @description Inform Rust that the webview has initialized and is
-   * ready for communication
-     */
-  <% } %>
-  setup: function setup() {
-    document.querySelector('body').addEventListener('click', function (e) {
-      var target = e.target;
+  loadAsset: function loadAsset(assetName, assetType) {
+    return this.promisified({
+      cmd: 'loadAsset',
+      asset: assetName,
+      asset_type: assetType || 'unknown'
+    })
+  }
+};
 
-      while (target != null) {
-        if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
-          tauri.open(target.href);
-          break;
-        }
+// init tauri API
 
-        target = target.parentElement;
-      }
-    }, true);
-    window.tauri.invoke({
-      cmd: 'init'
-    });
+window.tauri.invoke({
+  cmd: 'init'
+})
+
+if (window.onTauriInit !== void 0) {
+  window.onTauriInit()
+}
+
+document.addEventListener('error', function (e) {
+  var target = e.target
+  while (target != null) {
+    if (target.matches ? target.matches('img') : target.msMatchesSelector('img')) {
+      window.tauri.loadAsset(target.src, 'image')
+        .then(img => {
+          target.src = img
+        }).catch(alert)
+      break
+    }
+    target = target.parentElement
   }
-};
+}, true)
+
+window.addEventListener('DOMContentLoaded', function () {
+  // open <a href="..."> links with the Tauri API
+  document.querySelector('body').addEventListener('click', function (e) {
+    var target = e.target
+    while (target != null) {
+      if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
+        window.tauri.open(target.href)
+        break
+      }
+      target = target.parentElement
+    }
+  }, true)
+}, true)

+ 0 - 97
cli/tauri.js/webpack/index.js

@@ -1,97 +0,0 @@
-const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
-const tauriConfig = require('../helpers/tauri-config')
-const WebpackShellPlugin = require('webpack-shell-plugin')
-
-const safeTap = (options, cb) => {
-  if (options !== undefined) {
-    cb()
-  }
-  return options
-}
-
-module.exports.chain = function (chain) {
-  const cfg = tauriConfig({
-    ctx: {
-      debug: process.env.NODE_ENV !== 'production',
-      prod: process.env.NODE_ENV === 'production'
-    }
-  })
-  if (!cfg.tauri.embeddedServer.active) {
-    chain.optimization.splitChunks({
-      chunks: 'all',
-      minSize: 0,
-      maxSize: Infinity,
-      maxAsyncRequests: 1,
-      maxInitialRequests: 1,
-      automaticNameDelimiter: '~',
-      name: true,
-      cacheGroups: {
-        styles: {
-          name: 'styles',
-          chunks: 'all'
-        },
-        commons: {
-          name: 'vendors',
-          chunks: 'all'
-        }
-      }
-    })
-
-    chain.output.filename('js/app.js')
-
-    if (cfg.ctx.prod) {
-      if (cfg.build.extractCSS) {
-        chain.plugin('mini-css-extract')
-          .tap(options => {
-            options[0].filename = 'css/app.css'
-            return options
-          })
-      }
-
-      chain.plugin('html-webpack')
-        .tap(options => {
-          options[0].inlineSource = '.(js|css)$'
-          return options
-        })
-
-      chain.module.rule('babel')
-        .use('babel-loader')
-        .tap(options => safeTap(options, () => {
-          options.plugins.push([
-            'system-import-transformer', { // needs constant attention
-              modules: 'common'
-            }
-          ])
-        }))
-    }
-
-    const modules = {
-      images: 'url-loader',
-      fonts: 'url-loader',
-      media: 'url-loader'
-    }
-    for (const module in modules) {
-      chain.module.rule(module)
-        .use(modules[module])
-        .tap(options => safeTap(options, () => {
-          options.limit = undefined
-        }))
-    }
-  }
-
-  if (cfg.ctx.prod && !cfg.tauri.embeddedServer.active) {
-    chain.plugin('html-webpack-inline-source')
-      .use(HtmlWebpackInlineSourcePlugin)
-  }
-
-  if (cfg.tauri.automaticStart.active) {
-    chain.plugin('webpack-shell-plugin')
-      .use(WebpackShellPlugin, [{
-        onBuildEnd: [
-          cfg.ctx.prod
-            ? `tauri build${cfg.tauri.automaticStart.buildArgs.join(' ')}`
-            : `tauri dev${cfg.tauri.automaticStart.devArgs.join(' ')}`
-        ]
-      }])
-  }
-}

Diferenças do arquivo suprimidas por serem muito extensas
+ 542 - 39
cli/tauri.js/yarn.lock


+ 1 - 4
examples/gatsby/themed-site/tauri.conf.js

@@ -5,7 +5,7 @@ module.exports = function () {
   return {
     build: {
       distDir: distDir,
-      devPath: 'http://localhost:8000' // devServer URL or path to html file
+      devPath: 'http://localhost:8000' // devServer URL or html dir
     },
     ctx: {},
     tauri: {
@@ -26,9 +26,6 @@ module.exports = function () {
       },
       edge: {
         active: true
-      },
-      automaticStart: {
-        active: true
       }
     }
   }

+ 1 - 4
examples/vanillajs/monolith/tauri.conf.js

@@ -3,12 +3,9 @@ const distDir = path.resolve(__dirname, './dist')
 
 module.exports = function () {
   return {
-    automaticStart: {
-      active: true
-    },
     build: {
       distDir: distDir,
-      devPath: 'http://localhost:4000' // devServer URL or path to html file
+      devPath: 'http://localhost:4000' // devServer URL or html dir
     },
     ctx: {},
     tauri: {

+ 1 - 0
examples/vue/quasar-app/package.json

@@ -26,6 +26,7 @@
   },
   "devDependencies": {
     "@quasar/app": "1.3.6",
+    "@tauri-apps/tauri-webpack": "^0.1.4",
     "@vue/eslint-config-standard": "^4.0.0",
     "babel-eslint": "^10.0.1",
     "eslint": "^5.10.0",

+ 7 - 1
examples/vue/quasar-app/quasar.conf.js

@@ -1,6 +1,8 @@
 // Configuration for your app
 // https://quasar.dev/quasar-cli/quasar-conf-js
 
+const path = require(`path`)
+
 module.exports = function (ctx) {
   return {
     // app boot file (/src/boot)
@@ -72,6 +74,10 @@ module.exports = function (ctx) {
             formatter: require('eslint').CLIEngine.getFormatter('stylish')
           }
         })
+      },
+
+      chainWebpack (chain) {
+        require('@tauri-apps/tauri-webpack').chain(chain)
       }
     },
 
@@ -79,7 +85,7 @@ module.exports = function (ctx) {
     devServer: {
       // https: true,
       port: 7334,
-      open: true // opens browser window automatically
+      open: false // opens browser window automatically
     },
 
     // animations: 'all', // --- includes all animations

+ 1 - 1
examples/vue/quasar-app/src-tauri/.gitignore

@@ -9,6 +9,6 @@ Cargo.lock
 # These are backup files generated by rustfmt
 **/*.rs.bk
 
-# tauri.js
+tauri.js
 config.json
 bundle.json

+ 2 - 1
examples/vue/quasar-app/src-tauri/Cargo.toml

@@ -33,8 +33,9 @@ includedir = "0.5.0"
   features = [ "all-api", "edge" ]
 
 [features]
-dev = [ "tauri/dev" ]
+dev-server = [ "tauri/dev-server" ]
 embedded-server = [ "tauri/embedded-server" ]
+no-server = [ "tauri/no-server" ]
 
 [[bin]]
 name = "app"

+ 0 - 235
examples/vue/quasar-app/src-tauri/tauri.js

@@ -1,235 +0,0 @@
-/* eslint-disable */
-
-/**
- *  * THIS FILE IS GENERATED AUTOMATICALLY.
- * DO NOT EDIT.
- *
- * Please whitelist these API functions in tauri.conf.js
- *
- **/
-
-// open <a href="..."> links with the Tauri API
-
-/**
- * @module tauri
- * @description This API interface makes powerful interactions available
- * to be run on client side applications. They are opt-in features, and
- * must be enabled in tauri.conf.js
- *
- * Each binding MUST provide these interfaces in order to be compliant,
- * and also whitelist them based upon the developer's settings.
- */
-
-function s4() {
-  return Math.floor((1 + Math.random()) * 0x10000)
-    .toString(16)
-    .substring(1)
-}
-
-const uid = function () {
-  return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
-    s4() + '-' + s4() + s4() + s4()
-}
-
-function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
-
-function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
-
-function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
-
-
-function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
-
-
-var __reject = new Promise(function (reject) {
-  reject;
-});
-
-window.tauri = {
-  
-  invoke: function invoke(args) {
-    Object.freeze(args);
-    window.external.invoke(JSON.stringify(args));
-  },
-
-  
-  listen: function listen(event, handler) {
-    var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
-    this.invoke({
-      cmd: 'listen',
-      event: event,
-      handler: this.transformCallback(handler, once),
-      once: once
-    });
-  },
-
-  
-  emit: function emit(evt, payload) {
-    this.invoke({
-      cmd: 'emit',
-      event: evt,
-      payload: payload
-    });
-  },
-
-  
-  transformCallback: function transformCallback(callback) {
-    var once = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
-    var identifier = Object.freeze(uid());
-
-    window[identifier] = function (result) {
-      if (once) {
-        delete window[identifier];
-      }
-
-      return callback && callback(result);
-    };
-
-    return identifier;
-  },
-
-  
-  promisified: function promisified(args) {
-    var _this = this;
-
-    return new Promise(function (resolve, reject) {
-      _this.invoke(_objectSpread({
-        callback: _this.transformCallback(resolve),
-        error: _this.transformCallback(reject)
-      }, args));
-    });
-  },
-
-  
-  readTextFile: function readTextFile(path) {
-    
-    Object.freeze(path);
-    return this.promisified({
-      cmd: 'readTextFile',
-      path: path
-    });
-    
-  },
-
-  
-  readBinaryFile: function readBinaryFile(path) {
-    
-    Object.freeze(path);
-    return this.promisified({
-      cmd: 'readBinaryFile',
-      path: path
-    });
-    
-  },
-
-  
-  writeFile: function writeFile(cfg) {
-    
-    Object.freeze(cfg);
-    this.invoke({
-      cmd: 'writeFile',
-      file: cfg.file,
-      contents: cfg.contents
-    });
-    
-  },
-
-  
-  listFiles: function listFiles(path) {
-    
-
-    Object.freeze(path);
-    return this.promisified({
-      cmd: 'listFiles',
-      path: path
-    });
-    
-  },
-
-  
-  listDirs: function listDirs(path) {
-    
-    Object.freeze(path);
-    return this.promisified({
-      cmd: 'listDirs',
-      path: path
-    });
-    
-  },
-
-  
-  setTitle: function setTitle(title) {
-    
-    Object.freeze(title);
-    this.invoke({
-      cmd: 'setTitle',
-      title: title
-    });
-    
-  },
-
-  
-  open: function open(uri) {
-    
-    Object.freeze(uri);
-    this.invoke({
-      cmd: 'open',
-      uri: uri
-    });
-    
-  },
-
-  
-  execute: function execute(command, args) {
-    
-
-    Object.freeze(command);
-
-    if (typeof args === 'string' || _typeof(args) === 'object') {
-      Object.freeze(args);
-    }
-
-    return this.promisified({
-      cmd: 'execute',
-      command: command,
-      args: typeof args === 'string' ? [args] : args
-    });
-    
-  },
-
-  bridge: function bridge(command, payload) {
-    
-
-    Object.freeze(command);
-
-    if (typeof payload === 'string' || _typeof(payload) === 'object') {
-      Object.freeze(payload);
-    }
-
-    return this.promisified({
-      cmd: 'bridge',
-      command: command,
-      payload: _typeof(payload) === 'object' ? [payload] : payload
-    });
-    
-  },
-
-  
-  setup: function setup() {
-    document.querySelector('body').addEventListener('click', function (e) {
-      var target = e.target;
-
-      while (target != null) {
-        if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
-          tauri.open(target.href);
-          break;
-        }
-
-        target = target.parentElement;
-      }
-    }, true);
-    window.tauri.invoke({
-      cmd: 'init'
-    });
-  }
-};

+ 13 - 5
examples/vue/quasar-app/src/pages/Index.vue

@@ -8,9 +8,16 @@
 </template>
 
 <script>
-require('../../src-tauri/tauri.js')
 import { uid } from 'quasar'
 
+function __onTauriInit (cb) {
+  if (window.tauri) {
+    cb()
+  } else {
+    window.onTauriInit = cb
+  }
+}
+
 export default {
   name: 'HelloWorld',
   data () {
@@ -19,10 +26,11 @@ export default {
     }
   },
   mounted () {
-    window.tauri.setup()
-    window.tauri.listen('reply', res => {
-      this.msg = res.payload.msg
-    }, false)
+    __onTauriInit(() => {
+      window.tauri.listen('reply', res => {
+        this.msg = res.payload.msg
+      })
+    })
   },
   methods: {
     // set up an event listener

+ 2 - 5
examples/vue/quasar-app/tauri.conf.js

@@ -5,12 +5,12 @@ module.exports = function () {
   return {
     build: {
       distDir: distDir,
-      devPath: 'http://localhost:7334' // devServer URL or path to html file
+      devPath: 'http://localhost:7334' // devServer URL or html dir
     },
     ctx: {},
     tauri: {
       embeddedServer: {
-        active: true
+        active: false
       },
       bundle: {
         active: true
@@ -26,9 +26,6 @@ module.exports = function () {
       },
       edge: {
         active: true
-      },
-      automaticStart: {
-        active: true
       }
     }
   }

+ 18 - 1
examples/vue/quasar-app/yarn.lock

@@ -955,6 +955,15 @@
   resolved "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd"
   integrity sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow==
 
+"@tauri-apps/tauri-webpack@^0.1.4":
+  version "0.1.4"
+  resolved "https://registry.yarnpkg.com/@tauri-apps/tauri-webpack/-/tauri-webpack-0.1.4.tgz#be619274933a64370dc7598b916eedf4a78fe646"
+  integrity sha512-c/NM7PAQM+1vrpGyAQ6cgpv5CdsMGshjWGVZ6tmRESp8JXi9TPH43XBOX/QVIXJNIVz7E3YGiX+KzoTExforYA==
+  dependencies:
+    tauri "^0.1.9"
+    webpack-chain "^6.2.0"
+    webpack-shell-plugin "0.5.0"
+
 "@tauri-apps/toml@2.2.3":
   version "2.2.3"
   resolved "https://registry.npmjs.org/@tauri-apps/toml/-/toml-2.2.3.tgz#88cdebed2ae3944734aa8ecccce4834fffb8bc83"
@@ -5510,7 +5519,7 @@ isurl@^1.0.0-alpha5:
     has-to-string-tag-x "^1.2.0"
     is-object "^1.0.1"
 
-javascript-stringify@^2.0.0:
+javascript-stringify@^2.0.0, javascript-stringify@^2.0.1:
   version "2.0.1"
   resolved "https://registry.npmjs.org/javascript-stringify/-/javascript-stringify-2.0.1.tgz#6ef358035310e35d667c675ed63d3eb7c1aa19e5"
   integrity sha512-yV+gqbd5vaOYjqlbk16EG89xB5udgjqQF3C5FAORDg4f/IS1Yc5ERCv5e/57yBcfJYw05V5JyIXabhwb75Xxow==
@@ -9875,6 +9884,14 @@ webpack-chain@6.0.0:
     deepmerge "^1.5.2"
     javascript-stringify "^2.0.0"
 
+webpack-chain@^6.2.0:
+  version "6.2.0"
+  resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-6.2.0.tgz#bcea7b0ad5feae6845d70e6fd7a048953f8ae77c"
+  integrity sha512-Kt/TCt6p4sL8YJ49m6/mMkU1gkGJUMu/6yevWbWnaHYTdKc7U6hNAm0d9RSdLIN28CGonmYD5FkABqE1UuNTTw==
+  dependencies:
+    deepmerge "^1.5.2"
+    javascript-stringify "^2.0.1"
+
 webpack-dev-middleware@^3.7.2:
   version "3.7.2"
   resolved "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-3.7.2.tgz#0019c3db716e3fa5cecbf64f2ab88a74bab331f3"

+ 10 - 5
tauri/Cargo.toml

@@ -15,7 +15,7 @@ serde = "1.0"
 serde_derive = "1.0"
 dirs = "2.0.2"
 ignore = "0.4.10"
-phf = "0.7.24"
+phf = "0.8.0"
 threadpool = "1.7"
 rand = "0.7"
 zip = "0.5.3"
@@ -29,21 +29,26 @@ sysinfo = "0.10"
 webbrowser = "0.5.2"
 uuid = { version = "0.8.1", features = ["v4"] }
 lazy_static = "1.4.0"
-includedir = "0.5.0"
+tauri_includedir = "0.5.0"
 tiny_http = "0.6"
-clap = {version = "2.33", features = ["yaml"]}
+base64 = "0.11.0"
 
 reqwest = {version = "0.9", optional = true }
 hyper-old-types = {version = "0.11.0", optional = true }
 pbr = {version = "1", optional = true }
 
 [build-dependencies]
-includedir_codegen = "0.5.0"
+tauri_includedir_codegen = "0.5.1"
+serde_json = "1.0.42"
+serde = "1.0"
+serde_derive = "1.0"
+rand = "0.7"
 
 [features]
 edge = ["web-view/edge"]
-dev = []
+dev-server = []
 embedded-server = []
+no-server = []
 all-api = []
 readTextFile = []
 readBinaryFile = []

+ 85 - 7
tauri/build.rs

@@ -1,12 +1,90 @@
-use includedir_codegen::Compression;
+#[macro_use]
+extern crate serde_derive;
+extern crate serde_json;
+
 use std::env;
+use std::io::Write;
+
+#[path = "src/config.rs"]
+mod config;
+#[cfg(not(feature = "dev-server"))]
+extern crate tauri_includedir_codegen;
+#[cfg(feature = "embedded-server")]
+mod tcp;
 
 fn main() {
-  match env::var("TAURI_DIST_DIR") {
-    Ok(dist_path) => includedir_codegen::start("ASSETS")
-      .dir(dist_path, Compression::None)
-      .build("data.rs")
-      .unwrap(),
-    Err(_e) => panic!("Build error: Couldn't find ENV: {}", _e),
+  let out_dir = env::var("OUT_DIR").unwrap();
+  let dest_path = std::path::Path::new(&out_dir).join("tauri_src");
+  let mut file = std::fs::File::create(&dest_path).unwrap();
+
+  let tauri_src: String;
+  let config = config::get();
+
+  #[cfg(not(any(feature = "embedded-server", feature = "no-server")))]
+  {
+    tauri_src = if config.dev_path.starts_with("http") {
+      config.dev_path
+    } else {
+      let dev_path = std::path::Path::new(&config.dev_path).join("index.tauri.html");
+      println!("{}", format!("cargo:rerun-if-changed={:?}", dev_path));
+      std::fs::read_to_string(dev_path).unwrap()
+    };
+  }
+
+  #[cfg(not(feature = "dev-server"))]
+  {
+    match env::var("TAURI_DIST_DIR") {
+      Ok(dist_path) => {
+        // include assets
+        tauri_includedir_codegen::start("ASSETS")
+          .dir(dist_path, tauri_includedir_codegen::Compression::None)
+          .build("data.rs", config.inlined_assets)
+          .unwrap()
+      }
+      Err(_e) => panic!("Build error: Couldn't find ENV: {}", _e),
+    }
+  }
+  #[cfg(feature = "embedded-server")]
+  {
+    // define URL
+    let port;
+    let port_valid;
+    if config.embedded_server.port == "random" {
+      match tcp::get_available_port() {
+        Some(available_port) => {
+          port = available_port.to_string();
+          port_valid = true;
+        }
+        None => {
+          port = "0".to_string();
+          port_valid = false;
+        }
+      }
+    } else {
+      port = config.embedded_server.port;
+      port_valid = crate::tcp::port_is_available(
+        port
+          .parse::<u16>()
+          .expect(&format!("Invalid port {}", port)),
+      );
+    }
+    if port_valid {
+      let mut url = format!("{}:{}", config.embedded_server.host, port);
+      if !url.starts_with("http") {
+        url = format!("http://{}", url);
+      }
+      tauri_src = url.to_string();
+    } else {
+      panic!(format!("Port {} is not valid or not open", port));
+    }
   }
+
+  #[cfg(feature = "no-server")]
+  {
+    let index_path = std::path::Path::new(env!("TAURI_DIST_DIR")).join("index.tauri.html");
+    println!("{}", format!("cargo:rerun-if-changed={:?}", index_path));
+    tauri_src = std::fs::read_to_string(index_path).unwrap();
+  }
+
+  file.write_all(tauri_src.as_bytes()).unwrap();
 }

+ 46 - 5
tauri/src/api.rs

@@ -2,6 +2,9 @@ mod cmd;
 
 use web_view::WebView;
 
+#[cfg(not(any(feature = "dev-server", feature = "embedded-server")))]
+include!(concat!(env!("OUT_DIR"), "/data.rs"));
+
 #[allow(unused_variables)]
 pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
   use cmd::Cmd::*;
@@ -17,12 +20,11 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
                 .eval(&format!(
                   "window['{queue}'] = [];
                   window['{fn}'] = function (payload, salt, ignoreQueue) {{
-                    window.tauri.promisified({{
+                     window.tauri.promisified({{
                       cmd: 'validateSalt',
                       salt: salt
                     }}).then(function () {{
                       const listeners = (window['{listeners}'] && window['{listeners}'][payload.type]) || []
-
                       if (!ignoreQueue && listeners.length === 0) {{
                         window['{queue}'].push({{
                           payload: payload,
@@ -47,8 +49,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
                 Ok(())
             })
             .unwrap();
-
-        },
+        }
         #[cfg(any(feature = "all-api", feature = "readTextFile"))]
         ReadTextFile {
           path,
@@ -136,7 +137,7 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
                   once: {once_flag}
                 }});
 
-                for (let i = 0; i < window['{queue}'].length; i++) {{
+                for (let i = 0; i < (window['{queue}'] || []).length; i++) {{
                   const e = window['{queue}'][i];
                   window['{emit}'](e.payload, e.salt, true)
                 }}
@@ -154,6 +155,46 @@ pub fn handler<T: 'static>(webview: &mut WebView<'_, T>, arg: &str) -> bool {
         Emit { event, payload } => {
           crate::event::on_event(event, payload);
         }
+        LoadAsset {
+          asset,
+          asset_type,
+          callback,
+          error,
+        } => {
+          #[cfg(not(any(feature = "dev-server", feature = "embedded-server")))]
+          {
+            let handle = webview.handle();
+            crate::execute_promise(
+              webview,
+              move || {
+                let read_asset = ASSETS.get(&format!("{}{}{}", env!("TAURI_DIST_DIR"), if asset.starts_with("/") { "" } else { "/" }, asset));
+                if read_asset.is_err() {
+                  return Err(r#""Asset not found""#.to_string());
+                }
+
+                if asset_type == "image" {
+                  let ext = if asset.ends_with("gif") {
+                    "gif"
+                  } else if asset.ends_with("png") {
+                    "png"
+                  } else {
+                    "jpeg"
+                  };
+                  Ok(format!("`data:image/{};base64,{}`", ext, base64::encode(&read_asset.unwrap().into_owned())))
+                } else {
+                  handle
+                    .dispatch(move |_webview| {
+                      _webview.eval(&std::str::from_utf8(&read_asset.unwrap().into_owned()).unwrap())
+                    })
+                    .map_err(|err| format!("`{}`", err))
+                    .map(|_| r#""Asset loaded successfully""#.to_string())
+                }
+              },
+              callback,
+              error,
+            );
+          }
+        }
       }
       true
     }

+ 16 - 3
tauri/src/api/cmd.rs

@@ -34,7 +34,9 @@ pub enum Cmd {
     error: String,
   },
   #[cfg(any(feature = "all-api", feature = "setTitle"))]
-  SetTitle { title: String },
+  SetTitle {
+    title: String,
+  },
   #[cfg(any(feature = "all-api", feature = "execute"))]
   Execute {
     command: String,
@@ -43,7 +45,9 @@ pub enum Cmd {
     error: String,
   },
   #[cfg(any(feature = "all-api", feature = "open"))]
-  Open { uri: String },
+  Open {
+    uri: String,
+  },
   ValidateSalt {
     salt: String,
     callback: String,
@@ -55,5 +59,14 @@ pub enum Cmd {
     once: bool,
   },
   #[cfg(any(feature = "all-api", feature = "emit"))]
-  Emit { event: String, payload: String },
+  Emit {
+    event: String,
+    payload: String,
+  },
+  LoadAsset {
+    asset: String,
+    asset_type: String,
+    callback: String,
+    error: String,
+  },
 }

+ 2 - 5
tauri/src/app.rs

@@ -53,10 +53,7 @@ impl AppBuilder {
     self
   }
 
-  pub fn setup<F: FnMut(&mut WebView<'_, ()>) + 'static>(
-    mut self,
-    setup: F,
-  ) -> Self {
+  pub fn setup<F: FnMut(&mut WebView<'_, ()>) + 'static>(mut self, setup: F) -> Self {
     self.setup = Some(Box::new(setup));
     self
   }
@@ -64,7 +61,7 @@ impl AppBuilder {
   pub fn build(self) -> App {
     App {
       invoke_handler: self.invoke_handler,
-      setup: self.setup
+      setup: self.setup,
     }
   }
 }

+ 36 - 105
tauri/src/app/runner.rs

@@ -1,20 +1,16 @@
-#[cfg(feature = "dev")]
-use clap::{App, Arg};
-
-#[cfg(not(feature = "dev"))]
-#[cfg(feature = "embedded-server")]
-use std::thread;
-
 pub(crate) fn run(application: &mut crate::App) {
-  let debug;
-  let content;
+  let debug = cfg!(debug_assertions);
   let config = crate::config::get();
-  #[cfg(feature = "embedded-server")]
-  let mut server_url: String;
+  let tauri_src = include_str!(concat!(env!("OUT_DIR"), "/tauri_src"));
+  let content = if tauri_src.starts_with("http://") || tauri_src.starts_with("https://") {
+    web_view::Content::Url(tauri_src)
+  } else {
+    web_view::Content::Html(tauri_src)
+  };
 
   #[cfg(feature = "updater")]
   {
-    thread::spawn(|| {
+    std::thread::spawn(|| {
       crate::command::spawn_relative_command(
         "updater".to_string(),
         Vec::new(),
@@ -24,75 +20,6 @@ pub(crate) fn run(application: &mut crate::App) {
     });
   }
 
-  #[cfg(feature = "dev")]
-  {
-    let app = App::new("app")
-      .version("1.0.0")
-      .author("Author")
-      .about("About")
-      .arg(
-        Arg::with_name("path")
-          .short("p")
-          .long("path")
-          .value_name("PATH")
-          .help("Loads the specified URL/HTML into webview")
-          .required(true)
-          .takes_value(true),
-      );
-
-    let matches = app.get_matches();
-    let dev_path = matches.value_of("path").unwrap().to_owned();
-    content = if dev_path.starts_with("http") {
-      web_view::Content::Url(dev_path)
-    } else {
-      web_view::Content::Html(std::fs::read_to_string(dev_path).unwrap())
-    };
-    debug = true;
-  }
-
-  #[cfg(not(feature = "dev"))]
-  {
-    debug = cfg!(debug_assertions);
-    #[cfg(not(feature = "embedded-server"))]
-    {
-      content =
-        web_view::Content::Html(include_str!(concat!(env!("TAURI_DIST_DIR"), "/index.html")));
-    }
-    #[cfg(feature = "embedded-server")]
-    {
-      let port;
-      let port_valid;
-      if config.embedded_server.port == "random" {
-        match crate::tcp::get_available_port() {
-          Some(available_port) => {
-            port = available_port.to_string();
-            port_valid = true;
-          }
-          None => {
-            port = "0".to_string();
-            port_valid = false;
-          }
-        }
-      } else {
-        port = config.embedded_server.port;
-        port_valid = crate::tcp::port_is_available(
-          port
-            .parse::<u16>()
-            .expect(&format!("Invalid port {}", port)),
-        );
-      }
-      if port_valid {
-        server_url = format!("{}:{}", config.embedded_server.host, port);
-        if !server_url.starts_with("http") {
-          server_url = format!("http://{}", server_url);
-        }
-        content = web_view::Content::Url(server_url.clone());
-      } else {
-        panic!(format!("Port {} is not valid or not open", port));
-      }
-    }
-  }
-
   let mut ran_setup = false;
 
   let webview = web_view::builder()
@@ -117,32 +44,36 @@ pub(crate) fn run(application: &mut crate::App) {
     .build()
     .unwrap();
 
-  #[cfg(not(feature = "dev"))]
+  #[cfg(feature = "dev-server")]
+  webview.handle()
+    .dispatch(|_webview| {
+      _webview.eval(include_str!(concat!(env!("TAURI_DIR"), "/tauri.js")))
+    })
+    .unwrap();
+
+  #[cfg(feature = "embedded-server")]
   {
-    #[cfg(feature = "embedded-server")]
-    {
-      thread::spawn(move || {
-        let server = tiny_http::Server::http(
-          server_url
-            .clone()
-            .replace("http://", "")
-            .replace("https://", ""),
-        )
-        .expect(&format!(
-          "Could not start embedded server with the specified url: {}",
-          server_url
-        ));
-        for request in server.incoming_requests() {
-          let mut url = request.url().to_string();
-          if url == "/" {
-            url = "/index.html".to_string();
-          }
-          request
-            .respond(crate::server::asset_response(&url))
-            .unwrap();
+    std::thread::spawn(move || {
+      let server = tiny_http::Server::http(
+        tauri_src
+          .clone()
+          .replace("http://", "")
+          .replace("https://", ""),
+      )
+      .expect(&format!(
+        "Could not start embedded server with the specified url: {}",
+        tauri_src
+      ));
+      for request in server.incoming_requests() {
+        let mut url = request.url().to_string();
+        if url == "/" {
+          url = "/index.tauri.html".to_string();
         }
-      });
-    }
+        request
+          .respond(crate::server::asset_response(&url))
+          .unwrap();
+      }
+    });
   }
 
   webview.run().unwrap();

+ 13 - 1
tauri/src/config.rs

@@ -69,8 +69,20 @@ pub struct Config {
   pub window: WindowConfig,
   #[serde(default = "default_embedded_server")]
   pub embedded_server: EmbeddedServerConfig,
+  #[serde(default = "default_dev_path")]
+  pub dev_path: String,
+  #[serde(default = "default_inlined_assets")]
+  pub inlined_assets: Vec<String>,
+}
+
+fn default_inlined_assets() -> Vec<String> {
+  Vec::new()
+}
+
+fn default_dev_path() -> String {
+  "".to_string()
 }
 
 pub fn get() -> Config {
-  serde_json::from_str(include_str!(concat!(env!("TAURI_CONFIG_DIR"), "/config.json"))).unwrap()
+  serde_json::from_str(include_str!(concat!(env!("TAURI_DIR"), "/config.json"))).unwrap()
 }

+ 1 - 1
tauri/src/event.rs

@@ -34,7 +34,7 @@ pub fn listen<F: FnMut(String) + 'static>(id: &'static str, handler: F) {
       id.to_string(),
       EventHandler {
         on_event: Box::new(handler),
-      }
+      },
     );
   });
 }

+ 2 - 1
tauri/src/lib.rs

@@ -1,6 +1,7 @@
 #[macro_use]
 extern crate serde_derive;
 
+#[cfg(feature = "updater")]
 #[macro_use]
 mod macros;
 
@@ -19,13 +20,13 @@ pub mod file;
 pub mod file_system;
 #[cfg(feature = "updater")]
 pub mod http;
+#[cfg(feature = "updater")]
 pub mod platform;
 pub mod process;
 pub mod rpc;
 pub mod salt;
 #[cfg(feature = "embedded-server")]
 pub mod server;
-pub mod tcp;
 #[cfg(feature = "updater")]
 pub mod updater;
 

+ 1 - 1
tauri/src/salt.rs

@@ -1,6 +1,6 @@
 use std::sync::Mutex;
-use web_view::WebView;
 use uuid::Uuid;
+use web_view::WebView;
 
 struct Salt {
   value: String,

+ 0 - 0
tauri/src/tcp.rs → tauri/tcp.rs


+ 1 - 4
tauri/test/fixture/tauri.conf.js

@@ -3,12 +3,9 @@ const distDir = path.resolve(__dirname, './dist')
 
 module.exports = function () {
   return {
-    automaticStart: {
-      active: true
-    },
     build: {
       distDir: distDir,
-      devPath: 'http://localhost:4000' // devServer URL or path to html file
+      devPath: 'http://localhost:4000' // devServer URL or html dir
     },
     ctx: {},
     tauri: {

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff