alby-hub/wails/wails_app.go
Roland 3e1d16d423
Feat: NWA auth for self-hosted hubs (#1016)
* feat: nwc create_connection command (WIP)

* feat: allow creating superuser apps from the ui

* fix: pass methods rather than scopes in create_connection method

* chore: add extra tests

* fix: use browser router in http mode

* fix: update links to not use hash router

* fix: add redirect from hash router url

* fix: return nostrWalletConnectUrl in nwc connection success event and message

* feat: publish nwa event

* chore: use nwc info event instead of nwa event

* feat: create custom alby go detail page

* chore: allow creating/editing apps with the same name

* fix: convert budget from msats to sats (#1111)

* chore: address NWA feedback

* chore: address feedback

- adjust button copy
- make create_connection methods consistent with http deeplink flow
- remove unused constant
- add empty string check before adding lud16 tag
- fix test

* feat: add support for notification_types in create_connection method

* fix: shorter button copy

* fix: do not include lud16 tag in published info event

* Feat: add lud16 to get_info response (#1128)

feat: add lud16 to get_info response

* chore: minor alby go screen improvements

* fix: incorrect unlock password error message to create app with superuser access

* chore: minor ui improvements on alby go detail page

* chore: avoid duplicate app names by adding a suffix

* chore: move scopes check to apps service, add new tests, DRY controller test setup

* fix: scopes component full access scopes and isolated scope group check

* fix: use supported capabilities for Alby Go

* fix: return correct app name

* chore: address minor comments

---------

Co-authored-by: im-adithya <imadithyavardhan@gmail.com>
2025-02-27 19:12:55 +07:00

126 lines
3.3 KiB
Go

package wails
import (
"context"
"embed"
"github.com/getAlby/hub/api"
"github.com/getAlby/hub/apps"
"github.com/getAlby/hub/logger"
"github.com/getAlby/hub/service"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/runtime"
"gorm.io/gorm"
)
type WailsApp struct {
ctx context.Context
svc service.Service
api api.API
db *gorm.DB
appsSvc apps.AppsService
}
func NewApp(svc service.Service) *WailsApp {
return &WailsApp{
svc: svc,
api: api.NewAPI(svc, svc.GetDB(), svc.GetConfig(), svc.GetKeys(), svc.GetAlbyOAuthSvc(), svc.GetEventPublisher()),
db: svc.GetDB(),
appsSvc: apps.NewAppsService(svc.GetDB(), svc.GetEventPublisher(), svc.GetKeys(), svc.GetConfig()),
}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (app *WailsApp) startup(ctx context.Context) {
app.ctx = ctx
}
func (app *WailsApp) onBeforeClose(ctx context.Context) bool {
response, err := runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Confirm Exit",
Message: "Are you sure you want to shut down Alby Hub? Alby Hub needs to stay online to send and receive transactions.",
Buttons: []string{"Yes", "No"},
DefaultButton: "No",
})
if err != nil {
logger.Logger.WithError(err).Error("failed to show confirmation dialog")
return false
}
return response != "Yes"
}
func LaunchWailsApp(app *WailsApp, assets embed.FS, appIcon []byte) {
err := wails.Run(&options.App{
Title: "Alby Hub",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{
Assets: assets,
},
Logger: NewWailsLogger(),
// HideWindowOnClose: true, // with this on, there is no way to close the app - wait for v3
//BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
OnBeforeClose: func(ctx context.Context) bool {
return app.onBeforeClose(ctx)
},
Bind: []interface{}{
app,
},
Mac: &mac.Options{
About: &mac.AboutInfo{
Title: "Alby Hub",
Icon: appIcon,
},
},
Linux: &linux.Options{
Icon: appIcon,
},
})
if err != nil {
logger.Logger.WithError(err).Error("failed to run Wails app")
}
}
func NewWailsLogger() WailsLogger {
return WailsLogger{}
}
type WailsLogger struct {
}
func (wailsLogger WailsLogger) Print(message string) {
logger.Logger.WithField("wails", true).Print(message)
}
func (wailsLogger WailsLogger) Trace(message string) {
logger.Logger.WithField("wails", true).Trace(message)
}
func (wailsLogger WailsLogger) Debug(message string) {
logger.Logger.WithField("wails", true).Debug(message)
}
func (wailsLogger WailsLogger) Info(message string) {
logger.Logger.WithField("wails", true).Info(message)
}
func (wailsLogger WailsLogger) Warning(message string) {
logger.Logger.WithField("wails", true).Warning(message)
}
func (wailsLogger WailsLogger) Error(message string) {
logger.Logger.WithField("wails", true).Error(message)
}
func (wailsLogger WailsLogger) Fatal(message string) {
logger.Logger.WithField("wails", true).Fatal(message)
}