diff --git a/v2/examples/tray-icon/.gitignore b/v2/examples/tray-icon/.gitignore
new file mode 100644
index 000000000..a11bbf414
--- /dev/null
+++ b/v2/examples/tray-icon/.gitignore
@@ -0,0 +1,4 @@
+build/bin
+node_modules
+frontend/dist
+frontend/wailsjs
diff --git a/v2/examples/tray-icon/README.md b/v2/examples/tray-icon/README.md
new file mode 100644
index 000000000..e299d7870
--- /dev/null
+++ b/v2/examples/tray-icon/README.md
@@ -0,0 +1,19 @@
+# README
+
+## About
+
+This example tests tray icon behavior and runtime tray updates.
+
+## Running
+
+From `v2/examples/tray-icon`:
+
+```bash
+go run -tags "desktop,production,webkit2_41" .
+```
+
+Or from `v2`:
+
+```bash
+go run -tags "desktop,production,webkit2_41" ./examples/tray-icon
+```
diff --git a/v2/examples/tray-icon/app.go b/v2/examples/tray-icon/app.go
new file mode 100644
index 000000000..b2a2fadab
--- /dev/null
+++ b/v2/examples/tray-icon/app.go
@@ -0,0 +1,16 @@
+package main
+
+import "context"
+
+// App stores runtime context for tray callbacks.
+type App struct {
+ ctx context.Context
+}
+
+func NewApp() *App {
+ return &App{}
+}
+
+func (a *App) startup(ctx context.Context) {
+ a.ctx = ctx
+}
diff --git a/v2/examples/tray-icon/build/README.md b/v2/examples/tray-icon/build/README.md
new file mode 100644
index 000000000..1ae2f677f
--- /dev/null
+++ b/v2/examples/tray-icon/build/README.md
@@ -0,0 +1,35 @@
+# Build Directory
+
+The build directory is used to house all the build files and assets for your application.
+
+The structure is:
+
+* bin - Output directory
+* darwin - macOS specific files
+* windows - Windows specific files
+
+## Mac
+
+The `darwin` directory holds files specific to Mac builds.
+These may be customised and used as part of the build. To return these files to the default state, simply delete them
+and
+build with `wails build`.
+
+The directory contains the following files:
+
+- `Info.plist` - the main plist file used for Mac builds. It is used when building using `wails build`.
+- `Info.dev.plist` - same as the main plist file but used when building using `wails dev`.
+
+## Windows
+
+The `windows` directory contains the manifest and rc files used when building with `wails build`.
+These may be customised for your application. To return these files to the default state, simply delete them and
+build with `wails build`.
+
+- `icon.ico` - The icon used for the application. This is used when building using `wails build`. If you wish to
+ use a different icon, simply replace this file with your own. If it is missing, a new `icon.ico` file
+ will be created using the `appicon.png` file in the build directory.
+- `installer/*` - The files used to create the Windows installer. These are used when building using `wails build`.
+- `info.json` - Application details used for Windows builds. The data here will be used by the Windows installer,
+ as well as the application itself (right click the exe -> properties -> details)
+- `wails.exe.manifest` - The main application manifest file.
\ No newline at end of file
diff --git a/v2/examples/tray-icon/build/appicon.png b/v2/examples/tray-icon/build/appicon.png
new file mode 100644
index 000000000..63617fe4f
Binary files /dev/null and b/v2/examples/tray-icon/build/appicon.png differ
diff --git a/v2/examples/tray-icon/build/darwin/Info.dev.plist b/v2/examples/tray-icon/build/darwin/Info.dev.plist
new file mode 100644
index 000000000..14121ef7c
--- /dev/null
+++ b/v2/examples/tray-icon/build/darwin/Info.dev.plist
@@ -0,0 +1,68 @@
+
+
+
+ CFBundlePackageType
+ APPL
+ CFBundleName
+ {{.Info.ProductName}}
+ CFBundleExecutable
+ {{.OutputFilename}}
+ CFBundleIdentifier
+ com.wails.{{.Name}}
+ CFBundleVersion
+ {{.Info.ProductVersion}}
+ CFBundleGetInfoString
+ {{.Info.Comments}}
+ CFBundleShortVersionString
+ {{.Info.ProductVersion}}
+ CFBundleIconFile
+ iconfile
+ LSMinimumSystemVersion
+ 10.13.0
+ NSHighResolutionCapable
+ true
+ NSHumanReadableCopyright
+ {{.Info.Copyright}}
+ {{if .Info.FileAssociations}}
+ CFBundleDocumentTypes
+
+ {{range .Info.FileAssociations}}
+
+ CFBundleTypeExtensions
+
+ {{.Ext}}
+
+ CFBundleTypeName
+ {{.Name}}
+ CFBundleTypeRole
+ {{.Role}}
+ CFBundleTypeIconFile
+ {{.IconName}}
+
+ {{end}}
+
+ {{end}}
+ {{if .Info.Protocols}}
+ CFBundleURLTypes
+
+ {{range .Info.Protocols}}
+
+ CFBundleURLName
+ com.wails.{{.Scheme}}
+ CFBundleURLSchemes
+
+ {{.Scheme}}
+
+ CFBundleTypeRole
+ {{.Role}}
+
+ {{end}}
+
+ {{end}}
+ NSAppTransportSecurity
+
+ NSAllowsLocalNetworking
+
+
+
+
diff --git a/v2/examples/tray-icon/build/darwin/Info.plist b/v2/examples/tray-icon/build/darwin/Info.plist
new file mode 100644
index 000000000..d17a7475c
--- /dev/null
+++ b/v2/examples/tray-icon/build/darwin/Info.plist
@@ -0,0 +1,63 @@
+
+
+
+ CFBundlePackageType
+ APPL
+ CFBundleName
+ {{.Info.ProductName}}
+ CFBundleExecutable
+ {{.OutputFilename}}
+ CFBundleIdentifier
+ com.wails.{{.Name}}
+ CFBundleVersion
+ {{.Info.ProductVersion}}
+ CFBundleGetInfoString
+ {{.Info.Comments}}
+ CFBundleShortVersionString
+ {{.Info.ProductVersion}}
+ CFBundleIconFile
+ iconfile
+ LSMinimumSystemVersion
+ 10.13.0
+ NSHighResolutionCapable
+ true
+ NSHumanReadableCopyright
+ {{.Info.Copyright}}
+ {{if .Info.FileAssociations}}
+ CFBundleDocumentTypes
+
+ {{range .Info.FileAssociations}}
+
+ CFBundleTypeExtensions
+
+ {{.Ext}}
+
+ CFBundleTypeName
+ {{.Name}}
+ CFBundleTypeRole
+ {{.Role}}
+ CFBundleTypeIconFile
+ {{.IconName}}
+
+ {{end}}
+
+ {{end}}
+ {{if .Info.Protocols}}
+ CFBundleURLTypes
+
+ {{range .Info.Protocols}}
+
+ CFBundleURLName
+ com.wails.{{.Scheme}}
+ CFBundleURLSchemes
+
+ {{.Scheme}}
+
+ CFBundleTypeRole
+ {{.Role}}
+
+ {{end}}
+
+ {{end}}
+
+
diff --git a/v2/examples/tray-icon/build/windows/icon.ico b/v2/examples/tray-icon/build/windows/icon.ico
new file mode 100644
index 000000000..f33479841
Binary files /dev/null and b/v2/examples/tray-icon/build/windows/icon.ico differ
diff --git a/v2/examples/tray-icon/build/windows/info.json b/v2/examples/tray-icon/build/windows/info.json
new file mode 100644
index 000000000..9727946b7
--- /dev/null
+++ b/v2/examples/tray-icon/build/windows/info.json
@@ -0,0 +1,15 @@
+{
+ "fixed": {
+ "file_version": "{{.Info.ProductVersion}}"
+ },
+ "info": {
+ "0000": {
+ "ProductVersion": "{{.Info.ProductVersion}}",
+ "CompanyName": "{{.Info.CompanyName}}",
+ "FileDescription": "{{.Info.ProductName}}",
+ "LegalCopyright": "{{.Info.Copyright}}",
+ "ProductName": "{{.Info.ProductName}}",
+ "Comments": "{{.Info.Comments}}"
+ }
+ }
+}
\ No newline at end of file
diff --git a/v2/examples/tray-icon/build/windows/wails.exe.manifest b/v2/examples/tray-icon/build/windows/wails.exe.manifest
new file mode 100644
index 000000000..17e1a2387
--- /dev/null
+++ b/v2/examples/tray-icon/build/windows/wails.exe.manifest
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+ true/pm
+ permonitorv2,permonitor
+
+
+
\ No newline at end of file
diff --git a/v2/examples/tray-icon/go.mod b/v2/examples/tray-icon/go.mod
new file mode 100644
index 000000000..ef1e76bee
--- /dev/null
+++ b/v2/examples/tray-icon/go.mod
@@ -0,0 +1,37 @@
+module tray-icon
+
+go 1.23
+
+require github.com/wailsapp/wails/v2 v2.11.0
+
+require (
+ github.com/bep/debounce v1.2.1 // indirect
+ github.com/go-ole/go-ole v1.3.0 // indirect
+ github.com/godbus/dbus/v5 v5.1.0 // indirect
+ github.com/google/uuid v1.6.0 // indirect
+ github.com/gorilla/websocket v1.5.3 // indirect
+ github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
+ github.com/labstack/echo/v4 v4.13.3 // indirect
+ github.com/labstack/gommon v0.4.2 // indirect
+ github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
+ github.com/leaanthony/gosod v1.0.4 // indirect
+ github.com/leaanthony/slicer v1.6.0 // indirect
+ github.com/leaanthony/u v1.1.1 // indirect
+ github.com/mattn/go-colorable v0.1.13 // indirect
+ github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
+ github.com/pkg/errors v0.9.1 // indirect
+ github.com/rivo/uniseg v0.4.7 // indirect
+ github.com/samber/lo v1.49.1 // indirect
+ github.com/tkrajina/go-reflector v0.5.8 // indirect
+ github.com/valyala/bytebufferpool v1.0.0 // indirect
+ github.com/valyala/fasttemplate v1.2.2 // indirect
+ github.com/wailsapp/go-webview2 v1.0.22 // indirect
+ github.com/wailsapp/mimetype v1.4.1 // indirect
+ golang.org/x/crypto v0.33.0 // indirect
+ golang.org/x/net v0.35.0 // indirect
+ golang.org/x/sys v0.30.0 // indirect
+ golang.org/x/text v0.22.0 // indirect
+)
+
+replace github.com/wailsapp/wails/v2 => ../../
diff --git a/v2/examples/tray-icon/go.sum b/v2/examples/tray-icon/go.sum
new file mode 100644
index 000000000..10d4a9b18
--- /dev/null
+++ b/v2/examples/tray-icon/go.sum
@@ -0,0 +1,79 @@
+github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
+github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
+github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
+github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
+github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
+github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
+github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
+github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
+github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
+github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
+github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
+github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
+github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
+github.com/leaanthony/go-ansi-parser v1.6.1 h1:xd8bzARK3dErqkPFtoF9F3/HgN8UQk0ed1YDKpEz01A=
+github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
+github.com/leaanthony/gosod v1.0.4 h1:YLAbVyd591MRffDgxUOU1NwLhT9T1/YiwjKZpkNFeaI=
+github.com/leaanthony/gosod v1.0.4/go.mod h1:GKuIL0zzPj3O1SdWQOdgURSuhkF+Urizzxh26t9f1cw=
+github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
+github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
+github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
+github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
+github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
+github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
+github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
+github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
+github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
+github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
+github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
+github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
+github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
+github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
+github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
+github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
+github.com/wailsapp/go-webview2 v1.0.22 h1:YT61F5lj+GGaat5OB96Aa3b4QA+mybD0Ggq6NZijQ58=
+github.com/wailsapp/go-webview2 v1.0.22/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
+github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
+github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
+golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
+golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
+golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
+golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
+golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
+golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
+golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/v2/examples/tray-icon/main.go b/v2/examples/tray-icon/main.go
new file mode 100644
index 000000000..c1ee430e6
--- /dev/null
+++ b/v2/examples/tray-icon/main.go
@@ -0,0 +1,158 @@
+package main
+
+import (
+ "context"
+ "embed"
+ "fmt"
+ "os"
+ "path/filepath"
+ "sync"
+ "time"
+
+ "github.com/wailsapp/wails/v2"
+ "github.com/wailsapp/wails/v2/pkg/menu"
+ "github.com/wailsapp/wails/v2/pkg/options"
+ "github.com/wailsapp/wails/v2/pkg/options/assetserver"
+ "github.com/wailsapp/wails/v2/pkg/runtime"
+)
+
+//go:embed all:frontend/dist
+var assets embed.FS
+
+func resolveTrayIconPath() string {
+ return resolveTrayAssetPath("tray-icon.png")
+}
+
+func resolveTrayAssetPath(filename string) string {
+ candidates := []string{
+ filepath.Join("examples", "tray-icon", "trayicons", filename),
+ filepath.Join("trayicons", filename),
+ }
+
+ for _, p := range candidates {
+ if _, err := os.Stat(p); err == nil {
+ if abs, err := filepath.Abs(p); err == nil {
+ return abs
+ }
+ return p
+ }
+ }
+
+ return candidates[0]
+}
+
+func main() {
+ app := NewApp()
+ primaryIcon := resolveTrayIconPath()
+ altIcon := resolveTrayAssetPath("tray-icon-alt.png")
+
+ state := struct {
+ mu sync.Mutex
+ mode int
+ clicks int
+ updates int
+ }{}
+
+ var buildTray func() *menu.TrayMenu
+ buildTray = func() *menu.TrayMenu {
+ state.mu.Lock()
+ mode := state.mode
+ clicks := state.clicks
+ updates := state.updates
+ state.mu.Unlock()
+
+ icon := primaryIcon
+ label := "TrayIcon-A"
+ actionText := "Primary Action: switch to B"
+ actionLog := "action A"
+ if mode == 1 {
+ icon = altIcon
+ label = "TrayIcon-B"
+ actionText = "Primary Action: switch to A"
+ actionLog = "action B"
+ }
+
+ trayMenu := menu.NewMenu()
+
+ trayMenu.AddText("Show", nil, func(_ *menu.CallbackData) {
+ runtime.Show(app.ctx)
+ })
+ trayMenu.AddText(actionText, nil, func(_ *menu.CallbackData) {
+ state.mu.Lock()
+ state.mode = 1 - state.mode
+ state.clicks++
+ state.updates++
+ currentClicks := state.clicks
+ state.mu.Unlock()
+
+ fmt.Printf("[tray-test] %s clicked (clicks=%d)\n", actionLog, currentClicks)
+ runtime.TraySetSystemTray(app.ctx, buildTray())
+ })
+
+ trayMenu.AddText("Ping", nil, func(_ *menu.CallbackData) {
+ fmt.Println("[tray-test] Ping clicked")
+ })
+
+ trayMenu.AddText("Toggle icon + text now", nil, func(_ *menu.CallbackData) {
+ state.mu.Lock()
+ state.mode = 1 - state.mode
+ state.clicks++
+ state.updates++
+ currentClicks := state.clicks
+ state.mu.Unlock()
+
+ fmt.Printf("[tray-test] manual toggle clicked (clicks=%d)\n", currentClicks)
+ runtime.TraySetSystemTray(app.ctx, buildTray())
+ })
+
+ trayMenu.AddSeparator()
+ trayMenu.AddText("Quit", nil, func(_ *menu.CallbackData) {
+ runtime.Quit(app.ctx)
+ })
+
+ return &menu.TrayMenu{
+ Label: fmt.Sprintf("%s (%d)", label, updates),
+ Tooltip: fmt.Sprintf("Mode=%s, Clicks=%d", label, clicks),
+ Image: icon,
+ Menu: trayMenu,
+ }
+ }
+
+ onStartup := func(ctx context.Context) {
+ app.startup(ctx)
+
+ go func() {
+ time.Sleep(4 * time.Second)
+ state.mu.Lock()
+ state.mode = 1 - state.mode
+ state.updates++
+ state.mu.Unlock()
+ fmt.Println("[tray-test] timed update: 4s")
+ runtime.TraySetSystemTray(app.ctx, buildTray())
+
+ time.Sleep(4 * time.Second)
+ state.mu.Lock()
+ state.mode = 1 - state.mode
+ state.updates++
+ state.mu.Unlock()
+ fmt.Println("[tray-test] timed update: 8s")
+ runtime.TraySetSystemTray(app.ctx, buildTray())
+ }()
+ }
+
+ err := wails.Run(&options.App{
+ Title: "Wails Tray Icon Test",
+ Width: 720,
+ Height: 420,
+ AssetServer: &assetserver.Options{
+ Assets: assets,
+ },
+ OnStartup: onStartup,
+ Tray: buildTray(),
+ HideWindowOnClose: true,
+ })
+
+ if err != nil {
+ fmt.Println("[tray-test] Error:", err)
+ }
+}
diff --git a/v2/examples/tray-icon/trayicons/tray-icon-alt.png b/v2/examples/tray-icon/trayicons/tray-icon-alt.png
new file mode 100644
index 000000000..351f81caa
Binary files /dev/null and b/v2/examples/tray-icon/trayicons/tray-icon-alt.png differ
diff --git a/v2/examples/tray-icon/trayicons/tray-icon-alt.svg b/v2/examples/tray-icon/trayicons/tray-icon-alt.svg
new file mode 100644
index 000000000..11b523720
--- /dev/null
+++ b/v2/examples/tray-icon/trayicons/tray-icon-alt.svg
@@ -0,0 +1,13 @@
+
diff --git a/v2/examples/tray-icon/trayicons/tray-icon.png b/v2/examples/tray-icon/trayicons/tray-icon.png
new file mode 100644
index 000000000..925b9edbf
Binary files /dev/null and b/v2/examples/tray-icon/trayicons/tray-icon.png differ
diff --git a/v2/examples/tray-icon/trayicons/tray-icon.svg b/v2/examples/tray-icon/trayicons/tray-icon.svg
new file mode 100644
index 000000000..cd7c7e523
--- /dev/null
+++ b/v2/examples/tray-icon/trayicons/tray-icon.svg
@@ -0,0 +1,12 @@
+
diff --git a/v2/examples/tray-icon/wails.json b/v2/examples/tray-icon/wails.json
new file mode 100644
index 000000000..eaf05bcba
--- /dev/null
+++ b/v2/examples/tray-icon/wails.json
@@ -0,0 +1,5 @@
+{
+ "$schema": "https://wails.io/schemas/config.v2.json",
+ "name": "tray-icon",
+ "outputfilename": "tray-icon"
+}