mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
Support Message dialog in JS runtime
This commit is contained in:
parent
2a93e2694d
commit
6253ac30b7
7 changed files with 140 additions and 91 deletions
|
|
@ -13,24 +13,24 @@ The lightweight framework for web-like apps
|
|||
import { SystemCall } from './calls';
|
||||
|
||||
/**
|
||||
* @type {Object} OpenDialog
|
||||
* @type {Object} OpenDialogOptions
|
||||
* @param {string} [DefaultDirectory=""]
|
||||
* @param {string} [DefaultFilename=""]
|
||||
* @param {string} [Title=""]
|
||||
* @param {string} [Filters=""]
|
||||
* @param {bool} [AllowFiles=false]
|
||||
* @param {bool} [AllowDirectories=false]
|
||||
* @param {bool} [AllowMultiple=false]
|
||||
* @param {bool} [ShowHiddenFiles=false]
|
||||
* @param {bool} [CanCreateDirectories=false]
|
||||
* @param {bool} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
|
||||
* @param {bool} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
|
||||
* @param {boolean} [AllowFiles=false]
|
||||
* @param {boolean} [AllowDirectories=false]
|
||||
* @param {boolean} [AllowMultiple=false]
|
||||
* @param {boolean} [ShowHiddenFiles=false]
|
||||
* @param {boolean} [CanCreateDirectories=false]
|
||||
* @param {boolean} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
|
||||
* @param {boolean} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* Opens a dialog using the given parameters, prompting the user to
|
||||
* select files/folders.
|
||||
*
|
||||
* @export
|
||||
|
|
@ -42,25 +42,50 @@ export function Open(options) {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Object} SaveDialogOptions
|
||||
* @param {string} [DefaultDirectory=""]
|
||||
* @param {string} [DefaultFilename=""]
|
||||
* @param {string} [Title=""]
|
||||
* @param {string} [Filters=""]
|
||||
* @param {bool} [ShowHiddenFiles=false]
|
||||
* @param {bool} [CanCreateDirectories=false]
|
||||
* @param {bool} [TreatPackagesAsDirectories=false]
|
||||
*
|
||||
* @type {Object} SaveDialogOptions
|
||||
* @param {string} [DefaultDirectory=""]
|
||||
* @param {string} [DefaultFilename=""]
|
||||
* @param {string} [Title=""]
|
||||
* @param {string} [Filters=""]
|
||||
* @param {boolean} [ShowHiddenFiles=false]
|
||||
* @param {boolean} [CanCreateDirectories=false]
|
||||
* @param {boolean} [TreatPackagesAsDirectories=false]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* Opens a dialog using the given parameters, prompting the user to
|
||||
* select a single file/folder.
|
||||
*
|
||||
*
|
||||
* @export
|
||||
* @param {SaveDialogOptions} options
|
||||
* @returns {Promise<string>}
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function Save(options) {
|
||||
return SystemCall('Dialog.Save', options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Object} MessageDialogOptions
|
||||
* @param {DialogType} [Type=InfoDialog] - The type of the dialog
|
||||
* @param {string} [Title=""] - The dialog title
|
||||
* @param {string} [Message=""] - The dialog message
|
||||
* @param {string[]} [Buttons=[]] - The button titles in the order they should appear
|
||||
* @param {string} [DefaultButton=""] - The button that should be used as the default button
|
||||
* @param {string} [CancelButton=""] - The button that should be used as the cancel button
|
||||
* @param {string} [Icon=""] - The name of the icon to use in the dialog
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given parameters, to display a message
|
||||
* or prompt the user to select an option
|
||||
*
|
||||
* @export
|
||||
* @param {MessageDialogOptions} options
|
||||
* @returns {Promise<string>} - The button text that was selected
|
||||
*/
|
||||
export function Message(options) {
|
||||
return SystemCall('Dialog.Message', options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ The lightweight framework for web-like apps
|
|||
* @param {string} [DefaultFilename=""]
|
||||
* @param {string} [Title=""]
|
||||
* @param {string} [Filters=""]
|
||||
* @param {bool} [AllowFiles=false]
|
||||
* @param {bool} [AllowDirectories=false]
|
||||
* @param {bool} [AllowMultiple=false]
|
||||
* @param {bool} [ShowHiddenFiles=false]
|
||||
* @param {bool} [CanCreateDirectories=false]
|
||||
* @param {bool} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
|
||||
* @param {bool} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
|
||||
* @param {boolean} [AllowFiles=false]
|
||||
* @param {boolean} [AllowDirectories=false]
|
||||
* @param {boolean} [AllowMultiple=false]
|
||||
* @param {boolean} [ShowHiddenFiles=false]
|
||||
* @param {boolean} [CanCreateDirectories=false]
|
||||
* @param {boolean} [ResolvesAliases=false] - Mac Only: Resolves aliases (symlinks)
|
||||
* @param {boolean} [TreatPackagesAsDirectories=false] - Mac Only: Show packages (EG Applications) as folders
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* Opens a dialog using the given parameters, prompting the user to
|
||||
* select files/folders.
|
||||
*
|
||||
* @export
|
||||
|
|
@ -44,13 +44,13 @@ export function Open(options) {
|
|||
* @param {string} [DefaultFilename=""]
|
||||
* @param {string} [Title=""]
|
||||
* @param {string} [Filters=""]
|
||||
* @param {bool} [ShowHiddenFiles=false]
|
||||
* @param {bool} [CanCreateDirectories=false]
|
||||
* @param {bool} [TreatPackagesAsDirectories=false]
|
||||
* @param {boolean} [ShowHiddenFiles=false]
|
||||
* @param {boolean} [CanCreateDirectories=false]
|
||||
* @param {boolean} [TreatPackagesAsDirectories=false]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* Opens a dialog using the given parameters, prompting the user to
|
||||
* select a single file/folder.
|
||||
*
|
||||
* @export
|
||||
|
|
@ -60,3 +60,27 @@ export function Open(options) {
|
|||
export function Save(options) {
|
||||
return window.wails.Dialog.Save(options);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Object} MessageDialogOptions
|
||||
* @param {DialogType} [Type=InfoDialog] - The type of the dialog
|
||||
* @param {string} [Title=""] - The dialog title
|
||||
* @param {string} [Message=""] - The dialog message
|
||||
* @param {string[]} [Buttons=[]] - The button titles in the order they should appear
|
||||
* @param {string} [DefaultButton=""] - The button that should be used as the default button
|
||||
* @param {string} [CancelButton=""] - The button that should be used as the cancel button
|
||||
* @param {string} [Icon=""] - The name of the icon to use in the dialog
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given parameters, to display a message
|
||||
* or prompt the user to select an option
|
||||
*
|
||||
* @export
|
||||
* @param {MessageDialogOptions} options
|
||||
* @returns {Promise<string>} - The button text that was selected
|
||||
*/
|
||||
export function Message(options) {
|
||||
return window.wails.Dialog.Message(options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@wails/runtime",
|
||||
"version": "1.2.20",
|
||||
"version": "1.2.22",
|
||||
"description": "Wails V2 Javascript runtime library",
|
||||
"main": "main.js",
|
||||
"types": "runtime.d.ts",
|
||||
|
|
|
|||
20
v2/internal/runtime/js/runtime/runtime.d.ts
vendored
20
v2/internal/runtime/js/runtime/runtime.d.ts
vendored
|
|
@ -77,6 +77,23 @@ interface SaveDialogOptions {
|
|||
TreatPackagesAsDirectories: boolean;
|
||||
}
|
||||
|
||||
interface DialogType {
|
||||
InfoDialog: 'info',
|
||||
WarningDialog: 'warning',
|
||||
ErrorDialog: 'error',
|
||||
QuestionDialog: 'question',
|
||||
}
|
||||
|
||||
interface MessageDialogOptions {
|
||||
Type: DialogType;
|
||||
Title: string;
|
||||
Message: string;
|
||||
Buttons: string[];
|
||||
DefaultButton: string;
|
||||
CancelButton: string;
|
||||
Icon: string;
|
||||
}
|
||||
|
||||
declare const wailsapp__runtime: {
|
||||
Browser: {
|
||||
Open(target: string): Promise<any>;
|
||||
|
|
@ -109,7 +126,8 @@ declare const wailsapp__runtime: {
|
|||
};
|
||||
Dialog: {
|
||||
Open(options: OpenDialogOptions): Promise<Array<string>>;
|
||||
Save(options: SaveDialogOptions): Promise<Array<string>>;
|
||||
Save(options: SaveDialogOptions): Promise<string>;
|
||||
Message(options: MessageDialogOptions): Promise<string>;
|
||||
};
|
||||
Tray: {
|
||||
SetIcon(trayIconID: string): void;
|
||||
|
|
|
|||
|
|
@ -146,6 +146,14 @@ func (c *Call) processSystemCall(payload *message.CallMessage, clientID string)
|
|||
}
|
||||
result := c.runtime.Dialog.Save(dialogOptions)
|
||||
c.sendResult(result, payload, clientID)
|
||||
case "Dialog.Message":
|
||||
dialogOptions := new(options.MessageDialog)
|
||||
err := json.Unmarshal(payload.Args[0], dialogOptions)
|
||||
if err != nil {
|
||||
c.logger.Error("Error decoding: %s", err)
|
||||
}
|
||||
result := c.runtime.Dialog.Message(dialogOptions)
|
||||
c.sendResult(result, payload, clientID)
|
||||
default:
|
||||
c.logger.Error("Unknown system call: %+v", callName)
|
||||
}
|
||||
|
|
@ -153,12 +161,12 @@ func (c *Call) processSystemCall(payload *message.CallMessage, clientID string)
|
|||
|
||||
func (c *Call) sendResult(result interface{}, payload *message.CallMessage, clientID string) {
|
||||
c.logger.Trace("Sending success result with CallbackID '%s' : %+v\n", payload.CallbackID, result)
|
||||
message := &CallbackMessage{
|
||||
incomingMessage := &CallbackMessage{
|
||||
Result: result,
|
||||
CallbackID: payload.CallbackID,
|
||||
}
|
||||
messageData, err := json.Marshal(message)
|
||||
c.logger.Trace("json message data: %+v\n", string(messageData))
|
||||
messageData, err := json.Marshal(incomingMessage)
|
||||
c.logger.Trace("json incomingMessage data: %+v\n", string(messageData))
|
||||
if err != nil {
|
||||
// what now?
|
||||
c.logger.Fatal(err.Error())
|
||||
|
|
@ -168,13 +176,13 @@ func (c *Call) sendResult(result interface{}, payload *message.CallMessage, clie
|
|||
|
||||
func (c *Call) sendError(err error, payload *message.CallMessage, clientID string) {
|
||||
c.logger.Trace("Sending error result with CallbackID '%s' : %+v\n", payload.CallbackID, err.Error())
|
||||
message := &CallbackMessage{
|
||||
incomingMessage := &CallbackMessage{
|
||||
Err: err.Error(),
|
||||
CallbackID: payload.CallbackID,
|
||||
}
|
||||
|
||||
messageData, err := json.Marshal(message)
|
||||
c.logger.Trace("json message data: %+v\n", string(messageData))
|
||||
messageData, err := json.Marshal(incomingMessage)
|
||||
c.logger.Trace("json incomingMessage data: %+v\n", string(messageData))
|
||||
if err != nil {
|
||||
// what now?
|
||||
c.logger.Fatal(err.Error())
|
||||
|
|
|
|||
64
v2/test/kitchensink/frontend/package-lock.json
generated
64
v2/test/kitchensink/frontend/package-lock.json
generated
|
|
@ -135,9 +135,9 @@
|
|||
}
|
||||
},
|
||||
"@wails/runtime": {
|
||||
"version": "1.2.20",
|
||||
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.2.20.tgz",
|
||||
"integrity": "sha512-UsKFbU+q6p9pW8cddVtUxwtJT/mULtyJCti2kE2wT8kaqfo2fjQueVYHWj0BbRlHgXfkCPcJ2mAPFjqQjvET3g==",
|
||||
"version": "1.2.22",
|
||||
"resolved": "https://registry.npmjs.org/@wails/runtime/-/runtime-1.2.22.tgz",
|
||||
"integrity": "sha512-DI/7gohiqDdMZkmpJg24cwPVH9/n5CoAN11qSuI4FEf5vALVQZ2+KQXiTXIV20jQ2ozl/LTO4qMYI+sij3TA1g==",
|
||||
"dev": true
|
||||
},
|
||||
"alphanum-sort": {
|
||||
|
|
@ -1261,21 +1261,6 @@
|
|||
"has-symbols": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
|
||||
"dev": true
|
||||
},
|
||||
"isobject": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz",
|
||||
"integrity": "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"isarray": "1.0.0"
|
||||
}
|
||||
},
|
||||
"jest-worker": {
|
||||
"version": "24.9.0",
|
||||
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-24.9.0.tgz",
|
||||
|
|
@ -1334,16 +1319,6 @@
|
|||
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==",
|
||||
"dev": true
|
||||
},
|
||||
"line-column": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/line-column/-/line-column-1.0.2.tgz",
|
||||
"integrity": "sha1-0lryk2tvSEkXKzEuR5LR2Ye8NKI=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"isarray": "^1.0.0",
|
||||
"isobject": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"livereload": {
|
||||
"version": "0.9.1",
|
||||
"resolved": "https://registry.npmjs.org/livereload/-/livereload-0.9.1.tgz",
|
||||
|
|
@ -1470,9 +1445,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"nanoid": {
|
||||
"version": "3.1.16",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.16.tgz",
|
||||
"integrity": "sha512-+AK8MN0WHji40lj8AEuwLOvLSbWYApQpre/aFJZD71r43wVRLrOYS4FmJOPQYon1TqB462RzrrxlfA74XRES8w==",
|
||||
"version": "3.1.20",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz",
|
||||
"integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==",
|
||||
"dev": true
|
||||
},
|
||||
"neo-async": {
|
||||
|
|
@ -1651,14 +1626,13 @@
|
|||
"dev": true
|
||||
},
|
||||
"postcss": {
|
||||
"version": "8.1.7",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.1.7.tgz",
|
||||
"integrity": "sha512-llCQW1Pz4MOPwbZLmOddGM9eIJ8Bh7SZ2Oj5sxZva77uVaotYDsYTch1WBTNu7fUY0fpWp0fdt7uW40D4sRiiQ==",
|
||||
"version": "8.2.2",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.2.2.tgz",
|
||||
"integrity": "sha512-HM1NDNWLgglJPQQMNwvLxgH2KcrKZklKLi/xXYIOaqQB57p/pDWEJNS83PVICYsn1Dg/9C26TiejNr422/ePaQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"colorette": "^1.2.1",
|
||||
"line-column": "^1.0.2",
|
||||
"nanoid": "^3.1.16",
|
||||
"nanoid": "^3.1.20",
|
||||
"source-map": "^0.6.1"
|
||||
}
|
||||
},
|
||||
|
|
@ -2976,9 +2950,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"rollup": {
|
||||
"version": "2.33.3",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.33.3.tgz",
|
||||
"integrity": "sha512-RpayhPTe4Gu/uFGCmk7Gp5Z9Qic2VsqZ040G+KZZvsZYdcuWaJg678JeDJJvJeEQXminu24a2au+y92CUWVd+w==",
|
||||
"version": "2.35.1",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.35.1.tgz",
|
||||
"integrity": "sha512-q5KxEyWpprAIcainhVy6HfRttD9kutQpHbeqDTWnqAFNJotiojetK6uqmcydNMymBEtC4I8bCYR+J3mTMqeaUA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fsevents": "~2.1.2"
|
||||
|
|
@ -3413,9 +3387,9 @@
|
|||
}
|
||||
},
|
||||
"svelte": {
|
||||
"version": "3.29.7",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.29.7.tgz",
|
||||
"integrity": "sha512-rx0g311kBODvEWUU01DFBUl3MJuJven04bvTVFUG/w0On/wuj0PajQY/QlXcJndFxG+W1s8iXKaB418tdHWc3A==",
|
||||
"version": "3.31.0",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.31.0.tgz",
|
||||
"integrity": "sha512-r+n8UJkDqoQm1b+3tA3Lh6mHXKpcfOSOuEuIo5gE2W9wQYi64RYX/qE6CZBDDsP/H4M+N426JwY7XGH4xASvGQ==",
|
||||
"dev": true
|
||||
},
|
||||
"svelte-highlight": {
|
||||
|
|
@ -3429,9 +3403,9 @@
|
|||
}
|
||||
},
|
||||
"svelte-preprocess": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-4.6.0.tgz",
|
||||
"integrity": "sha512-kJwcU71+yw3KKMgGu9eHZMJVBSkW4VfGJ5LSMgFQP/XcwvY2QUV6JcyBoQTjJm+h1KRlo/WGDo6A7+7e+B8B4A==",
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-4.6.1.tgz",
|
||||
"integrity": "sha512-s7KdhR2pOsffyOzZIMEb315f6pfgeDnOWN47m6YKFeSEx3NMf/79Znc3vuG/Ai79SL/vsi86WDrjFPLGRfDesg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/pug": "^2.0.4",
|
||||
|
|
|
|||
|
|
@ -11,21 +11,21 @@
|
|||
"@rollup/plugin-commonjs": "^11.0.0",
|
||||
"@rollup/plugin-node-resolve": "^7.0.0",
|
||||
"@rollup/plugin-url": "^5.0.1",
|
||||
"@wails/runtime": "^1.2.20",
|
||||
"@wails/runtime": "^1.2.22",
|
||||
"focus-visible": "^5.2.0",
|
||||
"halfmoon": "^1.1.1",
|
||||
"postcss": "^8.1.7",
|
||||
"postcss": "^8.2.2",
|
||||
"postcss-import": "^12.0.1",
|
||||
"rollup": "^2.33.3",
|
||||
"rollup": "^2.35.1",
|
||||
"rollup-plugin-livereload": "^1.0.0",
|
||||
"rollup-plugin-postcss": "^3.1.8",
|
||||
"rollup-plugin-string": "^3.0.0",
|
||||
"rollup-plugin-svelte": "^5.0.3",
|
||||
"rollup-plugin-terser": "^5.1.2",
|
||||
"sirv-cli": "^0.4.4",
|
||||
"svelte": "^3.29.7",
|
||||
"svelte": "^3.31.0",
|
||||
"svelte-highlight": "^0.6.2",
|
||||
"svelte-preprocess": "^4.6.0"
|
||||
"svelte-preprocess": "^4.6.1"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue