github.com/secoba/wails/v2@v2.6.4/internal/frontend/frontend.go (about)

     1  package frontend
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/secoba/wails/v2/pkg/menu"
     7  	"github.com/secoba/wails/v2/pkg/options"
     8  )
     9  
    10  // FileFilter defines a filter for dialog boxes
    11  type FileFilter struct {
    12  	DisplayName string // Filter information EG: "Image Files (*.jpg, *.png)"
    13  	Pattern     string // semicolon separated list of extensions, EG: "*.jpg;*.png"
    14  }
    15  
    16  // OpenDialogOptions contains the options for the OpenDialogOptions runtime method
    17  type OpenDialogOptions struct {
    18  	DefaultDirectory           string
    19  	DefaultFilename            string
    20  	Title                      string
    21  	Filters                    []FileFilter
    22  	ShowHiddenFiles            bool
    23  	CanCreateDirectories       bool
    24  	ResolvesAliases            bool
    25  	TreatPackagesAsDirectories bool
    26  }
    27  
    28  // SaveDialogOptions contains the options for the SaveDialog runtime method
    29  type SaveDialogOptions struct {
    30  	DefaultDirectory           string
    31  	DefaultFilename            string
    32  	Title                      string
    33  	Filters                    []FileFilter
    34  	ShowHiddenFiles            bool
    35  	CanCreateDirectories       bool
    36  	TreatPackagesAsDirectories bool
    37  }
    38  
    39  type DialogType string
    40  
    41  const (
    42  	InfoDialog     DialogType = "info"
    43  	WarningDialog  DialogType = "warning"
    44  	ErrorDialog    DialogType = "error"
    45  	QuestionDialog DialogType = "question"
    46  )
    47  
    48  type Screen struct {
    49  	IsCurrent bool `json:"isCurrent"`
    50  	IsPrimary bool `json:"isPrimary"`
    51  
    52  	// Deprecated: Please use Size and PhysicalSize
    53  	Width int `json:"width"`
    54  	// Deprecated: Please use Size and PhysicalSize
    55  	Height int `json:"height"`
    56  
    57  	// Size is the size of the screen in logical pixel space, used when setting sizes in Wails
    58  	Size ScreenSize `json:"size"`
    59  	// PhysicalSize is the physical size of the screen in pixels
    60  	PhysicalSize ScreenSize `json:"physicalSize"`
    61  }
    62  
    63  type ScreenSize struct {
    64  	Width  int `json:"width"`
    65  	Height int `json:"height"`
    66  }
    67  
    68  // MessageDialogOptions contains the options for the Message dialogs, EG Info, Warning, etc runtime methods
    69  type MessageDialogOptions struct {
    70  	Type          DialogType
    71  	Title         string
    72  	Message       string
    73  	Buttons       []string
    74  	DefaultButton string
    75  	CancelButton  string
    76  	Icon          []byte
    77  }
    78  
    79  type Frontend interface {
    80  	Run(ctx context.Context) error
    81  	RunMainLoop()
    82  	ExecJS(js string)
    83  	Hide()
    84  	Show()
    85  	Quit()
    86  
    87  	// Dialog
    88  	OpenFileDialog(dialogOptions OpenDialogOptions) (string, error)
    89  	OpenMultipleFilesDialog(dialogOptions OpenDialogOptions) ([]string, error)
    90  	OpenDirectoryDialog(dialogOptions OpenDialogOptions) (string, error)
    91  	SaveFileDialog(dialogOptions SaveDialogOptions) (string, error)
    92  	MessageDialog(dialogOptions MessageDialogOptions) (string, error)
    93  
    94  	// Window
    95  	WindowSetTitle(title string)
    96  	WindowShow()
    97  	WindowHide()
    98  	WindowCenter()
    99  	WindowToggleMaximise()
   100  	WindowMaximise()
   101  	WindowUnmaximise()
   102  	WindowMinimise()
   103  	WindowUnminimise()
   104  	WindowSetAlwaysOnTop(b bool)
   105  	WindowSetPosition(x int, y int)
   106  	WindowGetPosition() (int, int)
   107  	WindowSetSize(width int, height int)
   108  	WindowGetSize() (int, int)
   109  	WindowSetMinSize(width int, height int)
   110  	WindowSetMaxSize(width int, height int)
   111  	WindowFullscreen()
   112  	WindowUnfullscreen()
   113  	WindowSetBackgroundColour(col *options.RGBA)
   114  	WindowReload()
   115  	WindowReloadApp()
   116  	WindowSetSystemDefaultTheme()
   117  	WindowSetLightTheme()
   118  	WindowSetDarkTheme()
   119  	WindowIsMaximised() bool
   120  	WindowIsMinimised() bool
   121  	WindowIsNormal() bool
   122  	WindowIsFullscreen() bool
   123  	WindowClose()
   124  	WindowPrint()
   125  
   126  	// Screen
   127  	ScreenGetAll() ([]Screen, error)
   128  
   129  	// Menus
   130  	MenuSetApplicationMenu(menu *menu.Menu)
   131  	MenuUpdateApplicationMenu()
   132  
   133  	// Events
   134  	Notify(name string, data ...interface{})
   135  
   136  	// Browser
   137  	BrowserOpenURL(url string)
   138  
   139  	// Clipboard
   140  	ClipboardGetText() (string, error)
   141  	ClipboardSetText(text string) error
   142  }