Skip to content

Commit cd5b401

Browse files
Ngo Iok Ui (Wu Yu Wei)lucasfernog
andauthored
feature: import official webview rust binding (#846)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent dac1db3 commit cd5b401

31 files changed

Lines changed: 733 additions & 499 deletions

.changes/tauri-webview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": minor
3+
---
4+
5+
Moving the webview implementation to [webview](https://github.com/webview/webview), with the [official Rust binding](https://github.com/webview/webview_rust).
6+
This is a breaking change.
7+
IE support has been dropped, so the `edge` object on `tauri.conf.json > tauri` no longer exists and you need to remove it.
8+
`webview.handle()` has been replaced with `webview.as_mut()`.

cli/tauri.js/api-src/tauri.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare global {
2-
interface External {
3-
invoke: (command: string) => void
2+
interface Window {
3+
__TAURI_INVOKE_HANDLER__: (command: string) => void
44
}
55
}
66

@@ -21,7 +21,7 @@ function uid(): string {
2121
* @param args
2222
*/
2323
function invoke(args: any): void {
24-
window.external.invoke(typeof args === 'object' ? JSON.stringify(args) : args)
24+
window.__TAURI_INVOKE_HANDLER__(args)
2525
}
2626

2727
function transformCallback(callback?: (response: any) => void, once = false): string {

cli/tauri.js/src/api/info.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ async function printAppInfo(tauriDir: string): Promise<void> {
192192
key: ' CSP',
193193
value: config.tauri.security ? config.tauri.security.csp : 'unset'
194194
})
195-
printInfo({
196-
key: ' Windows',
197-
value: config.tauri.edge?.active ? 'Edge' : 'MSHTML'
198-
})
199195
printInfo({
200196
key: ' distDir',
201197
value: config.build

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ const getTauriConfig = (cfg: Partial<TauriConfig>): TauriConfig => {
5454
security: {
5555
csp: "default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'"
5656
},
57-
edge: {
58-
active: true
59-
},
6057
inliner: {
6158
active: true
6259
}

cli/tauri.js/src/runner.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Runner {
117117
self.__parseHtml(cfg, indexDir, false)
118118
.then(({ html }) => {
119119
const headers: { [key: string]: string } = {}
120-
if(proxyRes.headers['content-type']) {
120+
if (proxyRes.headers['content-type']) {
121121
headers['content-type'] = proxyRes.headers['content-type']
122122
} else {
123123
const charsetMatch = /charset="(\S+)"/g.exec(bodyStr)
@@ -527,10 +527,6 @@ class Runner {
527527
tomlFeatures.push(...whitelist.map(toKebabCase))
528528
}
529529

530-
if (cfg.tauri.edge.active) {
531-
tomlFeatures.push('edge')
532-
}
533-
534530
if (cfg.tauri.cli) {
535531
tomlFeatures.push('cli')
536532
}

cli/tauri.js/src/template/defaultConfig.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ export default {
4545
security: {
4646
csp: "default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'"
4747
},
48-
edge: {
49-
active: true
50-
},
5148
inliner: {
5249
active: true
5350
}

cli/tauri.js/src/types/config.schema.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,6 @@
391391
"$ref": "#/definitions/CliConfig",
392392
"description": "app's CLI definition"
393393
},
394-
"edge": {
395-
"additionalProperties": false,
396-
"defaultProperties": [
397-
],
398-
"properties": {
399-
"active": {
400-
"type": "boolean"
401-
}
402-
},
403-
"type": "object"
404-
},
405394
"embeddedServer": {
406395
"additionalProperties": false,
407396
"defaultProperties": [
@@ -496,7 +485,6 @@
496485
},
497486
"required": [
498487
"bundle",
499-
"edge",
500488
"embeddedServer",
501489
"inliner",
502490
"security",

cli/tauri.js/src/types/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ export interface TauriConfig {
285285
security: {
286286
csp?: string
287287
}
288-
edge: {
289-
active?: boolean
290-
}
291288
inliner: {
292289
active?: boolean
293290
}

cli/tauri.js/src/types/config.validator.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,17 +401,6 @@ export const TauriConfigSchema = {
401401
"$ref": "#/definitions/CliConfig",
402402
"description": "app's CLI definition"
403403
},
404-
"edge": {
405-
"additionalProperties": false,
406-
"defaultProperties": [
407-
],
408-
"properties": {
409-
"active": {
410-
"type": "boolean"
411-
}
412-
},
413-
"type": "object"
414-
},
415404
"embeddedServer": {
416405
"additionalProperties": false,
417406
"defaultProperties": [
@@ -506,7 +495,6 @@ export const TauriConfigSchema = {
506495
},
507496
"required": [
508497
"bundle",
509-
"edge",
510498
"embeddedServer",
511499
"inliner",
512500
"security",

cli/tauri.js/templates/tauri.js

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,29 @@ if (!String.prototype.startsWith) {
66
}
77
}
88

9-
// makes the window.external.invoke API available after window.location.href changes
10-
switch (navigator.platform) {
11-
case "Macintosh":
12-
case "MacPPC":
13-
case "MacIntel":
14-
case "Mac68K":
15-
window.external = this
16-
invoke = function (x) {
17-
webkit.messageHandlers.invoke.postMessage(x);
18-
}
19-
break;
20-
case "Windows":
21-
case "WinCE":
22-
case "Win32":
23-
case "Win64":
24-
break;
25-
default:
26-
window.external = this
27-
invoke = function (x) {
28-
window.webkit.messageHandlers.external.postMessage(x);
9+
(function () {
10+
function webviewBind (name) {
11+
var RPC = window._rpc = (window._rpc || { nextSeq: 1 });
12+
window[name] = function () {
13+
var seq = RPC.nextSeq++;
14+
var promise = new Promise(function (resolve, reject) {
15+
RPC[seq] = {
16+
resolve: resolve,
17+
reject: reject,
18+
};
19+
});
20+
window.external.invoke(JSON.stringify({
21+
id: seq,
22+
method: name,
23+
params: Array.prototype.slice.call(arguments),
24+
}));
25+
return promise;
2926
}
30-
break;
31-
}
27+
}
28+
if (!window.__TAURI_INVOKE_HANDLER__) {
29+
webviewBind('__TAURI_INVOKE_HANDLER__')
30+
}
3231

33-
(function () {
3432
function s4() {
3533
return Math.floor((1 + Math.random()) * 0x10000)
3634
.toString(16)
@@ -89,9 +87,6 @@ switch (navigator.platform) {
8987
if (!window.__TAURI__) {
9088
window.__TAURI__ = {}
9189
}
92-
window.__TAURI__.invoke = function invoke(args) {
93-
window.external.invoke(JSON.stringify(args))
94-
}
9590

9691
window.__TAURI__.transformCallback = function transformCallback(callback) {
9792
var once = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false
@@ -109,10 +104,10 @@ switch (navigator.platform) {
109104
}
110105

111106
window.__TAURI__.promisified = function promisified(args) {
112-
var _this = this;
107+
var _this = this
113108

114109
return new Promise(function (resolve, reject) {
115-
_this.invoke(_objectSpread({
110+
window.__TAURI_INVOKE_HANDLER__(_objectSpread({
116111
callback: _this.transformCallback(resolve),
117112
error: _this.transformCallback(reject)
118113
}, args))
@@ -127,19 +122,6 @@ switch (navigator.platform) {
127122
})
128123
}
129124

130-
// init tauri API
131-
try {
132-
window.__TAURI__.invoke({
133-
cmd: 'init'
134-
})
135-
} catch (e) {
136-
window.addEventListener('DOMContentLoaded', function () {
137-
window.__TAURI__.invoke({
138-
cmd: 'init'
139-
})
140-
}, true)
141-
}
142-
143125
document.addEventListener('error', function (e) {
144126
var target = e.target
145127
while (target != null) {
@@ -161,7 +143,7 @@ switch (navigator.platform) {
161143
while (target != null) {
162144
if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
163145
if (target.href && target.href.startsWith('http') && target.target === '_blank') {
164-
window.__TAURI__.invoke({
146+
window.__TAURI_INVOKE_HANDLER__({
165147
cmd: 'open',
166148
uri: target.href
167149
})

0 commit comments

Comments
 (0)