diff --git a/cli/tauri.js/templates/tauri.js b/cli/tauri.js/templates/tauri.js index 01818a975..94f781f79 100644 --- a/cli/tauri.js/templates/tauri.js +++ b/cli/tauri.js/templates/tauri.js @@ -18,6 +18,14 @@ * and also whitelist them based upon the developer's settings. */ +// polyfills +if (!String.prototype.startsWith) { + String.prototype.startsWith = function (searchString, position) { + position = position || 0 + return this.substr(position, searchString.length) === searchString + } +} + // makes the window.external.invoke API available after window.location.href changes switch (navigator.platform) { @@ -166,7 +174,7 @@ window.tauri = { <% } %> transformCallback: function transformCallback(callback) { var once = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var identifier = Object.freeze(uid()); + var identifier = uid(); window[identifier] = function (result) { if (once) { @@ -209,7 +217,6 @@ window.tauri = { <% } %> readTextFile: function readTextFile(path) { <% if (tauri.whitelist.readTextFile === true || tauri.whitelist.all === true) { %> - Object.freeze(path); return this.promisified({ cmd: 'readTextFile', path: path @@ -233,7 +240,6 @@ window.tauri = { <% } %> readBinaryFile: function readBinaryFile(path) { <% if (tauri.whitelist.readBinaryFile === true || tauri.whitelist.all === true) { %> - Object.freeze(path); return this.promisified({ cmd: 'readBinaryFile', path: path @@ -258,7 +264,9 @@ window.tauri = { <% } %> writeFile: function writeFile(cfg) { <% if (tauri.whitelist.writeFile === true || tauri.whitelist.all === true) { %> - Object.freeze(cfg); + if (_typeof(cfg) === 'object') { + Object.freeze(cfg); + } this.invoke({ cmd: 'writeFile', file: cfg.file, @@ -283,8 +291,6 @@ window.tauri = { <% } %> listFiles: function listFiles(path) { <% if (tauri.whitelist.listFiles === true || tauri.whitelist.all === true) { %> - - Object.freeze(path); return this.promisified({ cmd: 'listFiles', path: path @@ -308,7 +314,6 @@ window.tauri = { <% } %> listDirs: function listDirs(path) { <% if (tauri.whitelist.listDirs === true || tauri.whitelist.all === true) { %> - Object.freeze(path); return this.promisified({ cmd: 'listDirs', path: path @@ -330,7 +335,6 @@ window.tauri = { <% } %> setTitle: function setTitle(title) { <% if (tauri.whitelist.setTitle === true || tauri.whitelist.all === true) { %> - Object.freeze(title); this.invoke({ cmd: 'setTitle', title: title @@ -352,7 +356,6 @@ window.tauri = { <% } %> open: function open(uri) { <% if (tauri.whitelist.open === true || tauri.whitelist.all === true) { %> - Object.freeze(uri); this.invoke({ cmd: 'open', uri: uri @@ -378,9 +381,7 @@ window.tauri = { execute: function execute(command, args) { <% if (tauri.whitelist.execute === true || tauri.whitelist.all === true) { %> - Object.freeze(command); - - if (typeof args === 'string' || _typeof(args) === 'object') { + if (_typeof(args) === 'object') { Object.freeze(args); } @@ -400,9 +401,7 @@ window.tauri = { bridge: function bridge(command, payload) { <% if (tauri.whitelist.bridge === true || tauri.whitelist.all === true) { %> - Object.freeze(command); - - if (typeof payload === 'string' || _typeof(payload) === 'object') { + if (_typeof(payload) === 'object') { Object.freeze(payload); } @@ -446,7 +445,7 @@ document.addEventListener('error', function (e) { while (target != null) { if (target.matches ? target.matches('img') : target.msMatchesSelector('img')) { window.tauri.loadAsset(target.src, 'image') - .then(img => { + .then(function (img) { target.src = img }) break @@ -463,6 +462,7 @@ function __openLinks() { if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) { if (target.href && target.href.startsWith('http') && target.target === '_blank') { window.tauri.open(target.href) + e.preventDefault() } break } diff --git a/tauri/src/app/runner.rs b/tauri/src/app/runner.rs index de6103326..d5ce62081 100644 --- a/tauri/src/app/runner.rs +++ b/tauri/src/app/runner.rs @@ -217,7 +217,7 @@ fn build_webview( Content::Html(ref html) => html, Content::Url(ref url) => url, }; - webview.eval(&format!("window.location.href = `{}`", content_href))?; + webview.eval(&format!(r#"window.location.href = "{}""#, content_href))?; } else if let Ok(b) = crate::endpoints::handle(webview, arg) { if !b { application.run_invoke_handler(webview, arg); diff --git a/tauri/src/endpoints.rs b/tauri/src/endpoints.rs index 943340c6e..18e4b6b35 100644 --- a/tauri/src/endpoints.rs +++ b/tauri/src/endpoints.rs @@ -243,7 +243,7 @@ fn load_asset( "jpeg" }; Ok(format!( - "`data:image/{};base64,{}`", + r#""data:image/{};base64,{}""#, ext, base64::encode(&read_asset.expect("Failed to read asset type").into_owned()) )) @@ -259,7 +259,7 @@ fn load_asset( _webview.eval(asset_str) } }) - .map_err(|err| crate::ErrorKind::Promise(format!("`{}`", err)).into()) + .map_err(|err| crate::ErrorKind::Promise(format!(r#""{}""#, err)).into()) .map(|_| r#""Asset loaded successfully""#.to_string()) } }, diff --git a/tauri/src/lib.rs b/tauri/src/lib.rs index 8ced19d61..18e1d8134 100644 --- a/tauri/src/lib.rs +++ b/tauri/src/lib.rs @@ -89,7 +89,7 @@ pub fn call( || { api::command::get_output(command, args, Stdio::piped()) .map_err(|err| crate::ErrorKind::Promise(err.to_string()).into()) - .map(|output| format!("`{}`", output)) + .map(|output| format!(r#""{}""#, output)) }, callback, error,