Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/massastation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime"

"github.com/massalabs/station/int/api"
"github.com/massalabs/station/int/config"
Expand Down Expand Up @@ -105,5 +106,14 @@ func main() {
utils.OpenURL(&stationGUI, fmt.Sprintf("https://%s", config.MassaStationURL))
})

if runtime.GOOS == "darwin" {
stationGUI.Lifecycle().SetOnEnteredForeground(func() {
fmt.Println(">>>>>>>YOOYO>>>>>>MassaStation is in the foreground")
logger.Debugf(">>>>>>>>>>>>>Dock icon clicked211111112")

utils.OpenURL(&stationGUI, fmt.Sprintf("https://%s", config.MassaStationURL))
})
}

stationGUI.Run()
}
70 changes: 69 additions & 1 deletion int/systray/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package systray

import (
"fmt"
"os/exec"

"fyne.io/fyne/v2"
//nolint:goimports,nolintlint
Expand All @@ -17,6 +18,8 @@ func MakeGUI() (fyne.App, *fyne.Menu) {
stationGUI := app.New()
menu := fyne.NewMenu("MassaStation")

msURL := fmt.Sprintf("https://%s", config.MassaStationURL)

if desk, ok := stationGUI.(desktop.App); ok {
icon := fyne.NewStaticResource("logo", embedded.Logo)
titleMenu := fyne.NewMenuItem("MassaStation", nil)
Expand All @@ -32,7 +35,7 @@ func MakeGUI() (fyne.App, *fyne.Menu) {
}

homeShortCutMenu.Action = func() {
utils.OpenURL(&stationGUI, fmt.Sprintf("https://%s", config.MassaStationURL))
utils.OpenURL(&stationGUI, msURL)
}

menu.Items = append(menu.Items,
Expand All @@ -46,5 +49,70 @@ func MakeGUI() (fyne.App, *fyne.Menu) {
desk.SetSystemTrayMenu(menu)
}

// Set up macOS dock click handler
// if runtime.GOOS == "darwin" {

// fmt.Println(">>>>>>>>>>>>>MassaStation is running on macOS")
// stationGUI.Lifecycle().SetOnEnteredForeground(func() {
// fmt.Println(">>>>>>>>>>>>>MassaStation is in the foreground")
// logger.Debugf(">>>>>>>>>>>>>Dock icon clicked211111112")

// openURL(msURL)
// utils.OpenURL(&stationGUI, msURL)
// })
// go handleMacDockClick()
// }

stationGUI.Run()
return stationGUI, menu
}

func openURL(url string) {
cmd := exec.Command("open", url)

if err := cmd.Start(); err != nil {
println("Error opening URL:", err.Error())
}
}

// 🖥 macOS: Detect Dock icon click
// func handleMacDockClick() {

// macos.RunApp(func(app appkit.Application, delegate *appkit.ApplicationDelegate) {
// // app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
// // app.ActivateIgnoringOtherApps(true)

// // Set the delegate to handle the application lifecycle
// delegate.SetApplicationShouldHandleReopenHasVisibleWindows(func(app appkit.Application, _ bool) bool {
// // Handle the Dock icon click
// // This is where you can open the URL or perform any action
// // openURL("https://example.com")
// fmt.Println(">>>>SetApplicationShouldHandleReopenHasVisibleWindows><YOOO Dock icon clicked")
// logger.Debugf(">>>>>>>>>>>>>Dock icon clicked")
// openURL("https://www.google.com")
// return true
// })

// delegate.SetApplicationDidBecomeActive(func(notification foundation.Notification) {
// logger.Debugf("Dock icon clicked222")

// fmt.Println(">>>>>SetApplicationDidBecomeActive<YOOO Dock icon clicked")
// openURL("https://www.google.com")
// })

// // Set the delegate to handle the application lifecycle
// // app.SetDelegate(delegate)

// })

// //ApplicationOpenURLs/

// // cocoa.NSApp_WithDidLaunch(func(n objc.Object) {
// // cocoa.NSApp_SetDelegate(cocoa.AppDelegate{
// // ApplicationShouldHandleReopen: func(_ objc.Object, _ bool) bool {
// // openURL("https://example.com")
// // return true
// // },
// // })
// // }).Run()
// }
Loading