5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 17:22:01 +08:00
wails/v2/internal/frontend/frontend.go
skamensky 04d35410de
Expose screen dimensions (#1519)
* get dimensions working for linux

* Cleaning up some GTK code

I was getting the following errors due to some bad casts.

Gdk-CRITICAL **: 18:58:51.943: gdk_monitor_get_geometry: assertion 'GDK_IS_MONITOR (monitor)' failed
Gdk-CRITICAL **: 18:58:51.943: gdk_display_get_monitor_at_window: assertion 'GDK_IS_DISPLAY (display)' failed

This commit fixes these errors

* Adding Screen namespace along with linux implementation

* moving ScreenGetAll into a more appropriate place

* Fixing typescript definition mistake, documentation, ordering of functions, and formatting

* add ScreenGetAll to more templates

* moving screen into its own javascript file

* fixing bug where screen objects are not returned from the runtime function

* rebuilding frontend wrapper package

* adding windows implementation of ScreenGetAll

* adding screen get all implementation for darwin

* reverting a change that is unrelated to the work on expose-dimensions

* removing duplicate comparison

* changing GetNthScreen in screen API on macos

To use frame instead of visibleframe to keep into account the space the the dock takes up
We want to include that space in the calculation in order to keep the sizes of screens consistent across platforms

* Correcting screen jsdoc

It used to say it returned a single screen object. Now it says that it returns an array of screen objects

* Fixing typo in function name

* reverting pointless spacing change

* reverting pointless spacing change

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
Co-authored-by: shmuel.kamensky <shmuel.kamensky@shutterfly.com>
2022-07-16 12:33:37 +10:00

116 lines
3.0 KiB
Go

package frontend
import (
"context"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/options"
)
// FileFilter defines a filter for dialog boxes
type FileFilter struct {
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
type OpenDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
ResolvesAliases bool
TreatPackagesAsDirectories bool
}
// SaveDialogOptions contains the options for the SaveDialog runtime method
type SaveDialogOptions struct {
DefaultDirectory string
DefaultFilename string
Title string
Filters []FileFilter
ShowHiddenFiles bool
CanCreateDirectories bool
TreatPackagesAsDirectories bool
}
type DialogType string
const (
InfoDialog DialogType = "info"
WarningDialog DialogType = "warning"
ErrorDialog DialogType = "error"
QuestionDialog DialogType = "question"
)
type Screen struct {
IsCurrent bool `json:"isCurrent"`
IsPrimary bool `json:"isPrimary"`
Width int `json:"width"`
Height int `json:"height"`
}
// MessageDialogOptions contains the options for the Message dialogs, EG Info, Warning, etc runtime methods
type MessageDialogOptions struct {
Type DialogType
Title string
Message string
Buttons []string
DefaultButton string
CancelButton string
Icon []byte
}
type Frontend interface {
Run(context.Context) error
Quit()
// Dialog
OpenFileDialog(dialogOptions OpenDialogOptions) (string, error)
OpenMultipleFilesDialog(dialogOptions OpenDialogOptions) ([]string, error)
OpenDirectoryDialog(dialogOptions OpenDialogOptions) (string, error)
SaveFileDialog(dialogOptions SaveDialogOptions) (string, error)
MessageDialog(dialogOptions MessageDialogOptions) (string, error)
// Window
WindowSetTitle(title string)
WindowShow()
WindowHide()
WindowCenter()
WindowToggleMaximise()
WindowMaximise()
WindowUnmaximise()
WindowMinimise()
WindowUnminimise()
WindowSetAlwaysOnTop(b bool)
WindowSetPosition(x int, y int)
WindowGetPosition() (int, int)
WindowSetSize(width int, height int)
WindowGetSize() (int, int)
WindowSetMinSize(width int, height int)
WindowSetMaxSize(width int, height int)
WindowFullscreen()
WindowUnfullscreen()
WindowSetBackgroundColour(col *options.RGBA)
WindowReload()
WindowReloadApp()
WindowSetSystemDefaultTheme()
WindowSetLightTheme()
WindowSetDarkTheme()
//Screen
ScreenGetAll() ([]Screen, error)
// Menus
MenuSetApplicationMenu(menu *menu.Menu)
MenuUpdateApplicationMenu()
// Events
Notify(name string, data ...interface{})
// Browser
BrowserOpenURL(url string)
}