mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +08:00
[windows-x] Experimental -> Default
This commit is contained in:
parent
de255729e6
commit
b7cd36921e
@ -113,10 +113,10 @@ func Build(options *Options) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the base assets
|
// Build the base assets
|
||||||
err = builder.BuildAssets(options)
|
//err = builder.BuildAssets(options)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
return "", err
|
// return "", err
|
||||||
}
|
//}
|
||||||
|
|
||||||
// If we are building for windows, we will need to generate the asset bundle before
|
// If we are building for windows, we will need to generate the asset bundle before
|
||||||
// compilation. This will be a .syso file in the project root
|
// compilation. This will be a .syso file in the project root
|
||||||
|
@ -2,7 +2,6 @@ package build
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/leaanthony/slicer"
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/buildassets"
|
"github.com/wailsapp/wails/v2/pkg/buildassets"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -24,7 +23,6 @@ func newDesktopBuilder(options *Options) *DesktopBuilder {
|
|||||||
|
|
||||||
// BuildAssets builds the assets for the desktop application
|
// BuildAssets builds the assets for the desktop application
|
||||||
func (d *DesktopBuilder) BuildAssets(options *Options) error {
|
func (d *DesktopBuilder) BuildAssets(options *Options) error {
|
||||||
var err error
|
|
||||||
|
|
||||||
// Check assets directory exists
|
// Check assets directory exists
|
||||||
if !fs.DirExists(options.ProjectData.BuildDir) {
|
if !fs.DirExists(options.ProjectData.BuildDir) {
|
||||||
@ -36,22 +34,20 @@ func (d *DesktopBuilder) BuildAssets(options *Options) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We only build assets for cgo builds
|
// We only build assets for cgo builds
|
||||||
userTags := slicer.String(options.UserTags)
|
//userTags := slicer.String(options.UserTags)
|
||||||
if userTags.Contains("experimental") {
|
//if userTags.Contains("cgo") {
|
||||||
return nil
|
// // Get a list of assets from the HTML
|
||||||
}
|
// assets, err := d.BaseBuilder.ExtractAssets()
|
||||||
|
// if err != nil {
|
||||||
// Get a list of assets from the HTML
|
// return err
|
||||||
assets, err := d.BaseBuilder.ExtractAssets()
|
// }
|
||||||
if err != nil {
|
//
|
||||||
return err
|
// // Build base assets (HTML/JS/CSS/etc)
|
||||||
}
|
// err = d.BuildBaseAssets(assets, options)
|
||||||
|
// if err != nil {
|
||||||
// Build base assets (HTML/JS/CSS/etc)
|
// return err
|
||||||
err = d.BuildBaseAssets(assets, options)
|
// }
|
||||||
if err != nil {
|
//}
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,16 @@
|
|||||||
|
|
||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/leaanthony/slicer"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/ffenestri/windows/x64"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PostCompilation is called after the compilation step, if successful
|
// PostCompilation is called after the compilation step, if successful
|
||||||
func (d *DesktopBuilder) PostCompilation(options *Options) error {
|
func (d *DesktopBuilder) PostCompilation(options *Options) error {
|
||||||
// Dump the DLLs
|
// Dump the DLLs
|
||||||
userTags := slicer.String(options.UserTags)
|
//userTags := slicer.String(options.UserTags)
|
||||||
if userTags.Contains("experimental") {
|
//if userTags.Contains("cgo") {
|
||||||
return nil
|
// err := os.WriteFile(filepath.Join(options.BuildDirectory, "WebView2Loader.dll"), x64.WebView2Loader, 0755)
|
||||||
}
|
// if err != nil {
|
||||||
err := os.WriteFile(filepath.Join(options.BuildDirectory, "WebView2Loader.dll"), x64.WebView2Loader, 0755)
|
// return err
|
||||||
if err != nil {
|
// }
|
||||||
return err
|
//}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
//+build experimental
|
|
||||||
|
|
||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FileFilter defines a filter for dialog boxes
|
|
||||||
type FileFilter = frontend.FileFilter
|
|
||||||
|
|
||||||
// OpenDialogOptions contains the options for the OpenDialogOptions runtime method
|
|
||||||
type OpenDialogOptions = frontend.OpenDialogOptions
|
|
||||||
|
|
||||||
// SaveDialogOptions contains the options for the SaveDialog runtime method
|
|
||||||
type SaveDialogOptions = frontend.SaveDialogOptions
|
|
||||||
|
|
||||||
type DialogType = frontend.DialogType
|
|
||||||
|
|
||||||
const (
|
|
||||||
InfoDialog = frontend.InfoDialog
|
|
||||||
WarningDialog = frontend.WarningDialog
|
|
||||||
ErrorDialog = frontend.ErrorDialog
|
|
||||||
QuestionDialog = frontend.QuestionDialog
|
|
||||||
)
|
|
||||||
|
|
||||||
// MessageDialogOptions contains the options for the Message dialogs, EG Info, Warning, etc runtime methods
|
|
||||||
type MessageDialogOptions = frontend.MessageDialogOptions
|
|
||||||
|
|
||||||
// OpenDirectoryDialog prompts the user to select a directory
|
|
||||||
func OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
return frontend.OpenDirectoryDialog(dialogOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenFileDialog prompts the user to select a file
|
|
||||||
func OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
return frontend.OpenFileDialog(dialogOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenMultipleFilesDialog prompts the user to select a file
|
|
||||||
func OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
return frontend.OpenMultipleFilesDialog(dialogOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveFileDialog prompts the user to select a file
|
|
||||||
func SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
return frontend.SaveFileDialog(dialogOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageDialog show a message dialog to the user
|
|
||||||
func MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
return frontend.MessageDialog(dialogOptions)
|
|
||||||
}
|
|
@ -1,192 +1,57 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||||
"github.com/wailsapp/wails/v2/internal/crypto"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FileFilter defines a filter for dialog boxes
|
// FileFilter defines a filter for dialog boxes
|
||||||
type FileFilter struct {
|
type FileFilter = frontend.FileFilter
|
||||||
DisplayName string // Filter information EG: "Image Files (*.jpg, *.png)"
|
|
||||||
Pattern string // semi-colon separated list of extensions, EG: "*.jpg;*.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenDialogOptions contains the options for the OpenDialogOptions runtime method
|
// OpenDialogOptions contains the options for the OpenDialogOptions runtime method
|
||||||
type OpenDialogOptions struct {
|
type OpenDialogOptions = frontend.OpenDialogOptions
|
||||||
DefaultDirectory string
|
|
||||||
DefaultFilename string
|
|
||||||
Title string
|
|
||||||
Filters []FileFilter
|
|
||||||
AllowFiles bool
|
|
||||||
AllowDirectories bool
|
|
||||||
ShowHiddenFiles bool
|
|
||||||
CanCreateDirectories bool
|
|
||||||
ResolvesAliases bool
|
|
||||||
TreatPackagesAsDirectories bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveDialogOptions contains the options for the SaveDialog runtime method
|
// SaveDialogOptions contains the options for the SaveDialog runtime method
|
||||||
type SaveDialogOptions struct {
|
type SaveDialogOptions = frontend.SaveDialogOptions
|
||||||
DefaultDirectory string
|
|
||||||
DefaultFilename string
|
|
||||||
Title string
|
|
||||||
Filters []FileFilter
|
|
||||||
ShowHiddenFiles bool
|
|
||||||
CanCreateDirectories bool
|
|
||||||
TreatPackagesAsDirectories bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type DialogType string
|
type DialogType = frontend.DialogType
|
||||||
|
|
||||||
const (
|
const (
|
||||||
InfoDialog DialogType = "info"
|
InfoDialog = frontend.InfoDialog
|
||||||
WarningDialog DialogType = "warning"
|
WarningDialog = frontend.WarningDialog
|
||||||
ErrorDialog DialogType = "error"
|
ErrorDialog = frontend.ErrorDialog
|
||||||
QuestionDialog DialogType = "question"
|
QuestionDialog = frontend.QuestionDialog
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageDialogOptions contains the options for the Message dialogs, EG Info, Warning, etc runtime methods
|
// MessageDialogOptions contains the options for the Message dialogs, EG Info, Warning, etc runtime methods
|
||||||
type MessageDialogOptions struct {
|
type MessageDialogOptions = frontend.MessageDialogOptions
|
||||||
Type DialogType
|
|
||||||
Title string
|
|
||||||
Message string
|
|
||||||
Buttons []string
|
|
||||||
DefaultButton string
|
|
||||||
CancelButton string
|
|
||||||
Icon string
|
|
||||||
}
|
|
||||||
|
|
||||||
// OpenDirectoryDialog prompts the user to select a directory
|
// OpenDirectoryDialog prompts the user to select a directory
|
||||||
func OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
func OpenDirectoryDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||||
|
appFrontend := getFrontend(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
return appFrontend.OpenDirectoryDialog(dialogOptions)
|
||||||
|
|
||||||
// Create unique dialog callback
|
|
||||||
uniqueCallback := crypto.RandomID()
|
|
||||||
|
|
||||||
// Subscribe to the respose channel
|
|
||||||
responseTopic := "dialog:opendirectoryselected:" + uniqueCallback
|
|
||||||
dialogResponseChannel, err := bus.Subscribe(responseTopic)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "dialog:select:directory:" + uniqueCallback
|
|
||||||
bus.Publish(message, dialogOptions)
|
|
||||||
|
|
||||||
// Wait for result
|
|
||||||
var result = <-dialogResponseChannel
|
|
||||||
|
|
||||||
// Delete subscription to response topic
|
|
||||||
bus.UnSubscribe(responseTopic)
|
|
||||||
|
|
||||||
return result.Data().(string), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenFileDialog prompts the user to select a file
|
// OpenFileDialog prompts the user to select a file
|
||||||
func OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
func OpenFileDialog(ctx context.Context, dialogOptions OpenDialogOptions) (string, error) {
|
||||||
|
appFrontend := getFrontend(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
return appFrontend.OpenFileDialog(dialogOptions)
|
||||||
|
|
||||||
// Create unique dialog callback
|
|
||||||
uniqueCallback := crypto.RandomID()
|
|
||||||
|
|
||||||
// Subscribe to the respose channel
|
|
||||||
responseTopic := "dialog:openselected:" + uniqueCallback
|
|
||||||
dialogResponseChannel, err := bus.Subscribe(responseTopic)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "dialog:select:open:" + uniqueCallback
|
|
||||||
bus.Publish(message, dialogOptions)
|
|
||||||
|
|
||||||
// Wait for result
|
|
||||||
var result = <-dialogResponseChannel
|
|
||||||
|
|
||||||
// Delete subscription to response topic
|
|
||||||
bus.UnSubscribe(responseTopic)
|
|
||||||
|
|
||||||
return result.Data().(string), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenMultipleFilesDialog prompts the user to select a file
|
// OpenMultipleFilesDialog prompts the user to select a file
|
||||||
func OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
func OpenMultipleFilesDialog(ctx context.Context, dialogOptions OpenDialogOptions) ([]string, error) {
|
||||||
|
appFrontend := getFrontend(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
return appFrontend.OpenMultipleFilesDialog(dialogOptions)
|
||||||
uniqueCallback := crypto.RandomID()
|
|
||||||
|
|
||||||
// Subscribe to the respose channel
|
|
||||||
responseTopic := "dialog:openmultipleselected:" + uniqueCallback
|
|
||||||
dialogResponseChannel, err := bus.Subscribe(responseTopic)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "dialog:select:openmultiple:" + uniqueCallback
|
|
||||||
bus.Publish(message, dialogOptions)
|
|
||||||
|
|
||||||
// Wait for result
|
|
||||||
var result = <-dialogResponseChannel
|
|
||||||
|
|
||||||
// Delete subscription to response topic
|
|
||||||
bus.UnSubscribe(responseTopic)
|
|
||||||
|
|
||||||
return result.Data().([]string), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveFileDialog prompts the user to select a file
|
// SaveFileDialog prompts the user to select a file
|
||||||
func SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
func SaveFileDialog(ctx context.Context, dialogOptions SaveDialogOptions) (string, error) {
|
||||||
|
appFrontend := getFrontend(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
return appFrontend.SaveFileDialog(dialogOptions)
|
||||||
uniqueCallback := crypto.RandomID()
|
|
||||||
|
|
||||||
// Subscribe to the respose channel
|
|
||||||
responseTopic := "dialog:saveselected:" + uniqueCallback
|
|
||||||
dialogResponseChannel, err := bus.Subscribe(responseTopic)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "dialog:select:save:" + uniqueCallback
|
|
||||||
bus.Publish(message, dialogOptions)
|
|
||||||
|
|
||||||
// Wait for result
|
|
||||||
var result = <-dialogResponseChannel
|
|
||||||
|
|
||||||
// Delete subscription to response topic
|
|
||||||
bus.UnSubscribe(responseTopic)
|
|
||||||
|
|
||||||
return result.Data().(string), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageDialog show a message dialog to the user
|
// MessageDialog show a message dialog to the user
|
||||||
func MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
|
func MessageDialog(ctx context.Context, dialogOptions MessageDialogOptions) (string, error) {
|
||||||
|
appFrontend := getFrontend(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
return appFrontend.MessageDialog(dialogOptions)
|
||||||
|
|
||||||
// Create unique dialog callback
|
|
||||||
uniqueCallback := crypto.RandomID()
|
|
||||||
|
|
||||||
// Subscribe to the respose channel
|
|
||||||
responseTopic := "dialog:messageselected:" + uniqueCallback
|
|
||||||
dialogResponseChannel, err := bus.Subscribe(responseTopic)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("ERROR: Cannot subscribe to bus topic: %+v\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "dialog:select:message:" + uniqueCallback
|
|
||||||
bus.Publish(message, dialogOptions)
|
|
||||||
|
|
||||||
// Wait for result
|
|
||||||
var result = <-dialogResponseChannel
|
|
||||||
|
|
||||||
// Delete subscription to response topic
|
|
||||||
bus.UnSubscribe(responseTopic)
|
|
||||||
|
|
||||||
return result.Data().(string), nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
// +build experimental
|
|
||||||
|
|
||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EventsOn registers a listener for the given event name
|
|
||||||
func EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
|
||||||
events := getEvents(ctx)
|
|
||||||
events.On(eventName, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EventsOff unregisters a listener for the given event name
|
|
||||||
func EventsOff(ctx context.Context, eventName string) {
|
|
||||||
events := getEvents(ctx)
|
|
||||||
events.Off(eventName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EventsOnce registers a listener for the given event name. After the first callback, the
|
|
||||||
// listener is deleted.
|
|
||||||
func EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
|
||||||
events := getEvents(ctx)
|
|
||||||
events.Once(eventName, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EventsOnMultiple registers a listener for the given event name, that may be called a maximum of 'counter' times
|
|
||||||
func EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int) {
|
|
||||||
events := getEvents(ctx)
|
|
||||||
events.OnMultiple(eventName, callback, counter)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EventsEmit pass through
|
|
||||||
func EventsEmit(ctx context.Context, eventName string, optionalData ...interface{}) {
|
|
||||||
events := getEvents(ctx)
|
|
||||||
events.Emit(eventName, optionalData...)
|
|
||||||
}
|
|
@ -1,45 +1,36 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// On registers a listener for a particular event
|
// EventsOn registers a listener for the given event name
|
||||||
func On(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
func EventsOn(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
||||||
|
events := getEvents(ctx)
|
||||||
bus := servicebus.ExtractBus(ctx)
|
events.On(eventName, callback)
|
||||||
|
|
||||||
eventMessage := &message.OnEventMessage{
|
|
||||||
Name: eventName,
|
|
||||||
Callback: callback,
|
|
||||||
Counter: -1,
|
|
||||||
}
|
|
||||||
bus.Publish("event:on", eventMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Once registers a listener for a particular event. After the first callback, the
|
// EventsOff unregisters a listener for the given event name
|
||||||
|
func EventsOff(ctx context.Context, eventName string) {
|
||||||
|
events := getEvents(ctx)
|
||||||
|
events.Off(eventName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EventsOnce registers a listener for the given event name. After the first callback, the
|
||||||
// listener is deleted.
|
// listener is deleted.
|
||||||
func Once(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
func EventsOnce(ctx context.Context, eventName string, callback func(optionalData ...interface{})) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
events := getEvents(ctx)
|
||||||
eventMessage := &message.OnEventMessage{
|
events.Once(eventName, callback)
|
||||||
Name: eventName,
|
|
||||||
Callback: callback,
|
|
||||||
Counter: 1,
|
|
||||||
}
|
|
||||||
bus.Publish("event:on", eventMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit pass through
|
// EventsOnMultiple registers a listener for the given event name, that may be called a maximum of 'counter' times
|
||||||
func Emit(ctx context.Context, eventName string, optionalData ...interface{}) {
|
func EventsOnMultiple(ctx context.Context, eventName string, callback func(optionalData ...interface{}), counter int) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
events := getEvents(ctx)
|
||||||
eventMessage := &message.EventMessage{
|
events.OnMultiple(eventName, callback, counter)
|
||||||
Name: eventName,
|
}
|
||||||
Data: optionalData,
|
|
||||||
}
|
// EventsEmit pass through
|
||||||
|
func EventsEmit(ctx context.Context, eventName string, optionalData ...interface{}) {
|
||||||
bus.Publish("event:emit:from:g", eventMessage)
|
events := getEvents(ctx)
|
||||||
|
events.Emit(eventName, optionalData...)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// +build !experimental
|
// +build cgo
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
//+build experimental
|
|
||||||
|
|
||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
)
|
|
||||||
|
|
||||||
func UpdateApplicationMenu(ctx context.Context) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
frontend.UpdateApplicationMenu()
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func UpdateContextMenu(ctx context.Context, contextMenu *menu.ContextMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:updatecontextmenu", contextMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:settraymenu", trayMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateTrayMenuLabel(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:updatetraymenulabel", trayMenu)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
|
||||||
frontend := getFrontend(ctx)
|
|
||||||
bus.Publish("menu:deletetraymenu", trayMenu)
|
|
||||||
}
|
|
||||||
*/
|
|
@ -1,34 +1,32 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateApplicationMenu(ctx context.Context) {
|
func UpdateApplicationMenu(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:updateappmenu", nil)
|
frontend.UpdateApplicationMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func UpdateContextMenu(ctx context.Context, contextMenu *menu.ContextMenu) {
|
func UpdateContextMenu(ctx context.Context, contextMenu *menu.ContextMenu) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:updatecontextmenu", contextMenu)
|
bus.Publish("menu:updatecontextmenu", contextMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
func SetTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:settraymenu", trayMenu)
|
bus.Publish("menu:settraymenu", trayMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateTrayMenuLabel(ctx context.Context, trayMenu *menu.TrayMenu) {
|
func UpdateTrayMenuLabel(ctx context.Context, trayMenu *menu.TrayMenu) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:updatetraymenulabel", trayMenu)
|
bus.Publish("menu:updatetraymenulabel", trayMenu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
func DeleteTrayMenu(ctx context.Context, trayMenu *menu.TrayMenu) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
frontend := getFrontend(ctx)
|
||||||
bus.Publish("menu:deletetraymenu", trayMenu)
|
bus.Publish("menu:deletetraymenu", trayMenu)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
//+build experimental
|
|
||||||
|
|
||||||
package runtime
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
|
||||||
"log"
|
|
||||||
goruntime "runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getFrontend(ctx context.Context) frontend.Frontend {
|
|
||||||
result := ctx.Value("frontend")
|
|
||||||
if result != nil {
|
|
||||||
return result.(frontend.Frontend)
|
|
||||||
}
|
|
||||||
pc, _, _, _ := goruntime.Caller(1)
|
|
||||||
funcName := goruntime.FuncForPC(pc).Name()
|
|
||||||
log.Fatalf("cannot call '%s': Application not initialised", funcName)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getEvents(ctx context.Context) frontend.Events {
|
|
||||||
result := ctx.Value("events")
|
|
||||||
if result != nil {
|
|
||||||
return result.(frontend.Events)
|
|
||||||
}
|
|
||||||
pc, _, _, _ := goruntime.Caller(1)
|
|
||||||
funcName := goruntime.FuncForPC(pc).Name()
|
|
||||||
log.Fatalf("cannot call '%s': Application not initialised", funcName)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quit the application
|
|
||||||
func Quit(ctx context.Context) {
|
|
||||||
appFrontend := getFrontend(ctx)
|
|
||||||
appFrontend.Quit()
|
|
||||||
}
|
|
@ -1,15 +1,36 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||||
|
"log"
|
||||||
|
goruntime "runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getFrontend(ctx context.Context) frontend.Frontend {
|
||||||
|
result := ctx.Value("frontend")
|
||||||
|
if result != nil {
|
||||||
|
return result.(frontend.Frontend)
|
||||||
|
}
|
||||||
|
pc, _, _, _ := goruntime.Caller(1)
|
||||||
|
funcName := goruntime.FuncForPC(pc).Name()
|
||||||
|
log.Fatalf("cannot call '%s': Application not initialised", funcName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEvents(ctx context.Context) frontend.Events {
|
||||||
|
result := ctx.Value("events")
|
||||||
|
if result != nil {
|
||||||
|
return result.(frontend.Events)
|
||||||
|
}
|
||||||
|
pc, _, _, _ := goruntime.Caller(1)
|
||||||
|
funcName := goruntime.FuncForPC(pc).Name()
|
||||||
|
log.Fatalf("cannot call '%s': Application not initialised", funcName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Quit the application
|
// Quit the application
|
||||||
func Quit(ctx context.Context) {
|
func Quit(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
// Start shutdown of Wails
|
appFrontend.Quit()
|
||||||
bus.Publish("quit", "runtime.Quit()")
|
|
||||||
}
|
}
|
||||||
|
@ -1,98 +1,89 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v2/internal/servicebus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// WindowSetTitle sets the title of the window
|
// WindowSetTitle sets the title of the window
|
||||||
func WindowSetTitle(ctx context.Context, title string) {
|
func WindowSetTitle(ctx context.Context, title string) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:settitle", title)
|
appFrontend.WindowSetTitle(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowFullscreen makes the window fullscreen
|
// WindowFullscreen makes the window fullscreen
|
||||||
func WindowFullscreen(ctx context.Context) {
|
func WindowFullscreen(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:fullscreen", "")
|
appFrontend.WindowFullscreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowUnFullscreen makes the window UnFullscreen
|
// WindowUnFullscreen makes the window UnFullscreen
|
||||||
func WindowUnFullscreen(ctx context.Context) {
|
func WindowUnFullscreen(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:unfullscreen", "")
|
appFrontend.WindowUnFullscreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowCenter the window on the current screen
|
// WindowCenter the window on the current screen
|
||||||
func WindowCenter(ctx context.Context) {
|
func WindowCenter(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:center", "")
|
appFrontend.WindowCenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowShow shows the window if hidden
|
// WindowShow shows the window if hidden
|
||||||
func WindowShow(ctx context.Context) {
|
func WindowShow(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:show", "")
|
appFrontend.WindowShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowHide the window
|
// WindowHide the window
|
||||||
func WindowHide(ctx context.Context) {
|
func WindowHide(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:hide", "")
|
appFrontend.WindowHide()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowSetSize sets the size of the window
|
// WindowSetSize sets the size of the window
|
||||||
func WindowSetSize(ctx context.Context, width int, height int) {
|
func WindowSetSize(ctx context.Context, width int, height int) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
message := fmt.Sprintf("window:size:%d:%d", width, height)
|
appFrontend.WindowSetSize(width, height)
|
||||||
bus.Publish(message, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowSetSize sets the size of the window
|
// WindowSetMinSize sets the minimum size of the window
|
||||||
func WindowSetMinSize(ctx context.Context, width int, height int) {
|
func WindowSetMinSize(ctx context.Context, width int, height int) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
message := fmt.Sprintf("window:minsize:%d:%d", width, height)
|
appFrontend.WindowSetMinSize(width, height)
|
||||||
bus.Publish(message, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowSetSize sets the size of the window
|
// WindowSetMaxSize sets the maximum size of the window
|
||||||
func WindowSetMaxSize(ctx context.Context, width int, height int) {
|
func WindowSetMaxSize(ctx context.Context, width int, height int) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
message := fmt.Sprintf("window:maxsize:%d:%d", width, height)
|
appFrontend.WindowSetMaxSize(width, height)
|
||||||
bus.Publish(message, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowSetPosition sets the position of the window
|
// WindowSetPosition sets the position of the window
|
||||||
func WindowSetPosition(ctx context.Context, x int, y int) {
|
func WindowSetPosition(ctx context.Context, x int, y int) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
message := fmt.Sprintf("window:position:%d:%d", x, y)
|
appFrontend.WindowSetPos(x, y)
|
||||||
bus.Publish(message, "")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowMaximise the window
|
// WindowMaximise the window
|
||||||
func WindowMaximise(ctx context.Context) {
|
func WindowMaximise(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:maximise", "")
|
appFrontend.WindowMaximise()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowUnmaximise the window
|
// WindowUnmaximise the window
|
||||||
func WindowUnmaximise(ctx context.Context) {
|
func WindowUnmaximise(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:unmaximise", "")
|
appFrontend.WindowUnmaximise()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowMinimise the window
|
// WindowMinimise the window
|
||||||
func WindowMinimise(ctx context.Context) {
|
func WindowMinimise(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:minimise", "")
|
appFrontend.WindowMinimise()
|
||||||
}
|
}
|
||||||
|
|
||||||
// WindowUnminimise the window
|
// WindowUnminimise the window
|
||||||
func WindowUnminimise(ctx context.Context) {
|
func WindowUnminimise(ctx context.Context) {
|
||||||
bus := servicebus.ExtractBus(ctx)
|
appFrontend := getFrontend(ctx)
|
||||||
bus.Publish("window:unminimise", "")
|
appFrontend.WindowUnminimise()
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
// +build !experimental
|
|
||||||
|
|
||||||
// Package wails is the main package of the Wails project.
|
// Package wails is the main package of the Wails project.
|
||||||
// It is used by client applications.
|
// It is used by client applications.
|
||||||
package wails
|
package wails
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/wailsapp/wails/v2/internal/app"
|
app "github.com/wailsapp/wails/v2/internal/appng"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
// +build windows
|
|
||||||
// +build experimental
|
|
||||||
|
|
||||||
// Package wails is the main package of the Wails project.
|
|
||||||
// It is used by client applications.
|
|
||||||
package wails
|
|
||||||
|
|
||||||
import (
|
|
||||||
app "github.com/wailsapp/wails/v2/internal/appng"
|
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Run creates an application based on the given config and executes it
|
|
||||||
func Run(options *options.App) error {
|
|
||||||
|
|
||||||
// Call an Init method manually
|
|
||||||
err := Init()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mainapp, err := app.CreateApp(options)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mainapp.Run()
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user