wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
24.46k stars 1.17k forks source link

V3: main process still running after closing main window and then systray. #3058

Open techierishi opened 10 months ago

techierishi commented 10 months ago

Description

I am trying to create an application with one main window and a systray which will run in background after window is closed. However even after closing the systray

To Reproduce

  1. Use following code

package main

import ( "changeme/pkg/clipboard" "embed" "log" "runtime"

"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/icons"

)

//go:embed all:frontend/dist var assets embed.FS

func main() {

app := application.New(application.Options{
    Name:        "App Demo",
    Description: "A demo of windows",
    Assets: application.AssetOptions{
        FS: assets,
    },
    Mac: application.MacOptions{
        ApplicationShouldTerminateAfterLastWindowClosed: true,
    },
})

app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{})

systemTray := app.NewSystemTray()

window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
    Width:         500,
    Height:        800,
    Frameless:     true,
    AlwaysOnTop:   true,
    Hidden:        true,
    DisableResize: true,
    ShouldClose: func(window *application.WebviewWindow) bool {
        window.Hide()
        return false
    },
    Windows: application.WindowsWindow{
        HiddenOnTaskbar: true,
    },
    KeyBindings: map[string]func(window *application.WebviewWindow){
        "F12": func(window *application.WebviewWindow) {
            systemTray.OpenMenu()
        },
    },
})

if runtime.GOOS == "darwin" {
    systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
}

myMenu := app.NewMenu()
myMenu.Add("Quit").OnClick(func(ctx *application.Context) {
    app.Quit()
})

systemTray.SetMenu(myMenu)
systemTray.AttachWindow(window).WindowOffset(5)

err := app.Run()
if err != nil {
    log.Fatal(err)
}

clipboard.Record()

}


2. Now run the application
3. Close main window
4. Exit from systray as well
5. Main process is still running

### Expected behaviour

Main process should close after exiting from main window and systray

### Screenshots

_No response_

### Attempted Fixes

_No response_

### System Details

```shell
DEB | Using go webview2loader

# Wails
Version | v2.6.0

# System
┌────────────────────────────────────┐
| OS           | Windows 10 Home     |
| Version      | 2009 (Build: 22621) |
| ID           | 22H2                |
| Go Version   | go1.21.1            |
| Platform     | windows             |
| Architecture | amd64               |
└────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 119.0.2151.58 |
| Nodejs     | N/A          | Installed | 20.8.0        |
| npm        | N/A          | Installed | 10.1.0        |
| *upx       | N/A          | Available |               |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

# Diagnosis
Optional package(s) installation details:
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

Additional context

No response

leaanthony commented 10 months ago

I appreciate you opening this. Whilst v3 is in alpha, we have a strict feedback procedure outlined here: https://v3alpha.wails.io/getting-started/feedback This is to reduce noise whilst the branch is unstable and keep all the information in one place. We'd love to have you as part of the v3 feedback loop and development. Locking this and moving it to discord. Thanks again 🙏

leaanthony commented 10 months ago

I'm unable to reproduce this so it might be to do with your clipboard package. I've updated the docs with better instructions for reporting bugs. Feel free to join us on discord to discuss more 👍