menus and windows

This commit is contained in:
sawka 2024-05-16 14:00:39 -07:00
parent b721f59166
commit cc4629f9e0
2 changed files with 47 additions and 11 deletions

51
main.go
View File

@ -16,6 +16,7 @@ import (
"github.com/wavetermdev/thenextwave/pkg/wavebase" "github.com/wavetermdev/thenextwave/pkg/wavebase"
"github.com/wailsapp/wails/v3/pkg/application" "github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
) )
//go:embed dist //go:embed dist
@ -24,6 +25,42 @@ var assets embed.FS
//go:embed build/appicon.png //go:embed build/appicon.png
var appIcon []byte var appIcon []byte
func createAppMenu(app *application.App) *application.Menu {
menu := application.NewMenu()
menu.AddRole(application.AppMenu)
fileMenu := menu.AddSubmenu("File")
newWindow := fileMenu.Add("New Window")
newWindow.OnClick(func(appContext *application.Context) {
createWindow(app)
})
closeWindow := fileMenu.Add("Close Window")
closeWindow.OnClick(func(appContext *application.Context) {
app.CurrentWindow().Close()
})
menu.AddRole(application.EditMenu)
menu.AddRole(application.ViewMenu)
menu.AddRole(application.WindowMenu)
menu.AddRole(application.HelpMenu)
return menu
}
func createWindow(app *application.App) {
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Title: "Wave Terminal",
Mac: application.MacWindow{
InvisibleTitleBarHeight: 50,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(27, 38, 54),
URL: "/public/index.html",
})
eventbus.RegisterWailsWindow(window)
window.On(events.Common.WindowClosing, func(event *application.WindowEvent) {
eventbus.UnregisterWailsWindow(window.ID())
})
}
func main() { func main() {
err := wavebase.EnsureWaveHomeDir() err := wavebase.EnsureWaveHomeDir()
if err != nil { if err != nil {
@ -52,19 +89,11 @@ func main() {
ApplicationShouldTerminateAfterLastWindowClosed: true, ApplicationShouldTerminateAfterLastWindowClosed: true,
}, },
}) })
menu := createAppMenu(app)
app.SetMenu(menu)
eventbus.RegisterWailsApp(app) eventbus.RegisterWailsApp(app)
window := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ createWindow(app)
Title: "Wave Terminal",
Mac: application.MacWindow{
InvisibleTitleBarHeight: 50,
Backdrop: application.MacBackdropTranslucent,
TitleBar: application.MacTitleBarHiddenInset,
},
BackgroundColour: application.NewRGB(27, 38, 54),
URL: "/public/index.html",
})
eventbus.RegisterWailsWindow(window)
eventbus.Start() eventbus.Start()
defer eventbus.Shutdown() defer eventbus.Shutdown()

View File

@ -115,6 +115,7 @@ func CloseBlock(blockId string) {
} }
bc.Close() bc.Close()
close(bc.InputCh) close(bc.InputCh)
removeBlockData(blockId)
} }
func GetBlockData(blockId string) *BlockData { func GetBlockData(blockId string) *BlockData {
@ -129,6 +130,12 @@ func setBlockData(bd *BlockData) {
blockDataMap[bd.BlockId] = bd blockDataMap[bd.BlockId] = bd
} }
func removeBlockData(blockId string) {
globalLock.Lock()
defer globalLock.Unlock()
delete(blockDataMap, blockId)
}
func (bc *BlockController) setShellProc(shellProc *shellexec.ShellProc) error { func (bc *BlockController) setShellProc(shellProc *shellexec.ShellProc) error {
bc.Lock.Lock() bc.Lock.Lock()
defer bc.Lock.Unlock() defer bc.Lock.Unlock()