-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Radical JS runtime overhaul. New @wailsio/runtime package
- Loading branch information
1 parent
d1255d3
commit b08126d
Showing
61 changed files
with
1,809 additions
and
4,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Runtime | ||
|
||
To rebuild the runtime run `task build-runtime` or if you have Wails v3 CLI, you can use `wails task build-runtime`. | ||
To rebuild the runtime run `task build-runtime` or if you have Wails v3 CLI, you can use `wails3 task build-runtime`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
v3/internal/runtime/desktop/@wailsio/runtime/application.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
_ __ _ __ | ||
| | / /___ _(_) /____ | ||
| | /| / / __ `/ / / ___/ | ||
| |/ |/ / /_/ / / (__ ) | ||
|__/|__/\__,_/_/_/____/ | ||
The electron alternative for Go | ||
(c) Lea Anthony 2019-present | ||
*/ | ||
|
||
/* jshint esversion: 9 */ | ||
|
||
import { newRuntimeCallerWithID, objectNames } from "./runtime"; | ||
const call = newRuntimeCallerWithID(objectNames.Application); | ||
|
||
const HideMethod = 0; | ||
const ShowMethod = 1; | ||
const QuitMethod = 2; | ||
|
||
/** | ||
* Hides a certain method by calling the HideMethod function. | ||
* | ||
* @return {Promise<void>} | ||
* | ||
*/ | ||
export function Hide() { | ||
return call(HideMethod); | ||
} | ||
|
||
/** | ||
* Calls the ShowMethod and returns the result. | ||
* | ||
* @return {Promise<void>} | ||
*/ | ||
export function Show() { | ||
return call(ShowMethod); | ||
} | ||
|
||
/** | ||
* Calls the QuitMethod to terminate the program. | ||
* | ||
* @return {Promise<void>} | ||
*/ | ||
export function Quit() { | ||
return call(QuitMethod); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
_ __ _ __ | ||
| | / /___ _(_) /____ | ||
| | /| / / __ `/ / / ___/ | ||
| |/ |/ / /_/ / / (__ ) | ||
|__/|__/\__,_/_/_/____/ | ||
The electron alternative for Go | ||
(c) Lea Anthony 2019-present | ||
*/ | ||
|
||
/* jshint esversion: 9 */ | ||
import { newRuntimeCallerWithID, objectNames } from "./runtime"; | ||
import { nanoid } from 'nanoid/non-secure'; | ||
|
||
const CallBinding = 0; | ||
const call = newRuntimeCallerWithID(objectNames.Call, ''); | ||
let callResponses = new Map(); | ||
|
||
window._wails = window._wails || {}; | ||
window._wails.callCallback = resultHandler; | ||
window._wails.callErrorCallback = errorHandler; | ||
|
||
function generateID() { | ||
let result; | ||
do { | ||
result = nanoid(); | ||
} while (callResponses.has(result)); | ||
return result; | ||
} | ||
|
||
export function resultHandler(id, data, isJSON) { | ||
const promiseHandler = getAndDeleteResponse(id); | ||
if (promiseHandler) { | ||
promiseHandler.resolve(isJSON ? JSON.parse(data) : data); | ||
} | ||
} | ||
|
||
export function errorHandler(id, message) { | ||
const promiseHandler = getAndDeleteResponse(id); | ||
if (promiseHandler) { | ||
promiseHandler.reject(message); | ||
} | ||
} | ||
|
||
function getAndDeleteResponse(id) { | ||
const response = callResponses.get(id); | ||
callResponses.delete(id); | ||
return response; | ||
} | ||
|
||
function callBinding(type, options = {}) { | ||
return new Promise((resolve, reject) => { | ||
const id = generateID(); | ||
options["call-id"] = id; | ||
callResponses.set(id, { resolve, reject }); | ||
call(type, options).catch((error) => { | ||
reject(error); | ||
callResponses.delete(id); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Call method. | ||
* | ||
* @param {Object} options - The options for the method. | ||
* @returns {Object} - The result of the call. | ||
*/ | ||
export function Call(options) { | ||
return callBinding(CallBinding, options); | ||
} | ||
|
||
/** | ||
* Executes a method by name. | ||
* | ||
* @param {string} name - The name of the method in the format 'package.struct.method'. | ||
* @param {...*} args - The arguments to pass to the method. | ||
* @throws {Error} If the name is not a string or is not in the correct format. | ||
* @returns {*} The result of the method execution. | ||
*/ | ||
export function ByName(name, ...args) { | ||
if (typeof name !== "string" || name.split(".").length !== 3) { | ||
throw new Error("CallByName requires a string in the format 'package.struct.method'"); | ||
} | ||
let [packageName, structName, methodName] = name.split("."); | ||
return callBinding(CallBinding, { | ||
packageName, | ||
structName, | ||
methodName, | ||
args | ||
}); | ||
} | ||
|
||
/** | ||
* Calls a method by its ID with the specified arguments. | ||
* | ||
* @param {string} methodID - The ID of the method to call. | ||
* @param {...*} args - The arguments to pass to the method. | ||
* @return {*} - The result of the method call. | ||
*/ | ||
export function ByID(methodID, ...args) { | ||
return callBinding(CallBinding, { | ||
methodID, | ||
args | ||
}); | ||
} | ||
|
||
/** | ||
* Calls a method on a plugin. | ||
* | ||
* @param {string} pluginName - The name of the plugin. | ||
* @param {string} methodName - The name of the method to call. | ||
* @param {...*} args - The arguments to pass to the method. | ||
* @returns {*} - The result of the method call. | ||
*/ | ||
export function Plugin(pluginName, methodName, ...args) { | ||
return callBinding(CallBinding, { | ||
packageName: "wails-plugins", | ||
structName: pluginName, | ||
methodName, | ||
args | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
_ __ _ __ | ||
| | / /___ _(_) /____ | ||
| | /| / / __ `/ / / ___/ | ||
| |/ |/ / /_/ / / (__ ) | ||
|__/|__/\__,_/_/_/____/ | ||
The electron alternative for Go | ||
(c) Lea Anthony 2019-present | ||
*/ | ||
|
||
/* jshint esversion: 9 */ | ||
|
||
import {newRuntimeCallerWithID, objectNames} from "./runtime"; | ||
|
||
const call = newRuntimeCallerWithID(objectNames.Clipboard, ''); | ||
const ClipboardSetText = 0; | ||
const ClipboardText = 1; | ||
|
||
/** | ||
* Sets the text to the Clipboard. | ||
* | ||
* @param {string} text - The text to be set to the Clipboard. | ||
* @return {Promise} - A Promise that resolves when the operation is successful. | ||
*/ | ||
export function SetText(text) { | ||
return call(ClipboardSetText, {text}); | ||
} | ||
|
||
/** | ||
* Get the Clipboard text | ||
* @returns {Promise<string>} A promise that resolves with the text from the Clipboard. | ||
*/ | ||
export function Text() { | ||
return call(ClipboardText); | ||
} |
17 changes: 14 additions & 3 deletions
17
v3/internal/runtime/desktop/contextmenu.js → ...e/desktop/@wailsio/runtime/contextmenu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.