mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[windows] support runtime.WindowSetRGBA
This commit is contained in:
@@ -21,7 +21,7 @@ require (
|
||||
github.com/leaanthony/debme v1.2.1
|
||||
github.com/leaanthony/go-ansi-parser v1.0.1
|
||||
github.com/leaanthony/go-common-file-dialog v1.0.3
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210906112707-5ca00d49e830
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210912034341-849718dc22d7
|
||||
github.com/leaanthony/gosod v1.0.1
|
||||
github.com/leaanthony/idgen v1.0.0
|
||||
github.com/leaanthony/slicer v1.5.0
|
||||
|
||||
@@ -125,8 +125,8 @@ github.com/leaanthony/go-ansi-parser v1.0.1 h1:97v6c5kYppVsbScf4r/VZdXyQ21KQIfeQ
|
||||
github.com/leaanthony/go-ansi-parser v1.0.1/go.mod h1:7arTzgVI47srICYhvgUV4CGd063sGEeoSlych5yeSPM=
|
||||
github.com/leaanthony/go-common-file-dialog v1.0.3 h1:O0uGjKnWtdEADGrkg+TyAAbZylykMwwx/MNEXn9fp+Y=
|
||||
github.com/leaanthony/go-common-file-dialog v1.0.3/go.mod h1:TGhEc9eSJgRsupZ+iH1ZgAOnEo9zp05cRH2j08RPrF0=
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210906112707-5ca00d49e830 h1:96/BSuQHPLQHkibP8PMs/BkSTHDL/yZoq4fGinEjb2w=
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210906112707-5ca00d49e830/go.mod h1:jVGFkh5EgsmI4X5Z/XsALrCELLEqrbc4dP3EGO9UY78=
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210912034341-849718dc22d7 h1:8IvKTQk33VBpncfgezD6BKutv5kCSZbDIcCNHOT9T4w=
|
||||
github.com/leaanthony/go-webview2 v0.0.0-20210912034341-849718dc22d7/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
|
||||
github.com/leaanthony/gosod v1.0.1 h1:F+4c3DmEBfigi7oAswCV2RpQ+k4DcNbhuCZUGdBHacQ=
|
||||
github.com/leaanthony/gosod v1.0.1/go.mod h1:W8RyeSFBXu7RpIxPGEJfW4moSyGGEjlJMLV25wEbAdU=
|
||||
github.com/leaanthony/idgen v1.0.0 h1:IZreR+JGEzFV4yeVuBZA25gM0keUoFy+RDUldncQ+Jw=
|
||||
|
||||
@@ -165,9 +165,37 @@ func (f *Frontend) WindowSetMaxSize(width int, height int) {
|
||||
f.mainWindow.SetMaxSize(width, height)
|
||||
}
|
||||
|
||||
func (f *Frontend) WindowSetColour(colour int) {
|
||||
func (f *Frontend) WindowSetRGBA(col *options.RGBA) {
|
||||
runtime.LockOSThread()
|
||||
// TODO: Set webview2 background to this colour
|
||||
if col == nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.mainWindow.Dispatch(func() {
|
||||
controller := f.chromium.GetController()
|
||||
controller2 := controller.GetICoreWebView2Controller2()
|
||||
|
||||
backgroundCol := edge.COREWEBVIEW2_COLOR{
|
||||
A: col.A,
|
||||
R: col.R,
|
||||
G: col.G,
|
||||
B: col.B,
|
||||
}
|
||||
|
||||
// Webview2 only has 0 and 255 as valid values.
|
||||
if backgroundCol.A > 0 && backgroundCol.A < 255 {
|
||||
backgroundCol.A = 255
|
||||
}
|
||||
|
||||
if f.frontendOptions.Windows != nil && f.frontendOptions.Windows.WebviewIsTransparent {
|
||||
backgroundCol.A = 0
|
||||
}
|
||||
|
||||
err := controller2.PutDefaultBackgroundColor(backgroundCol)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (f *Frontend) Quit() {
|
||||
@@ -176,6 +204,7 @@ func (f *Frontend) Quit() {
|
||||
|
||||
func (f *Frontend) setupChromium() {
|
||||
chromium := edge.NewChromium()
|
||||
f.chromium = chromium
|
||||
chromium.MessageCallback = f.processMessage
|
||||
chromium.WebResourceRequestedCallback = f.processRequest
|
||||
chromium.NavigationCompletedCallback = f.navigationCompleted
|
||||
@@ -209,14 +238,11 @@ func (f *Frontend) setupChromium() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
//c2, err := chromium.GetWebView2Controller2()
|
||||
//err = c2.PutDefaultBackgroundColor(edge.COREWEBVIEW2_COLOR{R: 255, G: 0, B: 0, A: 255})
|
||||
//if err != nil {
|
||||
// log.Fatal(err)
|
||||
//}
|
||||
// Set background colour
|
||||
f.WindowSetRGBA(f.frontendOptions.RGBA)
|
||||
|
||||
chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
|
||||
chromium.Navigate("file://wails/")
|
||||
f.chromium = chromium
|
||||
}
|
||||
|
||||
type EventNotify struct {
|
||||
|
||||
@@ -226,8 +226,8 @@ func (d *DevWebServer) WindowUnFullscreen() {
|
||||
d.desktopFrontend.WindowUnFullscreen()
|
||||
}
|
||||
|
||||
func (d *DevWebServer) WindowSetColour(colour int) {
|
||||
d.desktopFrontend.WindowSetColour(colour)
|
||||
func (d *DevWebServer) WindowSetRGBA(col *options.RGBA) {
|
||||
d.desktopFrontend.WindowSetRGBA(col)
|
||||
}
|
||||
|
||||
func (d *DevWebServer) SetApplicationMenu(menu *menu.Menu) {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package dispatcher
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/wailsapp/wails/v2/internal/frontend"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -44,6 +46,13 @@ func (d *Dispatcher) processWindowMessage(message string, sender frontend.Fronte
|
||||
go sender.WindowHide()
|
||||
case 'S':
|
||||
go sender.WindowShow()
|
||||
case 'r':
|
||||
var rgba options.RGBA
|
||||
err := json.Unmarshal([]byte(message[3:]), &rgba)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
go sender.WindowSetRGBA(&rgba)
|
||||
case 'M':
|
||||
go sender.WindowMaximise()
|
||||
case 'U':
|
||||
|
||||
@@ -3,6 +3,7 @@ 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
|
||||
@@ -84,7 +85,7 @@ type Frontend interface {
|
||||
WindowSetMaxSize(width int, height int)
|
||||
WindowFullscreen()
|
||||
WindowUnFullscreen()
|
||||
WindowSetColour(colour int)
|
||||
WindowSetRGBA(col *options.RGBA)
|
||||
WindowReload()
|
||||
|
||||
// Menus
|
||||
|
||||
@@ -173,6 +173,19 @@ export function WindowUnminimise() {
|
||||
window.WailsInvoke('Wu');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the background colour of the window
|
||||
*
|
||||
* @export
|
||||
* @param {RGBA} RGBA background colour
|
||||
*/
|
||||
export function WindowSetRGBA(RGBA) {
|
||||
let rgba = JSON.stringify(RGBA);
|
||||
window.WailsInvoke('Wr:' + rgba);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close the Window
|
||||
*
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -8,6 +8,13 @@ interface Size {
|
||||
h: number;
|
||||
}
|
||||
|
||||
interface RGBA {
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
a: number;
|
||||
}
|
||||
|
||||
|
||||
interface runtime {
|
||||
EventsEmit(eventName: string, data?: any): void;
|
||||
@@ -64,6 +71,8 @@ interface runtime {
|
||||
|
||||
WindowUnminimise(): void
|
||||
|
||||
WindowSetRGBA(rgba: RGBA): void;
|
||||
|
||||
WindowClose(): void
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -176,6 +176,16 @@ export function WindowUnminimise() {
|
||||
window.runtime.WindowUnminimise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background colour of the window
|
||||
*
|
||||
* @export
|
||||
* @param {RGBA} RGBA background colour
|
||||
*/
|
||||
export function WindowSetRGBA(RGBA) {
|
||||
window.runtime.WindowSetRGBA(RGBA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the Window
|
||||
*
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
var Default = &App{
|
||||
Width: 1024,
|
||||
Height: 768,
|
||||
RGBA: 0xFFFFFFFF,
|
||||
Logger: logger.NewDefaultLogger(),
|
||||
LogLevel: logger.INFO,
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type App struct {
|
||||
MaxHeight int
|
||||
StartHidden bool
|
||||
HideWindowOnClose bool
|
||||
RGBA int
|
||||
RGBA *RGBA
|
||||
Assets embed.FS
|
||||
Menu *menu.Menu
|
||||
Logger logger.Logger `json:"-"`
|
||||
@@ -42,6 +42,13 @@ type App struct {
|
||||
//Mac *mac.Options
|
||||
}
|
||||
|
||||
type RGBA struct {
|
||||
R uint8 `json:"r"`
|
||||
G uint8 `json:"g"`
|
||||
B uint8 `json:"b"`
|
||||
A uint8 `json:"a"`
|
||||
}
|
||||
|
||||
// MergeDefaults will set the minimum default values for an application
|
||||
func MergeDefaults(appoptions *App) {
|
||||
err := mergo.Merge(appoptions, Default)
|
||||
@@ -49,6 +56,16 @@ func MergeDefaults(appoptions *App) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// DEfault colour. Doesn't work well with mergo
|
||||
if appoptions.RGBA == nil {
|
||||
appoptions.RGBA = &RGBA{
|
||||
R: 255,
|
||||
G: 255,
|
||||
B: 255,
|
||||
A: 255,
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure max and min are valid
|
||||
if appoptions.MinWidth > 0 && appoptions.MaxWidth > 0 {
|
||||
if appoptions.MinWidth > appoptions.MaxWidth {
|
||||
|
||||
@@ -2,6 +2,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
)
|
||||
|
||||
// WindowSetTitle sets the title of the window
|
||||
@@ -93,3 +94,8 @@ func WindowUnminimise(ctx context.Context) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
appFrontend.WindowUnminimise()
|
||||
}
|
||||
|
||||
func WindowSetRGBA(ctx context.Context, col *options.RGBA) {
|
||||
appFrontend := getFrontend(ctx)
|
||||
appFrontend.WindowSetRGBA(col)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user