浏览代码

fix(tauri) use web-view fork to fix windows build on SDK 10.0.19041.1 (#657)

Lucas Fernandes Nogueira 5 年之前
父节点
当前提交
3953662b82

+ 2 - 2
cli/tauri.js/src/api/info.ts

@@ -133,7 +133,7 @@ function printAppInfo(tauriDir: string): void {
     printInfo({
     printInfo({
       key: '  build-type',
       key: '  build-type',
       value:
       value:
-        config.tauri.bundle && config.tauri.bundle.active ? 'bundle' : 'build'
+        config.tauri.bundle?.active ? 'bundle' : 'build'
     })
     })
     printInfo({
     printInfo({
       key: '  CSP',
       key: '  CSP',
@@ -141,7 +141,7 @@ function printAppInfo(tauriDir: string): void {
     })
     })
     printInfo({
     printInfo({
       key: '  Windows',
       key: '  Windows',
-      value: config.tauri.edge && config.tauri.edge.active ? 'Edge' : 'MSHTML'
+      value: config.tauri.edge?.active ? 'Edge' : 'MSHTML'
     })
     })
     printInfo({
     printInfo({
       key: '  distDir',
       key: '  distDir',

+ 1 - 0
cli/tauri.js/src/entry.ts

@@ -5,6 +5,7 @@ import { TauriConfig } from './types/config'
 
 
 export const generate = (outDir: string, cfg: TauriConfig): void => {
 export const generate = (outDir: string, cfg: TauriConfig): void => {
   // this MUST be from the templates repo
   // this MUST be from the templates repo
+  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
   const apiTemplate = require('../templates/tauri.js').default
   const apiTemplate = require('../templates/tauri.js').default
   const compiledApi = template(apiTemplate)
   const compiledApi = template(apiTemplate)
 
 

+ 1 - 1
cli/tauri.js/src/helpers/tauri-config.ts

@@ -70,7 +70,7 @@ const getTauriConfig = (cfg: Partial<TauriConfig>): TauriConfig => {
     process.exit(1)
     process.exit(1)
   }
   }
 
 
-  const runningDevServer = config.build.devPath && config.build.devPath.startsWith('http')
+  const runningDevServer = config.build.devPath?.startsWith('http')
   if (!runningDevServer) {
   if (!runningDevServer) {
     config.build.devPath = appPaths.resolve.tauri(config.build.devPath)
     config.build.devPath = appPaths.resolve.tauri(config.build.devPath)
     process.env.TAURI_DIST_DIR = config.build.devPath
     process.env.TAURI_DIST_DIR = config.build.devPath

+ 32 - 20
cli/tauri.js/src/runner.ts

@@ -66,13 +66,14 @@ class Runner {
         }
         }
       })
       })
 
 
-      ls.stderr && ls.stderr.pipe(process.stderr)
-      ls.stdout && ls.stdout.pipe(process.stdout)
+      ls.stderr?.pipe(process.stderr)
+       ls.stdout?.pipe(process.stdout)
     }
     }
 
 
-    const tomlContents = this.__getManifest() as any as CargoManifest
-    this.__whitelistApi(cfg, tomlContents)
-    this.__rewriteManifest(tomlContents as any as JsonMap)
+    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+    const cargoManifest = this.__getManifest() as any as CargoManifest
+    this.__whitelistApi(cfg, cargoManifest)
+    this.__rewriteManifest(cargoManifest as unknown as toml.JsonMap)
 
 
     entry.generate(tauriDir, cfg)
     entry.generate(tauriDir, cfg)
 
 
@@ -159,8 +160,8 @@ class Runner {
     // eslint-disable-next-line security/detect-non-literal-fs-filename
     // eslint-disable-next-line security/detect-non-literal-fs-filename
 
 
     let tauriPaths: string[] = []
     let tauriPaths: string[] = []
-    if (typeof tomlContents.dependencies.tauri !== 'string' && tomlContents.dependencies.tauri.path) {
-      const tauriPath = path.resolve(tauriDir, tomlContents.dependencies.tauri.path)
+    if (typeof cargoManifest.dependencies.tauri !== 'string' && cargoManifest.dependencies.tauri.path) {
+      const tauriPath = path.resolve(tauriDir, cargoManifest.dependencies.tauri.path)
       tauriPaths = [
       tauriPaths = [
         tauriPath,
         tauriPath,
         `${tauriPath}-api`,
         `${tauriPath}-api`,
@@ -222,9 +223,9 @@ class Runner {
       spawnSync(command, args, appDir)
       spawnSync(command, args, appDir)
     }
     }
 
 
-    const tomlContents = this.__getManifest()
-    this.__whitelistApi(cfg, tomlContents)
-    this.__rewriteManifest(tomlContents)
+    const cargoManifest = this.__getManifest()
+    this.__whitelistApi(cfg, cargoManifest as unknown as CargoManifest)
+    this.__rewriteManifest(cargoManifest)
 
 
     entry.generate(tauriDir, cfg)
     entry.generate(tauriDir, cfg)
 
 
@@ -286,6 +287,7 @@ class Runner {
 
 
         // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
         // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
         if (!((cfg.ctx.dev && cfg.build.devPath.startsWith('http')) || cfg.tauri.embeddedServer.active)) {
         if (!((cfg.ctx.dev && cfg.build.devPath.startsWith('http')) || cfg.tauri.embeddedServer.active)) {
+          // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
           const mutationObserverTemplate = require('../templates/mutation-observer').default
           const mutationObserverTemplate = require('../templates/mutation-observer').default
           const compiledMutationObserver = template(mutationObserverTemplate)
           const compiledMutationObserver = template(mutationObserverTemplate)
 
 
@@ -340,7 +342,8 @@ class Runner {
       } else {
       } else {
         const cwd = process.cwd()
         const cwd = process.cwd()
         process.chdir(indexDir) // the inliner requires this to properly work
         process.chdir(indexDir) // the inliner requires this to properly work
-        new Inliner({ source: originalHtml }, (err: Error, html: string) => {
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
+        const inliner = new Inliner({ source: originalHtml }, (err: Error, html: string) => {
           process.chdir(cwd) // reset CWD
           process.chdir(cwd) // reset CWD
           if (err) {
           if (err) {
             reject(err)
             reject(err)
@@ -348,7 +351,9 @@ class Runner {
             const rewrittenHtml = rewriteHtml(html, domInterceptor)
             const rewrittenHtml = rewriteHtml(html, domInterceptor)
             resolve({ inlinedAssets, html: rewrittenHtml })
             resolve({ inlinedAssets, html: rewrittenHtml })
           }
           }
-        }).on('progress', (event: string) => {
+        })
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
+        inliner.on('progress', (event: string) => {
           const match = event.match(/([\S\d]+)\.([\S\d]+)/g)
           const match = event.match(/([\S\d]+)\.([\S\d]+)/g)
           match && inlinedAssets.push(match[0])
           match && inlinedAssets.push(match[0])
         })
         })
@@ -358,8 +363,8 @@ class Runner {
 
 
   async stop(): Promise<void> {
   async stop(): Promise<void> {
     return await new Promise((resolve, reject) => {
     return await new Promise((resolve, reject) => {
-      this.devServer && this.devServer.close()
-      this.tauriWatcher && this.tauriWatcher.close()
+      this.devServer?.close()
+      this.tauriWatcher?.close().catch(reject)
       this.__stopCargo()
       this.__stopCargo()
         .then(resolve)
         .then(resolve)
         .catch(reject)
         .catch(reject)
@@ -455,13 +460,13 @@ class Runner {
   __getManifest(): JsonMap {
   __getManifest(): JsonMap {
     const tomlPath = this.__getManifestPath()
     const tomlPath = this.__getManifestPath()
     const tomlFile = readFileSync(tomlPath).toString()
     const tomlFile = readFileSync(tomlPath).toString()
-    const tomlContents = toml.parse(tomlFile)
-    return tomlContents
+    const cargoManifest = toml.parse(tomlFile)
+    return cargoManifest
   }
   }
 
 
-  __rewriteManifest(tomlContents: JsonMap): void {
+  __rewriteManifest(cargoManifest: JsonMap): void {
     const tomlPath = this.__getManifestPath()
     const tomlPath = this.__getManifestPath()
-    const output = toml.stringify(tomlContents)
+    const output = toml.stringify(cargoManifest)
 
 
     this.rewritingToml = true
     this.rewritingToml = true
     writeFileSync(tomlPath, output)
     writeFileSync(tomlPath, output)
@@ -472,7 +477,7 @@ class Runner {
 
 
   __whitelistApi(
   __whitelistApi(
     cfg: TauriConfig,
     cfg: TauriConfig,
-    tomlContents: { [index: string]: any }
+    manifest: CargoManifest
   ): void {
   ): void {
     const tomlFeatures = []
     const tomlFeatures = []
 
 
@@ -494,7 +499,14 @@ class Runner {
       tomlFeatures.push('edge')
       tomlFeatures.push('edge')
     }
     }
 
 
-    tomlContents.dependencies.tauri.features = tomlFeatures
+    if (typeof manifest.dependencies.tauri === 'string') {
+      manifest.dependencies.tauri = {
+        version: manifest.dependencies.tauri,
+        features: tomlFeatures
+      }
+    } else {
+      manifest.dependencies.tauri.features = tomlFeatures
+    }
   }
   }
 }
 }
 
 

+ 3 - 2
cli/tauri.js/src/types/cargo.ts

@@ -4,8 +4,9 @@ export interface CargoManifest {
 }
 }
 
 
 export interface CargoManifestDependency {
 export interface CargoManifestDependency {
-  version: string
-  path: string
+  version?: string
+  path?: string
+  features?: string[]
 }
 }
 
 
 export interface CargoLock {
 export interface CargoLock {

+ 2 - 2
tauri/Cargo.toml

@@ -12,8 +12,8 @@ exclude = ["test/fixture/**"]
 [dependencies]
 [dependencies]
 serde_json = "1.0"
 serde_json = "1.0"
 serde = { version = "1.0", features = ["derive"] }
 serde = { version = "1.0", features = ["derive"] }
-webview-sys = "=0.5.0"
-web-view = "=0.6.2"
+webview-sys = { git = "https://github.com/tauri-apps/web-view" }
+web-view = { git = "https://github.com/tauri-apps/web-view" }
 tauri_includedir = "0.5.0"
 tauri_includedir = "0.5.0"
 phf = "0.8.0"
 phf = "0.8.0"
 base64 = "0.12.1"
 base64 = "0.12.1"

+ 1 - 1
tauri/src/app/runner.rs

@@ -97,7 +97,7 @@ fn setup_content(_: Config) -> crate::Result<Content<String>> {
       .into_string()
       .into_string()
       .expect("Unable to convert to normal String"),
       .expect("Unable to convert to normal String"),
   };
   };
-  let index_path = Path::new(dist_dir).join("index.tauri.html");
+  let index_path = Path::new(&dist_dir).join("index.tauri.html");
 
 
   Ok(Content::Html(read_to_string(index_path)?))
   Ok(Content::Html(read_to_string(index_path)?))
 }
 }