Fix(All) - Add Edge support to GUIJS (#452)

* fix edge api to use window.external.invoke

* remove tauri-examples

* remove if statement

* add more cases.

* add batch_to_exe script
This commit is contained in:
Tensor-Programming 2020-02-23 18:15:57 -05:00 committed by GitHub
parent d79eb4fc21
commit 7b8edd29ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 165 additions and 94 deletions

4
.gitignore vendored
View File

@ -36,6 +36,9 @@ typings/
# Optional npm cache directory
.npm
# Optional yarn cache directory
.yarn
# Optional eslint cache
.eslintcache
@ -63,6 +66,7 @@ package-lock.json
proptest-regressions/
TODO.md
# Tauri output
/bundle.json
/config.json

57
.scripts/batch_to_exe.cmd Normal file
View File

@ -0,0 +1,57 @@
@ECHO OFF
ECHO Make EXE From BAT
ECHO.
ECHO.
REM Usage:
REM MakeExeFromBat BatFileToConvert [IncludeFile1] [IncludeFile2] [...]
REM
REM Required Parameters:
REM BatFileToConvert
REM Source batch file to use to produce the output Exe file.
REM
REM Optional Parameters:
REM IncludeFile
REM Additional files to include in the Exe file.
REM You can include external tools used by the batch file so they are available on the executing machine.
SETLOCAL
REM Configuration (no quotes needed):
SET PathTo7Zip=
REM ---- Do not modify anything below this line ----
SET OutputFile="%~n1.exe"
SET SourceFiles="%TEMP%MakeEXE_files.txt"
SET Config="%TEMP%MakeEXE_config.txt"
SET Source7ZFile="%Temp%MakeEXE.7z"
REM Remove existing files
IF EXIST %OutputFile% DEL %OutputFile%
REM Build source archive
ECHO "%~dpnx1" > %SourceFiles%
:AddInclude
IF {%2}=={} GOTO EndInclude
ECHO "%~dpnx2" >> %SourceFiles%
SHIFT /2
GOTO AddInclude
:EndInclude
"%PathTo7Zip%7za.exe" a %Source7ZFile% @%SourceFiles%
REM Build config file
ECHO ;!@Install@!UTF-8! > %Config%
ECHO RunProgram="%~nx1" >> %Config%
ECHO ;!@InstallEnd@! >> %Config%
REM Build EXE
COPY /B "%PathTo7Zip%7zsd.sfx" + %Config% + %Source7ZFile% %OutputFile%
REM Clean up
IF EXIST %SourceFiles% DEL %SourceFiles%
IF EXIST %Config% DEL %Config%
IF EXIST %Source7ZFile% DEL %Source7ZFile%
ENDLOCAL

View File

@ -18,20 +18,32 @@
* and also whitelist them based upon the developer's settings.
*/
// makes the window.external.invoke API available after window.location.href changes
if (navigator.platform != "Win64" && navigator.plaform != "Win32") {
// makes the window.external.invoke API available after window.location.href changes
switch (navigator.platform) {
case "Macintosh":
case "MacPPC":
case "MacIntel":
case "Mac68K":
window.external = this
if (navigator.platform == "MacIntel") {
invoke = function (x) {
webkit.messageHandlers.invoke.postMessage(x);
}
} else {
break;
case "Windows":
case "WinCE":
case "Win32":
case "Win64":
break;
default:
window.external = this
invoke = function (x) {
window.webkit.messageHandlers.external.postMessage(x);
}
}
break;
}
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
@ -61,10 +73,10 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
* @private
*/
var __whitelistWarning = function (func) {
console.warn('%c[Tauri] Danger \ntauri.' + func + ' not whitelisted 💣\n%c\nAdd to tauri.conf.json: \n\ntauri: \n whitelist: { \n ' + func + ': true \n\nReference: https://github.com/tauri-apps/tauri/wiki' + func , 'background: red; color: white; font-weight: 800; padding: 2px; font-size:1.5em', ' ')
console.warn('%c[Tauri] Danger \ntauri.' + func + ' not whitelisted 💣\n%c\nAdd to tauri.conf.json: \n\ntauri: \n whitelist: { \n ' + func + ': true \n\nReference: https://github.com/tauri-apps/tauri/wiki' + func, 'background: red; color: white; font-weight: 800; padding: 2px; font-size:1.5em', ' ')
return __reject()
}
<% } %>
}
<% } %>
<% if (ctx.dev) { %>
/**
@ -385,7 +397,7 @@ window.tauri = {
<% } %>
},
bridge: function bridge(command, payload) {
bridge: function bridge(command, payload) {
<% if (tauri.whitelist.bridge === true || tauri.whitelist.all === true) { %>
Object.freeze(command);
@ -407,13 +419,13 @@ window.tauri = {
<% } %>
},
loadAsset: function loadAsset(assetName, assetType) {
loadAsset: function loadAsset(assetName, assetType) {
return this.promisified({
cmd: 'loadAsset',
asset: assetName,
asset_type: assetType || 'unknown'
})
}
}
};
// init tauri API
@ -443,8 +455,8 @@ document.addEventListener('error', function (e) {
}
}, true)
// open <a href="..."> links with the Tauri API
function __openLinks () {
// open <a href="..."> links with the Tauri API
function __openLinks() {
document.querySelector('body').addEventListener('click', function (e) {
var target = e.target
while (target != null) {

View File

@ -28,9 +28,7 @@ pub fn format_command(path: String, command: String) -> String {
pub fn relative_command(command: String) -> crate::Result<String> {
match std::env::current_exe()?.parent() {
Some(exe_dir) => Ok(format_command(exe_dir.display().to_string(), command)),
None => {
Err(crate::ErrorKind::Command("Could not evaluate executable dir".to_string()).into())
}
None => Err(crate::ErrorKind::Command("Could not evaluate executable dir".to_string()).into()),
}
}