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

[v2] go fmt + windowIsTranslucent

This commit is contained in:
Lea Anthony 2021-09-15 08:41:38 +10:00
parent 00639677f5
commit be87d73da8
26 changed files with 79 additions and 71 deletions

View File

@ -1,3 +1,4 @@
//go:build linux || darwin || !windows
// +build linux darwin !windows
package wails

View File

@ -1,3 +1,4 @@
//go:build windows || !linux || !darwin
// +build windows !linux !darwin
package wails

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
//go:build dev
// +build dev
package main

View File

@ -1,3 +1,4 @@
//go:build dev
// +build dev
package main

View File

@ -1,3 +1,4 @@
//go:build windows
// +build windows
package cmd

View File

@ -1,4 +1,4 @@
package interfaces
// Runtime interface
type Runtime interface {}
type Runtime interface{}

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,7 +8,6 @@ import (
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/mac"
)
func main() {
@ -29,16 +28,11 @@ func main() {
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
RGBA: 0x000000FF,
RGBA: &options.RGBA{0, 0, 0, 255},
Windows: &windows.Options{
WebviewIsTransparent: true,
WindowBackgroundIsTranslucent: true,
DisableWindowIcon: true,
},
Mac: &mac.Options{
WebviewIsTransparent: true,
WindowBackgroundIsTranslucent: true,
TitleBar: mac.TitleBarHiddenInset(),
WebviewIsTransparent: true,
WindowIsTranslucent: true,
DisableWindowIcon: true,
},
LogLevel: logger.DEBUG,
OnStartup: app.startup,

View File

@ -35,18 +35,18 @@ HideWindowOnClose: false,
RGBA: 0x000000FF,
Assets: assets,
Windows: &windows.Options{
WebviewIsTransparent: true,
WindowBackgroundIsTranslucent: true,
DisableWindowIcon: true,
},
LogLevel: logger.DEBUG,
OnStartup: app.startup,
OnShutdown: app.shutdown,
Bind: []interface{}{
app,
},
})
if err != nil {
log.Fatal(err)
}
WebviewIsTransparent: true,
WindowIsTranslucent: true,
DisableWindowIcon: true,
},
LogLevel: logger.DEBUG,
OnStartup: app.startup,
OnShutdown: app.shutdown,
Bind: []interface{}{
app,
},
})
if err != nil {
log.Fatal(err)
}
}

View File

@ -32,12 +32,12 @@ func main() {
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
RGBA: 0x000000FF,
RGBA: &options.RGBA{0, 0, 0, 255},
Assets: assets,
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowBackgroundIsTranslucent: false,
DisableWindowIcon: false,
WebviewIsTransparent: false,
WindowIsTranslucent: false,
DisableWindowIcon: false,
},
LogLevel: logger.DEBUG,
OnStartup: app.startup,

View File

@ -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-20210912034341-849718dc22d7
github.com/leaanthony/go-webview2 v0.0.0-20210914103035-f00aa774a934
github.com/leaanthony/gosod v1.0.1
github.com/leaanthony/idgen v1.0.0
github.com/leaanthony/slicer v1.5.0

View File

@ -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-20210912034341-849718dc22d7 h1:8IvKTQk33VBpncfgezD6BKutv5kCSZbDIcCNHOT9T4w=
github.com/leaanthony/go-webview2 v0.0.0-20210912034341-849718dc22d7/go.mod h1:lS5ds4bruPk9d7lzdF/OH31Z0YCerI6MmHNFGsWoUnM=
github.com/leaanthony/go-webview2 v0.0.0-20210914103035-f00aa774a934 h1:nK/JTPyJi5QRqYjVZjXgtN4/dhg2qtngoLxLDVn429k=
github.com/leaanthony/go-webview2 v0.0.0-20210914103035-f00aa774a934/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=

View File

@ -46,7 +46,7 @@ extern void UpdateTrayMenuLabel(struct Application*, const char* JSON);
extern void AddContextMenu(struct Application*, char *contextMenuJSON);
extern void UpdateContextMenu(struct Application*, char *contextMenuJSON);
extern void WebviewIsTransparent(struct Application*);
extern void WindowBackgroundIsTranslucent(struct Application*);
extern void WindowIsTranslucent(struct Application*);
extern void* GetWindowHandle(struct Application*);
#ifdef __cplusplus

View File

@ -135,7 +135,7 @@ struct Application {
int fullSizeContent;
int useToolBar;
int hideToolbarSeparator;
int windowBackgroundIsTranslucent;
int WindowIsTranslucent;
int hasURLHandlers;
const char *startupURL;
@ -293,8 +293,8 @@ void Show(struct Application *app) {
);
}
void WindowBackgroundIsTranslucent(struct Application *app) {
app->windowBackgroundIsTranslucent = 1;
void WindowIsTranslucent(struct Application *app) {
app->WindowIsTranslucent = 1;
}
// Sends messages to the backend
@ -1534,7 +1534,7 @@ void Run(struct Application *app, int argc, char **argv) {
applyWindowColour(app);
// Process translucency
if (app->windowBackgroundIsTranslucent) {
if (app->WindowIsTranslucent) {
makeWindowBackgroundTranslucent(app);
}
@ -1775,7 +1775,7 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
result->useToolBar = 0;
result->hideToolbarSeparator = 0;
result->appearance = NULL;
result->windowBackgroundIsTranslucent = 0;
result->WindowIsTranslucent = 0;
// Window data
result->delegate = NULL;

View File

@ -57,8 +57,8 @@ func (a *Application) processPlatformSettings() error {
}
// Check if window should be translucent
if mac.WindowBackgroundIsTranslucent {
C.WindowBackgroundIsTranslucent(a.app)
if mac.WindowIsTranslucent {
C.WindowIsTranslucent(a.app)
}
// Process menu

View File

@ -138,7 +138,7 @@ void HideToolbarSeparator(struct Application* app);
void DisableFrame(struct Application* app);
void SetAppearance(struct Application* app, const char *);
void WebviewIsTransparent(struct Application* app);
void WindowBackgroundIsTranslucent(struct Application* app);
void WindowIsTranslucent(struct Application* app);
void SetTray(struct Application* app, const char *, const char *, const char *);
//void SetContextMenus(struct Application* app, const char *);
void AddTrayMenu(struct Application* app, const char *);

View File

@ -862,7 +862,7 @@ void UpdateTrayMenuLabel(struct Application* app, const char* JSON) {}
void AddContextMenu(struct Application* app, char *contextMenuJSON) {}
void UpdateContextMenu(struct Application* app, char *contextMenuJSON) {}
void WebviewIsTransparent(struct Application* app) {}
void WindowBackgroundIsTranslucent(struct Application* app) {}
void WindowIsTranslucent(struct Application* app) {}
void OpenDialog(struct Application* app, char *callbackID, char *title, char *filters, char *defaultFilename, char *defaultDir, int allowFiles, int allowDirs, int allowMultiple, int showHiddenFiles, int canCreateDirectories, int resolvesAliases, int treatPackagesAsDirectories) {}
void SaveDialog(struct Application* app, char *callbackID, char *title, char *filters, char *defaultFilename, char *defaultDir, int showHiddenFiles, int canCreateDirectories, int treatPackagesAsDirectories) {}
void MessageDialog(struct Application* app, char *callbackID, char *type, char *title, char *message, char *icon, char *button1, char *button2, char *button3, char *button4, char *defaultButton, char *cancelButton) {}

View File

@ -105,7 +105,7 @@ struct Application *NewApplication(const char *title, int width, int height, int
result->logLevel = logLevel;
result->hideWindowOnClose = hideWindowOnClose;
result->webviewIsTranparent = false;
result->windowBackgroundIsTranslucent = false;
result->WindowIsTranslucent = false;
result->disableWindowIcon = false;
// Min/Max Width/Height
@ -465,7 +465,7 @@ bool initWebView2(struct Application *app, int debugEnabled, messageCallback cb)
wvColor.G = app->backgroundColour.G;
wvColor.B = app->backgroundColour.B;
wvColor.A = app->backgroundColour.A == 0 ? 0 : 255;
if( app->windowBackgroundIsTranslucent ) {
if( app->WindowIsTranslucent ) {
wvColor.A = 0;
}
HRESULT result = wc2->put_DefaultBackgroundColor(wvColor);
@ -538,7 +538,7 @@ void Run(struct Application* app, int argc, char **argv) {
// Configure translucency
DWORD dwExStyle = 0;
if ( app->windowBackgroundIsTranslucent) {
if ( app->WindowIsTranslucent) {
dwExStyle = WS_EX_NOREDIRECTIONBITMAP;
wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));
}
@ -590,7 +590,7 @@ void Run(struct Application* app, int argc, char **argv) {
SetWindowPos(nullptr, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
}
if ( app->windowBackgroundIsTranslucent ) {
if ( app->WindowIsTranslucent ) {
// Enable the translucent background effect
enableTranslucentBackground(app);
@ -877,8 +877,8 @@ void WebviewIsTransparent(struct Application *app) {
app->webviewIsTranparent = true;
}
void WindowBackgroundIsTranslucent(struct Application *app) {
app->windowBackgroundIsTranslucent = true;
void WindowIsTranslucent(struct Application *app) {
app->WindowIsTranslucent = true;
}

View File

@ -47,8 +47,8 @@ func (a *Application) processPlatformSettings() error {
C.WebviewIsTransparent(a.app)
}
if config.WindowBackgroundIsTranslucent {
C.WindowBackgroundIsTranslucent(a.app)
if config.WindowIsTranslucent {
C.WindowIsTranslucent(a.app)
}
if config.DisableWindowIcon {

View File

@ -43,7 +43,7 @@ struct Application{
int frame;
char *startupURL;
bool webviewIsTranparent;
bool windowBackgroundIsTranslucent;
bool WindowIsTranslucent;
COREWEBVIEW2_COLOR backgroundColour;
bool disableWindowIcon;

View File

@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/leaanthony/slicer"
"log"
"runtime"
"strconv"
@ -42,8 +43,6 @@ type Frontend struct {
servingFromDisk bool
}
func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.Logger, appBindings *binding.Bindings, dispatcher frontend.Dispatcher) *Frontend {
result := &Frontend{
@ -241,14 +240,24 @@ func (f *Frontend) Quit() {
winc.Exit()
}
const (
ctrlZ int = 90
ctrlX = 88
ctrlC = 67
ctrlV = 86
)
func (f *Frontend) setupChromium() {
chromium := edge.NewChromium()
f.chromium = chromium
chromium.MessageCallback = f.processMessage
chromium.WebResourceRequestedCallback = f.processRequest
chromium.NavigationCompletedCallback = f.navigationCompleted
chromium.AcceleratorKeyCallback = func(_ uint) {
// TODO: Link to standard application shortcuts
acceleratorsWebviewShouldProcess := slicer.Int([]int{ctrlV, ctrlC, ctrlX, ctrlZ})
chromium.AcceleratorKeyCallback = func(vkey uint) bool {
// We want webview to handle ctrl-C, ctrl-Z, ctrl-v, ctrl-x
return !acceleratorsWebviewShouldProcess.Contains(int(vkey))
}
chromium.Embed(f.mainWindow.Handle())
chromium.Resize()

View File

@ -26,7 +26,7 @@ func NewWindow(parent winc.Controller, options *options.App) *Window {
var exStyle int
if options.Windows != nil {
exStyle = w32.WS_EX_CONTROLPARENT | w32.WS_EX_APPWINDOW
if options.Windows.WindowBackgroundIsTranslucent {
if options.Windows.WindowIsTranslucent {
exStyle |= w32.WS_EX_NOREDIRECTIONBITMAP
}
}
@ -58,7 +58,7 @@ func NewWindow(parent winc.Controller, options *options.App) *Window {
result.SetMaxSize(options.MaxWidth, options.MaxHeight)
if options.Windows != nil {
if options.Windows.WindowBackgroundIsTranslucent {
if options.Windows.WindowIsTranslucent {
result.SetTranslucentBackground()
}

View File

@ -10,10 +10,10 @@ const (
// Options are options specific to Mac
type Options struct {
TitleBar *TitleBar
Appearance AppearanceType
WebviewIsTransparent bool
WindowBackgroundIsTranslucent bool
ActivationPolicy ActivationPolicy
URLHandlers map[string]func(string)
TitleBar *TitleBar
Appearance AppearanceType
WebviewIsTransparent bool
WindowIsTranslucent bool
ActivationPolicy ActivationPolicy
URLHandlers map[string]func(string)
}

View File

@ -2,7 +2,7 @@ package windows
// Options are options specific to Windows
type Options struct {
WebviewIsTransparent bool
WindowBackgroundIsTranslucent bool
DisableWindowIcon bool
WebviewIsTransparent bool
WindowIsTranslucent bool
DisableWindowIcon bool
}