mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
[windows] Support wails dev
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -195,8 +195,8 @@ void execJS(struct Application* app, const char *script) {
|
||||
|
||||
void loadAssets(struct Application* app) {
|
||||
|
||||
// patch window.external.invoke
|
||||
std::string initialCode = std::string("window.external={invoke:s=>window.chrome.webview.postMessage(s)};");
|
||||
// setup window.wailsInvoke
|
||||
std::string initialCode = std::string("window.wailsInvoke=function(m){window.chrome.webview.postMessage(m)};");
|
||||
|
||||
// Load bindings
|
||||
initialCode += std::string(app->bindings);
|
||||
@@ -224,7 +224,7 @@ void loadAssets(struct Application* app) {
|
||||
initialCode += std::string("wails._.DisableDefaultContextMenu();");
|
||||
}
|
||||
|
||||
initialCode += std::string("window.external.invoke('completed');");
|
||||
initialCode += std::string("window.wailsInvoke('completed');");
|
||||
|
||||
// Keep a copy of the code
|
||||
app->initialCode = new char[initialCode.length()+1];
|
||||
@@ -304,8 +304,8 @@ bool initWebView2(struct Application *app, int debugEnabled, messageCallback cb)
|
||||
GetClientRect(app->window, &bounds);
|
||||
app->webviewController->put_Bounds(bounds);
|
||||
|
||||
// Callback hack
|
||||
app->webview->AddScriptToExecuteOnDocumentCreated(L"window.chrome.webview.postMessage('I');", nullptr);
|
||||
// Let the backend know we have initialised
|
||||
app->webview->AddScriptToExecuteOnDocumentCreated(L"window.chrome.webview.postMessage('initialised');", nullptr);
|
||||
// Load the HTML
|
||||
LPCWSTR html = (LPCWSTR) cstrToLPWSTR((char*)assets[0]);
|
||||
app->webview->Navigate(html);
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -66,21 +66,12 @@ class wv2ComHandler
|
||||
completed(app);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
switch(m[0]) {
|
||||
|
||||
// Standard message for backend
|
||||
case 'S':
|
||||
printf("--> Message to backend: %s\n", &m[1]);
|
||||
messageFromWindowCallback(&m[1]);
|
||||
break;
|
||||
// DOM Initialised
|
||||
case 'I':
|
||||
else if (strcmp(m, "initialised") == 0) {
|
||||
loadAssets(app);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("----> Unknown message type: %c\n", m[0]);
|
||||
return S_OK;
|
||||
}
|
||||
else {
|
||||
messageFromWindowCallback(m);
|
||||
}
|
||||
delete[] m;
|
||||
return S_OK;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -10,20 +10,6 @@ The lightweight framework for web-like apps
|
||||
/* jshint esversion: 6 */
|
||||
import { SetBindings } from './bindings';
|
||||
import { Init } from './main';
|
||||
import {RaiseError} from '../desktop/darwin';
|
||||
|
||||
// Setup global error handler
|
||||
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||
const errorMessage = {
|
||||
message: msg,
|
||||
url: url,
|
||||
line: lineNo,
|
||||
column: columnNo,
|
||||
error: JSON.stringify(error),
|
||||
stack: function() { return JSON.stringify(new Error().stack); }(),
|
||||
};
|
||||
RaiseError(errorMessage);
|
||||
};
|
||||
|
||||
// Initialise the Runtime
|
||||
Init();
|
||||
|
||||
@@ -25,10 +25,6 @@ export function SendMessage(message) {
|
||||
window.webkit.messageHandlers.external.postMessage(message);
|
||||
}
|
||||
|
||||
export function RaiseError(message) {
|
||||
window.webkit.messageHandlers.error.postMessage(message);
|
||||
}
|
||||
|
||||
export function Init() {
|
||||
|
||||
// Setup drag handler
|
||||
|
||||
@@ -22,11 +22,7 @@ export const System = {
|
||||
};
|
||||
|
||||
export function SendMessage(message) {
|
||||
window.chrome.webview.postMessage('S'+message);
|
||||
}
|
||||
|
||||
export function RaiseError(message) {
|
||||
window.chrome.webview.postMessage('E'+message);
|
||||
window.wailsInvoke(message);
|
||||
}
|
||||
|
||||
export function Init() {
|
||||
@@ -39,7 +35,7 @@ export function Init() {
|
||||
if (currentElement.hasAttribute('data-wails-no-drag')) {
|
||||
break;
|
||||
} else if (currentElement.hasAttribute('data-wails-drag')) {
|
||||
window.chrome.webview.postMessage('wails-drag');
|
||||
window.wailsInvoke('wails-drag');
|
||||
break;
|
||||
}
|
||||
currentElement = currentElement.parentElement;
|
||||
@@ -66,7 +62,7 @@ export function Init() {
|
||||
id: contextMenuId,
|
||||
data: contextData || '',
|
||||
};
|
||||
window.chrome.webview.postMessage('C'+JSON.stringify(message));
|
||||
window.wailsInvoke('C'+JSON.stringify(message));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1559,20 +1559,8 @@
|
||||
}
|
||||
|
||||
function setupIPCBridge() {
|
||||
// darwin
|
||||
window.webkit = {
|
||||
messageHandlers: {
|
||||
external: {
|
||||
postMessage: (message) => {
|
||||
websocket.send(message);
|
||||
}
|
||||
},
|
||||
windowDrag: {
|
||||
postMessage: () => {
|
||||
// Ignore window drag events
|
||||
}
|
||||
}
|
||||
}
|
||||
window.wailsInvoke = (message) => {
|
||||
websocket.send(message);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1636,7 +1624,7 @@
|
||||
|
||||
// We need to now send a message to the backend telling it
|
||||
// we have loaded (System Start)
|
||||
window.wails._.SendMessage('SS');
|
||||
window.wailsInvoke('SS');
|
||||
|
||||
// Now wails runtime is loaded, wails for the ready event
|
||||
// and callback to the main app
|
||||
|
||||
2
v2/internal/runtime/js/runtime/package-lock.json
generated
2
v2/internal/runtime/js/runtime/package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wails/runtime",
|
||||
"version": "1.2.24",
|
||||
"version": "1.3.15",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wails/runtime",
|
||||
"version": "1.3.15",
|
||||
"version": "1.3.18",
|
||||
"description": "Wails V2 Javascript runtime library",
|
||||
"main": "main.js",
|
||||
"types": "runtime.d.ts",
|
||||
|
||||
@@ -35,20 +35,8 @@ export function StartWebsocket(userCallback) {
|
||||
}
|
||||
|
||||
function setupIPCBridge() {
|
||||
// darwin
|
||||
window.webkit = {
|
||||
messageHandlers: {
|
||||
external: {
|
||||
postMessage: (message) => {
|
||||
websocket.send(message);
|
||||
}
|
||||
},
|
||||
windowDrag: {
|
||||
postMessage: () => {
|
||||
// Ignore window drag events
|
||||
}
|
||||
}
|
||||
}
|
||||
window.wailsInvoke = (message) => {
|
||||
websocket.send(message);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -112,7 +100,7 @@ function handleMessage(message) {
|
||||
|
||||
// We need to now send a message to the backend telling it
|
||||
// we have loaded (System Start)
|
||||
window.wails._.SendMessage('SS');
|
||||
window.wailsInvoke('SS');
|
||||
|
||||
// Now wails runtime is loaded, wails for the ready event
|
||||
// and callback to the main app
|
||||
|
||||
Reference in New Issue
Block a user