mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Added error handler for dealing with loading user js code
This commit is contained in:
@@ -140,6 +140,16 @@ void Debug(struct Application *app, const char *message, ... ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Error(struct Application *app, const char *message, ... ) {
|
||||||
|
const char *temp = concat("LEFfenestri (C) | ", message);
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
vsnprintf(logbuffer, MAXMESSAGE, temp, args);
|
||||||
|
app->sendMessageToBackend(&logbuffer[0]);
|
||||||
|
MEMFREE(temp);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
void Fatal(struct Application *app, const char *message, ... ) {
|
void Fatal(struct Application *app, const char *message, ... ) {
|
||||||
const char *temp = concat("LFFfenestri (C) | ", message);
|
const char *temp = concat("LFFfenestri (C) | ", message);
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -246,7 +256,10 @@ void messageHandler(id self, SEL cmd, id contentController, id message) {
|
|||||||
struct Application *app = (struct Application *)objc_getAssociatedObject(
|
struct Application *app = (struct Application *)objc_getAssociatedObject(
|
||||||
self, "application");
|
self, "application");
|
||||||
const char *name = (const char *)msg(msg(message, s("name")), s("UTF8String"));
|
const char *name = (const char *)msg(msg(message, s("name")), s("UTF8String"));
|
||||||
if( strcmp(name, "completed") == 0) {
|
if( strcmp(name, "error") == 0 ) {
|
||||||
|
printf("There was a Javascript error. Please open the devtools for more information.\n");
|
||||||
|
Show(app);
|
||||||
|
} else if( strcmp(name, "completed") == 0) {
|
||||||
// Delete handler
|
// Delete handler
|
||||||
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("completed"));
|
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("completed"));
|
||||||
|
|
||||||
@@ -450,6 +463,7 @@ void DestroyApplication(struct Application *app) {
|
|||||||
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("contextMenu"));
|
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("contextMenu"));
|
||||||
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("windowDrag"));
|
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("windowDrag"));
|
||||||
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("external"));
|
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("external"));
|
||||||
|
msg(app->manager, s("removeScriptMessageHandlerForName:"), str("error"));
|
||||||
|
|
||||||
// Close main window
|
// Close main window
|
||||||
msg(app->mainWindow, s("close"));
|
msg(app->mainWindow, s("close"));
|
||||||
@@ -1534,6 +1548,7 @@ void Run(struct Application *app, int argc, char **argv) {
|
|||||||
id manager = msg(config, s("userContentController"));
|
id manager = msg(config, s("userContentController"));
|
||||||
msg(manager, s("addScriptMessageHandler:name:"), app->delegate, str("external"));
|
msg(manager, s("addScriptMessageHandler:name:"), app->delegate, str("external"));
|
||||||
msg(manager, s("addScriptMessageHandler:name:"), app->delegate, str("completed"));
|
msg(manager, s("addScriptMessageHandler:name:"), app->delegate, str("completed"));
|
||||||
|
msg(manager, s("addScriptMessageHandler:name:"), app->delegate, str("error"));
|
||||||
app->manager = manager;
|
app->manager = manager;
|
||||||
|
|
||||||
id wkwebview = msg(c("WKWebView"), s("alloc"));
|
id wkwebview = msg(c("WKWebView"), s("alloc"));
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -10,6 +10,7 @@ The lightweight framework for web-like apps
|
|||||||
/* jshint esversion: 6 */
|
/* jshint esversion: 6 */
|
||||||
import { SetBindings } from './bindings';
|
import { SetBindings } from './bindings';
|
||||||
import { Init } from './main';
|
import { Init } from './main';
|
||||||
|
import {RaiseError} from '../desktop/darwin';
|
||||||
|
|
||||||
// Setup global error handler
|
// Setup global error handler
|
||||||
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||||
@@ -21,7 +22,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|||||||
error: JSON.stringify(error),
|
error: JSON.stringify(error),
|
||||||
stack: function() { return JSON.stringify(new Error().stack); }(),
|
stack: function() { return JSON.stringify(new Error().stack); }(),
|
||||||
};
|
};
|
||||||
window.wails.Log.Error(JSON.stringify(errorMessage));
|
RaiseError(errorMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialise the Runtime
|
// Initialise the Runtime
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ export function SendMessage(message) {
|
|||||||
window.webkit.messageHandlers.external.postMessage(message);
|
window.webkit.messageHandlers.external.postMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RaiseError(message) {
|
||||||
|
window.webkit.messageHandlers.error.postMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
export function Init() {
|
export function Init() {
|
||||||
|
|
||||||
// Setup drag handler
|
// Setup drag handler
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ module.exports = {
|
|||||||
mode: 'production',
|
mode: 'production',
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, '..', 'assets'),
|
path: path.resolve(__dirname, '..', 'assets'),
|
||||||
filename: 'desktop.js',
|
filename: 'desktop_'+platform+'.js',
|
||||||
library: 'Wails'
|
library: 'Wails'
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/wailsapp/wails/v2/internal/fs"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/shell"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/wailsapp/wails/v2/internal/fs"
|
||||||
|
"github.com/wailsapp/wails/v2/internal/shell"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -49,7 +50,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wailsJS := fs.RelativePath("../../../internal/runtime/assets/desktop.js")
|
wailsJS := fs.RelativePath("../../../internal/runtime/assets/desktop_" + platform + ".js")
|
||||||
runtimeData, err := ioutil.ReadFile(wailsJS)
|
runtimeData, err := ioutil.ReadFile(wailsJS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user