mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Merge branch '930_-_default_window_state'
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
@interface AppDelegate : NSResponder <NSTouchBarProvider>
|
||||
|
||||
@property bool alwaysOnTop;
|
||||
@property bool startHidden;
|
||||
@property (retain) WailsWindow* mainWindow;
|
||||
|
||||
@end
|
||||
|
||||
@@ -16,16 +16,22 @@
|
||||
}
|
||||
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
[self.mainWindow makeKeyAndOrderFront:self];
|
||||
if (self.alwaysOnTop) {
|
||||
[self.mainWindow setLevel:NSStatusWindowLevel];
|
||||
}
|
||||
if ( !self.startHidden ) {
|
||||
[self.mainWindow makeKeyAndOrderFront:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@synthesize touchBar;
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,7 +12,12 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "WailsContext.h"
|
||||
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug);
|
||||
#define WindowStartsNormal 0
|
||||
#define WindowStartsMaximised 1
|
||||
#define WindowStartsMinimised 2
|
||||
#define WindowStartsFullscreen 3
|
||||
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden);
|
||||
void Run(void*);
|
||||
|
||||
void SetTitle(void* ctx, const char *title);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#import "WailsMenu.h"
|
||||
#import "WailsMenuItem.h"
|
||||
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug) {
|
||||
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int debug, int windowStartState, int startsHidden) {
|
||||
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
@@ -20,10 +20,27 @@ WailsContext* Create(const char* title, int width, int height, int frameless, in
|
||||
|
||||
result.debug = debug;
|
||||
|
||||
if ( windowStartState == WindowStartsFullscreen ) {
|
||||
fullscreen = 1;
|
||||
}
|
||||
|
||||
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent];
|
||||
[result SetTitle:safeInit(title)];
|
||||
[result Center];
|
||||
|
||||
switch( windowStartState ) {
|
||||
case WindowStartsMaximised:
|
||||
[result.mainWindow zoom:nil];
|
||||
break;
|
||||
case WindowStartsMinimised:
|
||||
//TODO: Can you start a mac app minimised?
|
||||
break;
|
||||
}
|
||||
|
||||
if ( startsHidden == 1 ) {
|
||||
result.startHidden = true;
|
||||
}
|
||||
|
||||
result.alwaysOnTop = alwaysOnTop;
|
||||
result.hideOnClose = hideWindowOnClose;
|
||||
|
||||
@@ -306,6 +323,7 @@ void Run(void *inctx) {
|
||||
ctx.appdelegate = delegate;
|
||||
delegate.mainWindow = ctx.mainWindow;
|
||||
delegate.alwaysOnTop = ctx.alwaysOnTop;
|
||||
delegate.startHidden = ctx.startHidden;
|
||||
|
||||
[ctx loadRequest:@"wails://wails/"];
|
||||
[app setMainMenu:ctx.applicationMenu];
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
@property bool hideOnClose;
|
||||
@property bool shuttingDown;
|
||||
@property bool startHidden;
|
||||
|
||||
@property NSSize maxSize;
|
||||
@property NSSize minSize;
|
||||
|
||||
@@ -533,10 +533,10 @@
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:0 error:nil];
|
||||
NSString *nsjson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
processOpenFileDialogResponse([nsjson UTF8String]);
|
||||
[nsjson release];
|
||||
[arr release];
|
||||
}];
|
||||
|
||||
ON_MAIN_THREAD([dialog runModal];)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -579,11 +579,13 @@
|
||||
// Setup callback handler
|
||||
[dialog beginSheetModalForWindow:self.mainWindow completionHandler:^(NSModalResponse returnCode) {
|
||||
NSURL *url = [dialog URL];
|
||||
processSaveFileDialogResponse([url.path UTF8String]);
|
||||
if ( url != nil ) {
|
||||
processSaveFileDialogResponse([url.path UTF8String]);
|
||||
return;
|
||||
}
|
||||
processSaveFileDialogResponse("");
|
||||
}];
|
||||
|
||||
ON_MAIN_THREAD([dialog runModal];)
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void) SetAbout :(NSString*)title :(NSString*)description :(void*)imagedata :(int)datalen {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
}
|
||||
|
||||
- (NSMenuItem*) newMenuItemWithContext :(WailsContext*)ctx :(NSString*)title :(SEL)selector :(NSString*)key :(NSEventModifierFlags)flags {
|
||||
NSMenuItem *result = [[NSMenuItem new] autorelease];
|
||||
NSMenuItem *result = [NSMenuItem new];
|
||||
if ( title != nil ) {
|
||||
[result setTitle:title];
|
||||
}
|
||||
@@ -45,7 +45,7 @@
|
||||
[super initWithTitle:title];
|
||||
}
|
||||
[self setAutoenablesItems:NO];
|
||||
return self;
|
||||
return [self init];
|
||||
}
|
||||
|
||||
- (void) appendSubmenu :(WailsMenu*)child {
|
||||
|
||||
@@ -50,6 +50,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
||||
fullscreen := bool2Cint(frontendOptions.Fullscreen)
|
||||
alwaysOnTop := bool2Cint(frontendOptions.AlwaysOnTop)
|
||||
hideWindowOnClose := bool2Cint(frontendOptions.HideWindowOnClose)
|
||||
startsHidden := bool2Cint(frontendOptions.StartHidden)
|
||||
debug := bool2Cint(debugMode)
|
||||
|
||||
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
|
||||
@@ -58,6 +59,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
||||
|
||||
width := C.int(frontendOptions.Width)
|
||||
height := C.int(frontendOptions.Height)
|
||||
windowStartState := C.int(int(frontendOptions.WindowStartState))
|
||||
|
||||
title = c.String(frontendOptions.Title)
|
||||
|
||||
@@ -78,7 +80,7 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
|
||||
}
|
||||
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
|
||||
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
|
||||
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug)
|
||||
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug, windowStartState, startsHidden)
|
||||
|
||||
// Create menu
|
||||
result := &Window{
|
||||
|
||||
@@ -130,10 +130,6 @@ func (f *Frontend) Run(ctx context.Context) error {
|
||||
}
|
||||
}()
|
||||
|
||||
if f.frontendOptions.Fullscreen {
|
||||
mainWindow.Fullscreen()
|
||||
}
|
||||
|
||||
mainWindow.Run()
|
||||
mainWindow.Close()
|
||||
return nil
|
||||
@@ -412,11 +408,6 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC
|
||||
go f.frontendOptions.OnDomReady(f.ctx)
|
||||
}
|
||||
|
||||
// If you want to start hidden, return
|
||||
if f.frontendOptions.StartHidden {
|
||||
return
|
||||
}
|
||||
|
||||
// Hack to make it visible: https://github.com/MicrosoftEdge/WebView2Feedback/issues/1077#issuecomment-825375026
|
||||
err := f.chromium.Hide()
|
||||
if err != nil {
|
||||
@@ -426,6 +417,24 @@ func (f *Frontend) navigationCompleted(sender *edge.ICoreWebView2, args *edge.IC
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
f.mainWindow.Show()
|
||||
|
||||
if f.frontendOptions.StartHidden {
|
||||
return
|
||||
}
|
||||
|
||||
switch f.frontendOptions.WindowStartState {
|
||||
case options.Maximised:
|
||||
f.mainWindow.Maximise()
|
||||
case options.Minimised:
|
||||
f.mainWindow.Minimise()
|
||||
case options.Fullscreen:
|
||||
f.mainWindow.Fullscreen()
|
||||
f.mainWindow.Show()
|
||||
default:
|
||||
if f.frontendOptions.Fullscreen {
|
||||
f.mainWindow.Fullscreen()
|
||||
}
|
||||
f.mainWindow.Show()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,24 +18,24 @@ type Window struct {
|
||||
dispatchq []func()
|
||||
}
|
||||
|
||||
func NewWindow(parent winc.Controller, options *options.App) *Window {
|
||||
func NewWindow(parent winc.Controller, appoptions *options.App) *Window {
|
||||
result := new(Window)
|
||||
result.frontendOptions = options
|
||||
result.frontendOptions = appoptions
|
||||
result.SetIsForm(true)
|
||||
|
||||
var exStyle int
|
||||
if options.Windows != nil {
|
||||
if appoptions.Windows != nil {
|
||||
exStyle = w32.WS_EX_CONTROLPARENT | w32.WS_EX_APPWINDOW
|
||||
if options.Windows.WindowIsTranslucent {
|
||||
if appoptions.Windows.WindowIsTranslucent {
|
||||
exStyle |= w32.WS_EX_NOREDIRECTIONBITMAP
|
||||
}
|
||||
}
|
||||
if options.AlwaysOnTop {
|
||||
if appoptions.AlwaysOnTop {
|
||||
exStyle |= w32.WS_EX_TOPMOST
|
||||
}
|
||||
|
||||
var dwStyle = w32.WS_OVERLAPPEDWINDOW
|
||||
if options.Frameless {
|
||||
if appoptions.Frameless {
|
||||
dwStyle = w32.WS_POPUP
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func NewWindow(parent winc.Controller, options *options.App) *Window {
|
||||
result.SetParent(parent)
|
||||
|
||||
loadIcon := true
|
||||
if options.Windows != nil && options.Windows.DisableWindowIcon == true {
|
||||
if appoptions.Windows != nil && appoptions.Windows.DisableWindowIcon == true {
|
||||
loadIcon = false
|
||||
}
|
||||
if loadIcon {
|
||||
@@ -53,21 +53,21 @@ func NewWindow(parent winc.Controller, options *options.App) *Window {
|
||||
}
|
||||
}
|
||||
|
||||
result.SetSize(options.Width, options.Height)
|
||||
result.SetText(options.Title)
|
||||
if options.Frameless == false && !options.Fullscreen {
|
||||
result.EnableMaxButton(!options.DisableResize)
|
||||
result.EnableSizable(!options.DisableResize)
|
||||
result.SetMinSize(options.MinWidth, options.MinHeight)
|
||||
result.SetMaxSize(options.MaxWidth, options.MaxHeight)
|
||||
result.SetSize(appoptions.Width, appoptions.Height)
|
||||
result.SetText(appoptions.Title)
|
||||
if appoptions.Frameless == false && !appoptions.Fullscreen {
|
||||
result.EnableMaxButton(!appoptions.DisableResize)
|
||||
result.EnableSizable(!appoptions.DisableResize)
|
||||
result.SetMinSize(appoptions.MinWidth, appoptions.MinHeight)
|
||||
result.SetMaxSize(appoptions.MaxWidth, appoptions.MaxHeight)
|
||||
}
|
||||
|
||||
if options.Windows != nil {
|
||||
if options.Windows.WindowIsTranslucent {
|
||||
if appoptions.Windows != nil {
|
||||
if appoptions.Windows.WindowIsTranslucent {
|
||||
result.SetTranslucentBackground()
|
||||
}
|
||||
|
||||
if options.Windows.DisableWindowIcon {
|
||||
if appoptions.Windows.DisableWindowIcon {
|
||||
result.DisableIcon()
|
||||
}
|
||||
}
|
||||
@@ -78,8 +78,8 @@ func NewWindow(parent winc.Controller, options *options.App) *Window {
|
||||
|
||||
result.SetFont(winc.DefaultFont)
|
||||
|
||||
if options.Menu != nil {
|
||||
result.SetApplicationMenu(options.Menu)
|
||||
if appoptions.Menu != nil {
|
||||
result.SetApplicationMenu(appoptions.Menu)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@@ -16,6 +16,15 @@ import (
|
||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||
)
|
||||
|
||||
type WindowStartState int
|
||||
|
||||
const (
|
||||
Normal WindowStartState = 0
|
||||
Maximised WindowStartState = 1
|
||||
Minimised WindowStartState = 2
|
||||
Fullscreen WindowStartState = 3
|
||||
)
|
||||
|
||||
// App contains options for creating the App
|
||||
type App struct {
|
||||
Title string
|
||||
@@ -40,6 +49,7 @@ type App struct {
|
||||
OnDomReady func(ctx context.Context) `json:"-"`
|
||||
OnShutdown func(ctx context.Context) `json:"-"`
|
||||
Bind []interface{}
|
||||
WindowStartState WindowStartState
|
||||
|
||||
//ContextMenus []*menu.ContextMenu
|
||||
//TrayMenus []*menu.TrayMenu
|
||||
|
||||
Reference in New Issue
Block a user