mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 21:10:54 +08:00
[mac] Fix lifecycle hooks
This commit is contained in:
parent
62d1d621aa
commit
c90bfc310a
@ -35,10 +35,6 @@ type App struct {
|
||||
|
||||
func (a *App) Run() error {
|
||||
err := a.frontend.Run(a.ctx)
|
||||
if a.shutdownCallback != nil {
|
||||
a.shutdownCallback(a.ctx)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -13,14 +13,12 @@
|
||||
|
||||
#define ON_MAIN_THREAD(str) dispatch_async(dispatch_get_main_queue(), ^{ str; });
|
||||
#define unicode(input) [NSString stringWithFormat:@"%C", input]
|
||||
#define STREQ(a,b) strcmp(a, b) == 0
|
||||
|
||||
|
||||
@interface WailsWindow : NSWindow
|
||||
- (BOOL)canBecomeKeyWindow;
|
||||
@end
|
||||
|
||||
@interface WailsContext : NSObject <WKURLSchemeHandler,WKScriptMessageHandler>
|
||||
@interface WailsContext : NSObject <WKURLSchemeHandler,WKScriptMessageHandler,WKNavigationDelegate>
|
||||
|
||||
@property (retain) WailsWindow* mainWindow;
|
||||
@property (retain) WKWebView* webview;
|
||||
|
@ -238,6 +238,8 @@
|
||||
[self.webview setValue:[NSNumber numberWithBool:!webviewIsTransparent] forKey:@"drawsBackground"];
|
||||
}
|
||||
|
||||
[self.webview setNavigationDelegate:self];
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setBool:FALSE forKey:@"NSAutomaticQuoteSubstitutionEnabled"];
|
||||
|
||||
@ -395,6 +397,10 @@
|
||||
|
||||
}
|
||||
|
||||
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
|
||||
processMessage("DomReady");
|
||||
}
|
||||
|
||||
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
|
||||
NSString *m = message.body;
|
||||
|
||||
|
@ -214,6 +214,9 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) {
|
||||
|
||||
func (f *Frontend) Quit() {
|
||||
f.mainWindow.Quit()
|
||||
if f.frontendOptions.OnShutdown != nil {
|
||||
f.frontendOptions.OnShutdown(f.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
type EventNotify struct {
|
||||
@ -235,6 +238,14 @@ func (f *Frontend) Notify(name string, data ...interface{}) {
|
||||
}
|
||||
|
||||
func (f *Frontend) processMessage(message string) {
|
||||
|
||||
if message == "DomReady" {
|
||||
if f.frontendOptions.OnDomReady != nil {
|
||||
f.frontendOptions.OnDomReady(f.ctx)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
result, err := f.dispatcher.ProcessMessage(message, f)
|
||||
if err != nil {
|
||||
f.logger.Error(err.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user