mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
* feat: choose payment method when opening first channel (WIP) * chore: update terms * chore: consume lsp endpoint, display fees+LSP in manual channel flow, first channel ui improvements * chore: improve handling of fee_credits payment method * chore: add terms and description * feat: add terms to manual increase incoming capacity flow * chore: add error handling for get_info endpoint * feat: allow alby account to pay for manual channel order * chore: use consistent logging methods * chore: rename lsp balance sats field to be consistent * chore: update to use consistent field name for public key in auto channel request * chore: rename channel suggestion url and type fields * feat: support included payment method * chore: update LDK startup peers * chore: move non-oauth methods out of alby oauth service * chore: improve terms around duration, only display duration in terms modal
126 lines
3.3 KiB
Go
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.GetAlbySvc(), 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. Channels may be closed if your hub stays offline for an extended period of time.",
|
|
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)
|
|
}
|