Skip to content

Commit

Permalink
toolbar added.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Nov 16, 2024
1 parent 532f80a commit 2df504d
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:

build:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

Expand Down
1 change: 1 addition & 0 deletions core/icon/account_balance_wallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/key.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/login.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/logout.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/percent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/person_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/person_remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/icon/price_change.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions core/res.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package core

import (
_ "embed"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)

//go:embed icon/login.svg
var loginRes []byte

//go:embed icon/logout.svg
var logoutRes []byte

//go:embed icon/person_add.svg
var useraddRes []byte

//go:embed icon/person_remove.svg
var userdelRes []byte

//go:embed icon/account_balance_wallet.svg
var walletRes []byte

//go:embed icon/percent.svg
var percentRes []byte

//go:embed icon/key.svg
var accessRes []byte

//go:embed icon/price_change.svg
var bankRes []byte

var loginIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "login",
StaticContent: loginRes,
})

var logoutIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "logout",
StaticContent: logoutRes,
})

var useraddIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "useradd",
StaticContent: useraddRes,
})

var userdelIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "userdel",
StaticContent: userdelRes,
})

var walletIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "wallet",
StaticContent: walletRes,
})

var percentIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "mrtp",
StaticContent: percentRes,
})

var accessIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "access",
StaticContent: accessRes,
})

var bankIconRes = theme.NewThemedResource(&fyne.StaticResource{
StaticName: "bank",
StaticContent: bankRes,
})
143 changes: 17 additions & 126 deletions core/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package core
import (
"fmt"
"log"
"strconv"
"time"

"fyne.io/fyne/v2"
Expand All @@ -13,37 +12,6 @@ import (
cfg "github.com/slotopol/balance/config"
)

var Foreground bool

var (
admwnd = widget.NewLabel("not logined yet")
clubtabs = &container.AppTabs{}
userlist *widget.Table
curcid uint64
cural AL
)

var colhdr = []string{
"email", "wallet", "MRTP", "access",
}

func RefreshContent() {
var err error

userlist.Refresh()

var label = clubtabs.Selected().Content.(*widget.Label)
var bank, fund, deposit = "N/A", "N/A", "N/A"
if cural&ALclub != 0 {
var info RetClubInfo
if info, err = ApiClubInfo(curcid); err != nil {
return
}
bank, fund, deposit = fmt.Sprintf("%.2f", info.Bank), fmt.Sprintf("%.2f", info.Fund), fmt.Sprintf("%.2f", info.Lock)
}
label.SetText(fmt.Sprintf("bank: %s, jackpot fund: %s, deposit: %s", bank, fund, deposit))
}

func MakeSignIn() (err error) {
if err = cfg.ReadCredentials(); err != nil {
log.Printf("failure on reading credentials, using default: %s\n", err.Error())
Expand All @@ -53,7 +21,7 @@ func MakeSignIn() (err error) {
if admin, err = ApiSignIn(cfg.Credentials.Email, cfg.Credentials.Secret); err != nil {
return
}
admwnd.SetText(fmt.Sprintf("logined as '%s'", cfg.Credentials.Email))
loginTxt.SetText(fmt.Sprintf(cfg.Credentials.Email))
log.Printf("signed as '%s'", cfg.Credentials.Email)
return
}
Expand Down Expand Up @@ -109,18 +77,20 @@ func MakeUserList() (err error) {
user.props = map[uint64]Props{} // make new empty map
Users[email] = user
}
go func() {
var c = time.Tick(Cfg.PropUpdateTick)
for range c {
if Foreground {
RefreshContent()
}
}
}()
go RefreshLoop()
log.Printf("users list ready, %d users", len(Users))
return
}

func RefreshLoop() {
var c = time.Tick(Cfg.PropUpdateTick)
for range c {
if Foreground {
RefreshContent()
}
}
}

func WaitToken() (err error) {
for {
var t time.Time
Expand Down Expand Up @@ -149,97 +119,18 @@ func StartupChain() {
}
}

func Lifecycle(a fyne.App) {
var l = a.Lifecycle()
l.SetOnStarted(func() {
log.Println("lifecycle: started")
})
l.SetOnStopped(func() {
log.Println("lifecycle: stopped")
})
l.SetOnEnteredForeground(func() {
Foreground = true
log.Println("lifecycle: entered foreground")
})
l.SetOnExitedForeground(func() {
Foreground = false
log.Println("lifecycle: exited foreground")
})
}

func CreateMainWindow(a fyne.App) fyne.Window {
var w = a.NewWindow("Balance")

userlist = widget.NewTableWithHeaders(
func() (int, int) { return len(cfg.UserList), 4 },
func() fyne.CanvasObject {
var label = widget.NewLabel("")
label.Truncation = fyne.TextTruncateClip
return label
},
func(id widget.TableCellID, cell fyne.CanvasObject) {
var err error

var label = cell.(*widget.Label)
var user, ok = Users[cfg.UserList[id.Row]]
if !ok {
label.SetText("error")
return
}
if id.Col == 0 { // email
label.SetText(cfg.UserList[id.Row])
return
}
if cural&ALuser == 0 {
label.SetText("N/A")
return
}
var prop Props
if prop, err = GetProp(curcid, &user); err != nil {
label.SetText("error")
return
}
switch id.Col {
case 1: // wallet
label.SetText(fmt.Sprintf("%.2f", prop.Wallet))
case 2: // mtrp
if prop.MRTP > 0 {
label.SetText(fmt.Sprintf("%g%%", prop.MRTP))
} else {
label.SetText("-")
}
case 3: // access
label.SetText(FormatAL(prop.Access))
}
})
w.SetContent(mainPage)
go StartupChain()
go WaitToken()

userlist.SetColumnWidth(0, 180) // email
userlist.SetColumnWidth(1, 100) // wallet
userlist.SetColumnWidth(2, 50) // mtrp
userlist.SetColumnWidth(3, 150) // access
userlist.UpdateHeader = func(id widget.TableCellID, cell fyne.CanvasObject) {
var label = cell.(*widget.Label)
if id.Row < 0 {
label.SetText(colhdr[id.Col])
} else if id.Col < 0 {
var user, ok = Users[cfg.UserList[id.Row]]
if !ok {
label.SetText("error")
return
}
label.SetText(strconv.Itoa(int(user.UID)))
} else {
label.SetText("")
}
}

var frame = container.NewBorder(
container.NewVBox(admwnd, clubtabs),
nil, nil, nil,
userlist)
w.SetContent(frame)
go StartupChain()
go WaitToken()

w.Resize(fyne.NewSize(540, 720))
userlist.ExtendBaseWidget(userlist)
w.Resize(fyne.NewSize(540, 640))
return w
}
Loading

0 comments on commit 2df504d

Please sign in to comment.