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