[windows-x] Refactor runtime & asset server

This commit is contained in:
Lea Anthony
2021-08-18 22:12:00 +10:00
parent ec8d8e4587
commit 6923ea301b
16 changed files with 431 additions and 182 deletions

View File

@@ -9,8 +9,6 @@ The lightweight framework for web-like apps
*/
/* jshint esversion: 6 */
import {SendMessage} from './ipc';
var callbacks = {};
/**
@@ -95,7 +93,7 @@ export function Call(name, args, timeout) {
};
// Make the call
SendMessage('C' + JSON.stringify(payload));
window.WailsInvoke('C' + JSON.stringify(payload));
} catch (e) {
// eslint-disable-next-line
console.error(e);

View File

@@ -9,8 +9,6 @@ The lightweight framework for web-like apps
*/
/* jshint esversion: 6 */
import {SendMessage} from './ipc';
// Defines a single listener with a maximum number of times to callback
/**
@@ -152,7 +150,7 @@ export function EventsEmit(eventName) {
notifyListeners(payload);
// Notify Go listeners
SendMessage('EE' + JSON.stringify(payload));
window.WailsInvoke('EE' + JSON.stringify(payload));
}
export function EventsOff(eventName) {
@@ -160,5 +158,5 @@ export function EventsOff(eventName) {
eventListeners.delete(eventName);
// Notify Go listeners
SendMessage('EX' + eventName);
window.WailsInvoke('EX' + eventName);
}

View File

@@ -9,23 +9,12 @@ The lightweight framework for web-like apps
*/
/* jshint esversion: 6 */
// IPC Listeners
const listeners = [];
/**
* Adds a listener to IPC messages
* @param {function} callback
*/
export function AddIPCListener(callback) {
listeners.push(callback);
}
/**
* SendMessage sends the given message to the backend
*
* @param {string} message
*/
export function SendMessage(message) {
window.WailsInvoke = function (message) {
// Call Platform specific invoke method
if (PLATFORM === "windows") {
@@ -35,11 +24,4 @@ export function SendMessage(message) {
} else {
console.error("Unsupported Platform");
}
// Also send to listeners
if (listeners.length > 0) {
for (let i = 0; i < listeners.length; i++) {
listeners[i](message);
}
}
}
};

View File

@@ -10,8 +10,6 @@ The lightweight framework for web-like apps
/* jshint esversion: 6 */
import {SendMessage} from './ipc';
/**
* Sends a log message to the backend with the given level + message
*
@@ -22,7 +20,7 @@ function sendLogMessage(level, message) {
// Log Message format:
// l[type][message]
SendMessage('L' + level + message);
window.WailsInvoke('L' + level + message);
}
/**

View File

@@ -12,8 +12,6 @@ import * as Log from './log';
import {EventsEmit, EventsNotify, EventsOff, EventsOn, EventsOnce, EventsOnMultiple} from './events';
import {Callback} from './calls';
import {SetBindings} from "./bindings";
// import {AddScript, DisableDefaultContextMenu, InjectCSS} from './utils';
import {SendMessage} from './ipc';
// Backend is where the Go struct wrappers get bound to
window.backend = {};
@@ -35,8 +33,8 @@ window.wails = {
};
window.wails.SetBindings(window.wailsbindings);
delete window.wails['SetBindings'];
delete window['wailsbindings'];
delete window.wails.SetBindings;
delete window.wailsbindings;
// Setup drag handler
// Based on code from: https://github.com/patr0nus/DeskGap
@@ -46,7 +44,7 @@ window.addEventListener('mousedown', (e) => {
if (currentElement.hasAttribute('data-wails-no-drag')) {
break;
} else if (currentElement.hasAttribute('data-wails-drag')) {
SendMessage("drag");
window.WailsInvoke("drag");
break;
}
currentElement = currentElement.parentElement;

View File

@@ -0,0 +1,8 @@
//go:build dev
package runtime
import _ "embed"
//go:embed ipc_dev.js
var IPCJS []byte

View File

@@ -0,0 +1,8 @@
//go:build desktop && windows
package runtime
import _ "embed"
//go:embed ipc_windows.js
var IPCJS []byte

View File

@@ -5,8 +5,10 @@
"main": "index.js",
"scripts": {
"build": "run-p build:*",
"build:windows": "esbuild desktop/main.js --bundle --minify --outfile=runtime_production_windows.js --define:PLATFORM='windows'",
"build:windows-dev": "esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_debug_windows.js --define:PLATFORM='windows'",
"build:ipc-windows": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_windows.js --define:PLATFORM='windows'",
"build:ipc-dev": "esbuild desktop/ipc.js --bundle --minify --outfile=ipc_dev.js",
"build:runtime-desktop-prod": "esbuild desktop/main.js --bundle --minify --outfile=runtime_prod_desktop.js",
"build:runtime-desktop-debug": "esbuild desktop/main.js --bundle --sourcemap=inline --outfile=runtime_debug_desktop.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Lea Anthony <lea.anthony@gmail.com>",

View File

@@ -0,0 +1,8 @@
//go:build debug && desktop
package runtime
import _ "embed"
//go:embed runtime_debug_desktop.js
var RuntimeJS []byte

View File

@@ -1,9 +0,0 @@
//+build debug
//+build windows
package runtime
import _ "embed"
//go:embed runtime_debug_windows.js
var RuntimeJS string

View File

@@ -0,0 +1,8 @@
//go:build production && desktop
package runtime
import _ "embed"
//go:embed runtime_prod_desktop.js
var RuntimeJS []byte

View File

@@ -1,9 +0,0 @@
//+build !debug
//+build windows
package runtime
import _ "embed"
//go:embed runtime_production_windows.js
var RuntimeJS string