5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 20:03:01 +08:00

Feature/align api (#1161)

* Fix WindowSetRGBA API

* Change WindowUnFullscreen -> WindowUnfullscreen for consistency
RGBA bugfix
This commit is contained in:
Lea Anthony 2022-02-19 20:29:55 +11:00 committed by GitHub
parent 2ded86c369
commit 93491eb2eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 77 additions and 94 deletions

View File

@ -106,8 +106,8 @@ func (b BridgeClient) WindowFullscreen() {
b.session.log.Info("WindowFullscreen unsupported in Bridge mode")
}
func (b BridgeClient) WindowUnFullscreen() {
b.session.log.Info("WindowUnFullscreen unsupported in Bridge mode")
func (b BridgeClient) WindowUnfullscreen() {
b.session.log.Info("WindowUnfullscreen unsupported in Bridge mode")
}
func (b BridgeClient) WindowSetColour(colour int) {

View File

@ -2,11 +2,12 @@ package bridge
import (
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os/exec"
"strconv"
"strings"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wailsapp/wails/v2/internal/messagedispatcher"
"github.com/wailsapp/wails/v2/internal/logger"
@ -126,7 +127,7 @@ func (d *DialogClient) WindowSetMaxSize(width int, height int) {
func (d *DialogClient) WindowFullscreen() {
}
func (d *DialogClient) WindowUnFullscreen() {
func (d *DialogClient) WindowUnfullscreen() {
}
func (d *DialogClient) WindowSetColour(colour int) {

View File

@ -61,8 +61,8 @@ func (c *Client) WindowFullscreen() {
C.Fullscreen(c.app.app)
}
// WindowUnFullscreen will unfullscreen the window
func (c *Client) WindowUnFullscreen() {
// WindowUnfullscreen will unfullscreen the window
func (c *Client) WindowUnfullscreen() {
C.UnFullscreen(c.app.app)
}
@ -141,8 +141,6 @@ func (c *Client) OpenFileDialog(dialogOptions runtime.OpenDialogOptions, callbac
c.app.string2CString(strings.Join(filters, ";")),
c.app.string2CString(dialogOptions.DefaultFilename),
c.app.string2CString(dialogOptions.DefaultDirectory),
c.app.bool2Cint(dialogOptions.AllowFiles),
c.app.bool2Cint(dialogOptions.AllowDirectories),
c.app.bool2Cint(false),
c.app.bool2Cint(dialogOptions.ShowHiddenFiles),
c.app.bool2Cint(dialogOptions.CanCreateDirectories),
@ -189,8 +187,6 @@ func (c *Client) OpenMultipleFilesDialog(dialogOptions runtime.OpenDialogOptions
c.app.string2CString(strings.Join(filters, ";")),
c.app.string2CString(dialogOptions.DefaultFilename),
c.app.string2CString(dialogOptions.DefaultDirectory),
c.app.bool2Cint(dialogOptions.AllowFiles),
c.app.bool2Cint(dialogOptions.AllowDirectories),
c.app.bool2Cint(true),
c.app.bool2Cint(dialogOptions.ShowHiddenFiles),
c.app.bool2Cint(dialogOptions.CanCreateDirectories),
@ -239,7 +235,6 @@ func (c *Client) MessageDialog(dialogOptions runtime.MessageDialogOptions, callb
c.app.string2CString(string(dialogOptions.Type)),
c.app.string2CString(dialogOptions.Title),
c.app.string2CString(dialogOptions.Message),
c.app.string2CString(dialogOptions.Icon),
c.app.string2CString(buttons[0]),
c.app.string2CString(buttons[1]),
c.app.string2CString(buttons[2]),

View File

@ -10,13 +10,14 @@ import "C"
import (
"encoding/json"
"github.com/leaanthony/go-common-file-dialog/cfd"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/sys/windows"
"log"
"strconv"
"syscall"
"github.com/leaanthony/go-common-file-dialog/cfd"
"github.com/wailsapp/wails/v2/pkg/runtime"
"golang.org/x/sys/windows"
"github.com/wailsapp/wails/v2/internal/logger"
)
@ -63,8 +64,8 @@ func (c *Client) WindowFullscreen() {
C.Fullscreen(c.app.app)
}
// WindowUnFullscreen will unfullscreen the window
func (c *Client) WindowUnFullscreen() {
// WindowUnfullscreen will unfullscreen the window
func (c *Client) WindowUnfullscreen() {
C.UnFullscreen(c.app.app)
}

View File

@ -167,7 +167,7 @@ func (f *Frontend) WindowFullscreen() {
f.mainWindow.Fullscreen()
}
func (f *Frontend) WindowUnFullscreen() {
func (f *Frontend) WindowUnfullscreen() {
f.mainWindow.UnFullscreen()
}

View File

@ -159,7 +159,7 @@ func (f *Frontend) WindowFullscreen() {
f.mainWindow.Fullscreen()
}
func (f *Frontend) WindowUnFullscreen() {
func (f *Frontend) WindowUnfullscreen() {
f.mainWindow.UnFullscreen()
}

View File

@ -172,7 +172,7 @@ func (f *Frontend) WindowFullscreen() {
f.mainWindow.Fullscreen()
}
func (f *Frontend) WindowUnFullscreen() {
func (f *Frontend) WindowUnfullscreen() {
runtime.LockOSThread()
if f.frontendOptions.Frameless && f.frontendOptions.DisableResize == false {
f.ExecJS("window.wails.flags.enableResize = true;")

View File

@ -231,8 +231,8 @@ func (d *DevWebServer) WindowFullscreen() {
d.desktopFrontend.WindowFullscreen()
}
func (d *DevWebServer) WindowUnFullscreen() {
d.desktopFrontend.WindowUnFullscreen()
func (d *DevWebServer) WindowUnfullscreen() {
d.desktopFrontend.WindowUnfullscreen()
}
func (d *DevWebServer) WindowSetRGBA(col *options.RGBA) {
@ -308,7 +308,7 @@ func (d *DevWebServer) broadcast(message string) {
d.socketMutex.Lock()
defer d.socketMutex.Unlock()
for client, locker := range d.websocketClients {
go func() {
go func(client *websocket.Conn, locker *sync.Mutex) {
if client == nil {
d.logger.Error("Lost connection to websocket server")
return
@ -321,7 +321,7 @@ func (d *DevWebServer) broadcast(message string) {
return
}
locker.Unlock()
}()
}(client, locker)
}
}
@ -343,7 +343,7 @@ func (d *DevWebServer) broadcastExcludingSender(message string, sender *websocke
d.socketMutex.Lock()
defer d.socketMutex.Unlock()
for client, locker := range d.websocketClients {
go func() {
go func(client *websocket.Conn, locker *sync.Mutex) {
if client == sender {
return
}
@ -355,7 +355,7 @@ func (d *DevWebServer) broadcastExcludingSender(message string, sender *websocke
return
}
locker.Unlock()
}()
}(client, locker)
}
}

View File

@ -3,10 +3,11 @@ package dispatcher
import (
"encoding/json"
"errors"
"github.com/wailsapp/wails/v2/internal/frontend"
"github.com/wailsapp/wails/v2/pkg/options"
"strconv"
"strings"
"github.com/wailsapp/wails/v2/internal/frontend"
"github.com/wailsapp/wails/v2/pkg/options"
)
func (d *Dispatcher) mustAtoI(input string) int {
@ -31,7 +32,7 @@ func (d *Dispatcher) processWindowMessage(message string, sender frontend.Fronte
case 'F':
go sender.WindowFullscreen()
case 'f':
go sender.WindowUnFullscreen()
go sender.WindowUnfullscreen()
case 's':
parts := strings.Split(message[3:], ":")
w := d.mustAtoI(parts[0])

View File

@ -84,7 +84,7 @@ type Frontend interface {
WindowSetMinSize(width int, height int)
WindowSetMaxSize(width int, height int)
WindowFullscreen()
WindowUnFullscreen()
WindowUnfullscreen()
WindowSetRGBA(col *options.RGBA)
WindowReload()

View File

@ -50,7 +50,7 @@ export function WindowFullscreen() {
*
* @export
*/
export function WindowUnFullscreen() {
export function WindowUnfullscreen() {
window.WailsInvoke('Wf');
}
@ -187,10 +187,13 @@ export function WindowUnminimise() {
* Sets the background colour of the window
*
* @export
* @param {RGBA} RGBA background colour
* @param {number} R Red
* @param {number} G Green
* @param {number} B Blue
* @param {number} A Alpha
*/
export function WindowSetRGBA(RGBA) {
let rgba = JSON.stringify(RGBA);
export function WindowSetRGBA(R, G, B, A) {
let rgba = JSON.stringify({r:R || 0, g:G || 0, b:B || 0, a:A || 255});
window.WailsInvoke('Wr:' + rgba);
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -8,14 +8,6 @@ export interface Size {
h: number;
}
export interface RGBA {
r: number;
g: number;
b: number;
a: number;
}
export interface runtime {
EventsEmit(eventName: string, data?: any): void;
@ -45,7 +37,7 @@ export interface runtime {
WindowFullscreen(): void;
WindowUnFullscreen(): void;
WindowUnfullscreen(): void;
WindowSetSize(width: number, height: number): Promise<Size>;
@ -73,7 +65,7 @@ export interface runtime {
WindowUnminimise(): void;
WindowSetRGBA(rgba: RGBA): void;
WindowSetRGBA(R: number, G: number, B: number, A: number): void;
BrowserOpenURL(url: string): void;

View File

@ -1 +1 @@
(()=>{var d=Object.defineProperty;var m=n=>d(n,"__esModule",{value:!0});var e=(n,i)=>{m(n);for(var o in i)d(n,o,{get:i[o],enumerable:!0})};var t={};e(t,{LogDebug:()=>W,LogError:()=>f,LogFatal:()=>s,LogInfo:()=>c,LogTrace:()=>p,LogWarning:()=>x});function p(n){window.runtime.LogTrace(n)}function W(n){window.runtime.LogDebug(n)}function c(n){window.runtime.LogInfo(n)}function x(n){window.runtime.LogWarning(n)}function f(n){window.runtime.LogError(n)}function s(n){window.runtime.LogFatal(n)}var w={};e(w,{EventsEmit:()=>S,EventsOn:()=>a,EventsOnMultiple:()=>l,EventsOnce:()=>g});function l(n,i,o){window.runtime.EventsOnMultiple(n,i,o)}function a(n,i){OnMultiple(n,i,-1)}function g(n,i){OnMultiple(n,i,1)}function S(n){let i=[n].slice.call(arguments);return window.runtime.EventsEmit.apply(null,i)}var r={};e(r,{WindowCenter:()=>M,WindowFullscreen:()=>v,WindowGetPosition:()=>T,WindowGetSize:()=>O,WindowHide:()=>B,WindowMaximise:()=>b,WindowMinimise:()=>C,WindowReload:()=>L,WindowSetMaxSize:()=>F,WindowSetMinSize:()=>G,WindowSetPosition:()=>R,WindowSetRGBA:()=>H,WindowSetSize:()=>U,WindowSetTitle:()=>E,WindowShow:()=>P,WindowToggleMaximise:()=>h,WindowUnFullscreen:()=>z,WindowUnmaximise:()=>A,WindowUnminimise:()=>D});function L(){window.runtime.WindowReload()}function M(){window.runtime.WindowCenter()}function E(n){window.runtime.WindowSetTitle(n)}function v(){window.runtime.WindowFullscreen()}function z(){window.runtime.WindowUnFullscreen()}function O(){window.runtime.WindowGetSize()}function U(n,i){window.runtime.WindowSetSize(n,i)}function F(n,i){window.runtime.WindowSetMaxSize(n,i)}function G(n,i){window.runtime.WindowSetMinSize(n,i)}function R(n,i){window.runtime.WindowSetPosition(n,i)}function T(){window.runtime.WindowGetPosition()}function B(){window.runtime.WindowHide()}function P(){window.runtime.WindowShow()}function b(){window.runtime.WindowMaximise()}function h(){window.runtime.WindowToggleMaximise()}function A(){window.runtime.WindowUnmaximise()}function C(){window.runtime.WindowMinimise()}function D(){window.runtime.WindowUnminimise()}function H(n){window.runtime.WindowSetRGBA(n)}var u={};e(u,{BrowserOpenURL:()=>I});function I(n){window.runtime.BrowserOpenURL(n)}function Q(){window.runtime.Quit()}var j={...t,...w,...r,...u,Quit:Q};})();
(()=>{var d=Object.defineProperty;var m=n=>d(n,"__esModule",{value:!0});var e=(n,i)=>{m(n);for(var o in i)d(n,o,{get:i[o],enumerable:!0})};var t={};e(t,{LogDebug:()=>W,LogError:()=>x,LogFatal:()=>s,LogInfo:()=>c,LogTrace:()=>p,LogWarning:()=>f});function p(n){window.runtime.LogTrace(n)}function W(n){window.runtime.LogDebug(n)}function c(n){window.runtime.LogInfo(n)}function f(n){window.runtime.LogWarning(n)}function x(n){window.runtime.LogError(n)}function s(n){window.runtime.LogFatal(n)}var w={};e(w,{EventsEmit:()=>S,EventsOn:()=>a,EventsOnMultiple:()=>l,EventsOnce:()=>g});function l(n,i,o){window.runtime.EventsOnMultiple(n,i,o)}function a(n,i){OnMultiple(n,i,-1)}function g(n,i){OnMultiple(n,i,1)}function S(n){let i=[n].slice.call(arguments);return window.runtime.EventsEmit.apply(null,i)}var r={};e(r,{WindowCenter:()=>M,WindowFullscreen:()=>v,WindowGetPosition:()=>B,WindowGetSize:()=>O,WindowHide:()=>F,WindowMaximise:()=>b,WindowMinimise:()=>C,WindowReload:()=>L,WindowSetMaxSize:()=>G,WindowSetMinSize:()=>R,WindowSetPosition:()=>T,WindowSetRGBA:()=>H,WindowSetSize:()=>U,WindowSetTitle:()=>E,WindowShow:()=>P,WindowToggleMaximise:()=>h,WindowUnfullscreen:()=>z,WindowUnmaximise:()=>A,WindowUnminimise:()=>D});function L(){window.runtime.WindowReload()}function M(){window.runtime.WindowCenter()}function E(n){window.runtime.WindowSetTitle(n)}function v(){window.runtime.WindowFullscreen()}function z(){window.runtime.WindowUnfullscreen()}function O(){window.runtime.WindowGetSize()}function U(n,i){window.runtime.WindowSetSize(n,i)}function G(n,i){window.runtime.WindowSetMaxSize(n,i)}function R(n,i){window.runtime.WindowSetMinSize(n,i)}function T(n,i){window.runtime.WindowSetPosition(n,i)}function B(){window.runtime.WindowGetPosition()}function F(){window.runtime.WindowHide()}function P(){window.runtime.WindowShow()}function b(){window.runtime.WindowMaximise()}function h(){window.runtime.WindowToggleMaximise()}function A(){window.runtime.WindowUnmaximise()}function C(){window.runtime.WindowMinimise()}function D(){window.runtime.WindowUnminimise()}function H(n){window.runtime.WindowSetRGBA(n)}var u={};e(u,{BrowserOpenURL:()=>I});function I(n){window.runtime.BrowserOpenURL(n)}function Q(){window.runtime.Quit()}var j={...t,...w,...r,...u,Quit:Q};})();

View File

@ -52,8 +52,8 @@ export function WindowFullscreen() {
*
* @export
*/
export function WindowUnFullscreen() {
window.runtime.WindowUnFullscreen();
export function WindowUnfullscreen() {
window.runtime.WindowUnfullscreen();
}
/**

View File

@ -2,6 +2,7 @@ package messagedispatcher
import (
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wailsapp/wails/v2/internal/logger"
@ -32,7 +33,7 @@ type Client interface {
WindowSetMinSize(width int, height int)
WindowSetMaxSize(width int, height int)
WindowFullscreen()
WindowUnFullscreen()
WindowUnfullscreen()
WindowSetColour(colour int)
DarkModeEnabled(callbackID string)
SetApplicationMenu(menuJSON string)

View File

@ -3,11 +3,12 @@ package messagedispatcher
import (
"context"
"encoding/json"
"github.com/wailsapp/wails/v2/pkg/runtime"
"strconv"
"strings"
"sync"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wailsapp/wails/v2/internal/crypto"
"github.com/wailsapp/wails/v2/internal/logger"
"github.com/wailsapp/wails/v2/internal/messagedispatcher/message"
@ -278,7 +279,7 @@ func (d *Dispatcher) processWindowMessage(result *servicebus.Message) {
case "unfullscreen":
// Notify clients
for _, client := range d.clients {
client.frontend.WindowUnFullscreen()
client.frontend.WindowUnfullscreen()
}
case "setcolour":
colour, ok := result.Data().(int)

View File

@ -2,11 +2,12 @@ package webserver
import (
"context"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/runtime"
"net/http"
"strings"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/wailsapp/wails/v2/internal/logger"
ws "nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
@ -150,8 +151,8 @@ func (wc *WebClient) WindowSetTitle(title string) {}
// WindowFullscreen is a noop in the webclient
func (wc *WebClient) WindowFullscreen() {}
// WindowUnFullscreen is a noop in the webclient
func (wc *WebClient) WindowUnFullscreen() {}
// WindowUnfullscreen is a noop in the webclient
func (wc *WebClient) WindowUnfullscreen() {}
// WindowSetColour is a noop in the webclient
func (wc *WebClient) WindowSetColour(colour int) {

View File

@ -18,10 +18,10 @@ func WindowFullscreen(ctx context.Context) {
appFrontend.WindowFullscreen()
}
// WindowUnFullscreen makes the window UnFullscreen
func WindowUnFullscreen(ctx context.Context) {
// WindowUnfullscreen makes the window UnFullscreen
func WindowUnfullscreen(ctx context.Context) {
appFrontend := getFrontend(ctx)
appFrontend.WindowUnFullscreen()
appFrontend.WindowUnfullscreen()
}
// WindowCenter the window on the current screen
@ -112,7 +112,13 @@ func WindowUnminimise(ctx context.Context) {
appFrontend.WindowUnminimise()
}
func WindowSetRGBA(ctx context.Context, col *options.RGBA) {
func WindowSetRGBA(ctx context.Context, R, G, B, A uint8) {
appFrontend := getFrontend(ctx)
col := &options.RGBA{
R: R,
G: G,
B: B,
A: A,
}
appFrontend.WindowSetRGBA(col)
}

View File

@ -22,10 +22,10 @@ JS Signature: `WindowFullscreen()`
Makes the window full screen.
### WindowUnFullscreen
Go Signature: `WindowUnFullscreen(ctx context.Context)`
### WindowUnfullscreen
Go Signature: `WindowUnfullscreen(ctx context.Context)`
JS Signature: `WindowUnFullscreen()`
JS Signature: `WindowUnfullscreen()`
Restores the previous window dimensions and position prior to full screen.
@ -141,11 +141,11 @@ JS Signature: `WindowUnminimise()`
Restores the window to the dimensions and position prior to minimising.
### WindowSetRGBA
Go Signature: `WindowSetRGBA(ctx context.Context, col *options.RGBA)`
Go Signature: `WindowSetRGBA(ctx context.Context, R, G, B, A uint8)`
JS Signature: `WindowSetRGBA(col: RGBA)`
JS Signature: `WindowSetRGBA(R, G, B, A)`
Sets the background colour of the window to the given [RGBA](window#rgba) colour definition.
Sets the background colour of the window to the given RGBA colour definition.
This colour will show through for all transparent pixels.
Valid values for R, G, B and A are 0-255.
@ -177,15 +177,4 @@ interface Size {
}
```
### RGBA
```ts
interface RGBA {
r: number;
g: number;
b: number;
a: number;
}
```

View File

@ -27,9 +27,9 @@ JS 方法签名: `WindowFullscreen()`
### 窗口取消全屏
Go 方法签名: `WindowUnFullscreen(ctx context.Context)`
Go 方法签名: `WindowUnfullscreen(ctx context.Context)`
JS 方法签名: `WindowUnFullscreen()`
JS 方法签名: `WindowUnfullscreen()`
在全屏之前恢复先前的窗口尺寸和位置。