mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Support Dialog in runtime
This commit is contained in:
@@ -10,14 +10,57 @@ The lightweight framework for web-like apps
|
||||
|
||||
/* jshint esversion: 6 */
|
||||
|
||||
import { SendMessage } from 'ipc';
|
||||
import { SystemCall } from './calls';
|
||||
|
||||
/**
|
||||
* Open a dialog with the given parameters
|
||||
* @type {Object} OpenDialog
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* select files/folders.
|
||||
*
|
||||
* @export
|
||||
* @param {object} options
|
||||
* @param {OpenDialogOptions} options
|
||||
* @returns {Promise<Array<string>>} - List of files/folders selected
|
||||
*/
|
||||
export function Open(options) {
|
||||
SendMessage('DO'+JSON.stringify(options));
|
||||
return SystemCall('Dialog.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]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* select a single file/folder.
|
||||
*
|
||||
* @export
|
||||
* @param {SaveDialogOptions} options
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function Save(options) {
|
||||
return SystemCall('Dialog.Save', options);
|
||||
}
|
||||
|
||||
@@ -10,13 +10,53 @@ The lightweight framework for web-like apps
|
||||
|
||||
/* jshint esversion: 6 */
|
||||
|
||||
/**
|
||||
* @type {Object} OpenDialog
|
||||
* @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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Open a dialog with the given parameters
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* select files/folders.
|
||||
*
|
||||
* @export
|
||||
* @param {object} options
|
||||
* @param {OpenDialogOptions} options
|
||||
* @returns {Promise<Array<string>>} - List of files/folders selected
|
||||
*/
|
||||
export function Open(options) {
|
||||
window.wails.Dialog.Open(options);
|
||||
return window.wails.Dialog.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]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens a dialog using the given paramaters, prompting the user to
|
||||
* select a single file/folder.
|
||||
*
|
||||
* @export
|
||||
* @param {SaveDialogOptions} options
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function Save(options) {
|
||||
return window.wails.Dialog.Save(options);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wails/runtime",
|
||||
"version": "1.2.11",
|
||||
"version": "1.2.12",
|
||||
"description": "Wails V2 Javascript runtime library",
|
||||
"main": "main.js",
|
||||
"types": "runtime.d.ts",
|
||||
|
||||
30
v2/internal/runtime/js/runtime/runtime.d.ts
vendored
30
v2/internal/runtime/js/runtime/runtime.d.ts
vendored
@@ -53,6 +53,30 @@ interface Level {
|
||||
ERROR: 5,
|
||||
}
|
||||
|
||||
interface OpenDialogOptions {
|
||||
DefaultDirectory: string;
|
||||
DefaultFilename: string;
|
||||
Title: string;
|
||||
Filters: string;
|
||||
AllowFiles: boolean;
|
||||
AllowDirectories: boolean;
|
||||
AllowMultiple: boolean;
|
||||
ShowHiddenFiles: boolean;
|
||||
CanCreateDirectories: boolean;
|
||||
ResolvesAliases: boolean;
|
||||
TreatPackagesAsDirectories: boolean;
|
||||
}
|
||||
|
||||
interface SaveDialogOptions {
|
||||
DefaultDirectory: string;
|
||||
DefaultFilename: string;
|
||||
Title: string;
|
||||
Filters: string;
|
||||
ShowHiddenFiles: boolean;
|
||||
CanCreateDirectories: boolean;
|
||||
TreatPackagesAsDirectories: boolean;
|
||||
}
|
||||
|
||||
declare const wailsapp__runtime: {
|
||||
Browser: {
|
||||
Open(target: string): Promise<any>;
|
||||
@@ -82,7 +106,11 @@ declare const wailsapp__runtime: {
|
||||
};
|
||||
Store: {
|
||||
New(name: string, defaultValue?: any): Store;
|
||||
}
|
||||
};
|
||||
Dialog: {
|
||||
Open(options: OpenDialogOptions): Promise<Array<string>>;
|
||||
Save(options: SaveDialogOptions): Promise<Array<string>>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
||||
"github.com/wailsapp/wails/v2/internal/runtime"
|
||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
)
|
||||
|
||||
// Call is the Call subsystem. It manages all service bus messages
|
||||
@@ -129,6 +130,24 @@ func (c *Call) processSystemCall(payload *message.CallMessage, clientID string)
|
||||
case "IsDarkMode":
|
||||
darkModeEnabled := c.runtime.System.IsDarkMode()
|
||||
c.sendResult(darkModeEnabled, payload, clientID)
|
||||
case "Dialog.Open":
|
||||
dialogOptions := new(options.OpenDialog)
|
||||
err := json.Unmarshal(payload.Args[0], dialogOptions)
|
||||
if err != nil {
|
||||
c.logger.Error("Error decoding: %s", err)
|
||||
}
|
||||
result := c.runtime.Dialog.Open(dialogOptions)
|
||||
c.sendResult(result, payload, clientID)
|
||||
case "Dialog.Save":
|
||||
dialogOptions := new(options.SaveDialog)
|
||||
err := json.Unmarshal(payload.Args[0], dialogOptions)
|
||||
if err != nil {
|
||||
c.logger.Error("Error decoding: %s", err)
|
||||
}
|
||||
result := c.runtime.Dialog.Save(dialogOptions)
|
||||
c.sendResult(result, payload, clientID)
|
||||
default:
|
||||
c.logger.Error("Unknown system call: %+v", callName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ type OpenDialog struct {
|
||||
AllowMultiple bool
|
||||
ShowHiddenFiles bool
|
||||
CanCreateDirectories bool
|
||||
ResolveAliases bool
|
||||
ResolvesAliases bool
|
||||
TreatPackagesAsDirectories bool
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
wails "github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
)
|
||||
@@ -21,7 +19,10 @@ func (l *Dialog) WailsInit(runtime *wails.Runtime) error {
|
||||
|
||||
// Open Dialog
|
||||
func (l *Dialog) Open(options *options.OpenDialog) []string {
|
||||
fmt.Printf("%#v\n", options)
|
||||
// Perform your setup here
|
||||
return l.runtime.Dialog.Open(options)
|
||||
}
|
||||
|
||||
// Save Dialog
|
||||
func (l *Dialog) Save(options *options.SaveDialog) string {
|
||||
return l.runtime.Dialog.Save(options)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user