Skip to content

Commit 07386ce

Browse files
committed
Run Baš Čelik in background using system tray
1 parent e504af4 commit 07386ce

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

embed/translation/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"preference.language": "Language",
9494
"preference.placeholder.modulePath": "Enter module path",
9595
"preference.placeholder.directoryPath": "Enter directory path",
96+
"preference.runInBackground": "Run in background also",
9697
"preference.save": "Save",
9798
"preference.saved": "Preferences saved",
9899
"preference.smartboxMode": "Smartbox mode",
@@ -174,5 +175,6 @@
174175
"pinChange.error": "Error occurred. Don't try to change PIN with Baš Čelik anymore.",
175176
"pinChange.triesLeft": "Tries left: %d.",
176177
"smartbox.error": "Error occurred while starting Smartbox server.",
177-
"smartbox.running": "Smartbox server is running."
178+
"smartbox.running": "Smartbox server is running.",
179+
"tray.show": "Show"
178180
}

embed/translation/sr-cyrillic.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"preference.language": "Језик",
9494
"preference.placeholder.modulePath": "Унеси путању до модула",
9595
"preference.placeholder.directoryPath": "Унеси путању директоријума",
96+
"preference.runInBackground": "Покрени и у позадини",
9697
"preference.save": "Сачувај",
9798
"preference.saved": "Подешавања сачувана",
9899
"preference.smartboxMode": "Smartbox режим",
@@ -174,5 +175,6 @@
174175
"pinChange.error": "Дошло је до грешке. Не покушавајте више да промените PIN са Баш Челиком.",
175176
"pinChange.triesLeft": "Преостало покушаја: %d.",
176177
"smartbox.error": "Грешка при покретању сервера",
177-
"smartbox.running": "Smartbox сервер је покренут"
178+
"smartbox.running": "Smartbox сервер је покренут",
179+
"tray.show": "Otvori"
178180
}

embed/translation/sr-latin.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"preference.language": "Jezik",
9494
"preference.placeholder.modulePath": "Unesi putanju do modula",
9595
"preference.placeholder.directoryPath": "Unesi putanju direktorijuma",
96+
"preference.runInBackground": "Pokreni i u pozadini",
9697
"preference.save": "Sačuvaj",
9798
"preference.saved": "Podešavanja sačuvana",
9899
"preference.smartboxMode": "Smartbox režim",
@@ -174,5 +175,6 @@
174175
"pinChange.error": "Došlo je do greške. Ne pokušavajte više da promenite PIN sa Baš Čelikom.",
175176
"pinChange.triesLeft": "Preostalo pokušaja: %d.",
176177
"smartbox.error": "Greška pri pokretanju servera",
177-
"smartbox.running": "Smartbox server jе pokrenut"
178+
"smartbox.running": "Smartbox server jе pokrenut",
179+
"tray.show": "Otvori"
178180
}

internal/gui/poller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func tryToProcessCard(sCard *scard.Card) bool {
8181

8282
go autoSave(doc)
8383

84+
showWindowFromTray()
85+
8486
switch cardDoc.(type) {
8587
case *card.Gemalto:
8688
state.mu.Lock()
@@ -91,6 +93,13 @@ func tryToProcessCard(sCard *scard.Card) bool {
9193
return loaded
9294
}
9395

96+
func showWindowFromTray() {
97+
if state.runInBackground && state.autoSaveMode != AutoSaveSaveAndOpen {
98+
state.window.Show()
99+
state.window.RequestFocus()
100+
}
101+
}
102+
94103
func initCardAndReadDoc(cardDoc card.CardDocument) (document.Document, error) {
95104
err := cardDoc.InitCard()
96105
if err != nil {

internal/gui/preferences.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const languagePreferenceKey = "language"
1818
const autoSavePdfKey = "auto-save-pdf"
1919
const autoSaveLocationKey = "auto-save-location"
2020

21+
const runInBackgroundKey = "run-in-background"
22+
2123
const lastUsedDirectoryKey = "last-used-directory"
2224

2325
const smartboxModeKey = "smartbox-mode"
@@ -56,6 +58,10 @@ func showSetupBox() func() {
5658
autoSaveLocationEntry.SetText(autoSaveLocation)
5759
autoSaveLocationEntry.SetPlaceHolder(t("preference.placeholder.directoryPath"))
5860

61+
runInBackground := preferences.BoolWithFallback(runInBackgroundKey, false)
62+
runInBackgroundCheck := widget.NewCheck("", func(b bool) {})
63+
runInBackgroundCheck.SetChecked(runInBackground)
64+
5965
mupPkcsEntry := widget.NewEntry()
6066
mupPkcsEntry.SetText(preferences.String(mupPkcsPathKey))
6167
mupPkcsEntry.SetPlaceHolder(t("preference.placeholder.modulePath"))
@@ -115,6 +121,8 @@ func showSetupBox() func() {
115121
{Text: t("preference.language"), Widget: languageSelect},
116122
{Text: t("preference.autoSave"), Widget: autoSavePdfSelect},
117123
{Text: t("preference.autoSaveLocation"), Widget: autoSaveLocationEntry},
124+
{Text: t("preference.runInBackground"), Widget: runInBackgroundCheck},
125+
{Text: "", Widget: &widgets.Spacer{}},
118126
{Text: t("preference.smartboxMode"), Widget: smartboxModeCheck},
119127
{Text: "MUP", Widget: mupPkcsEntry},
120128
{Text: "PKS", Widget: pksPkcsEntry},
@@ -129,6 +137,7 @@ func showSetupBox() func() {
129137
preferences.SetInt(languagePreferenceKey, languageSelect.SelectedIndex())
130138
preferences.SetInt(autoSavePdfKey, autoSavePdfSelect.SelectedIndex())
131139
preferences.SetString(autoSaveLocationKey, autoSaveLocationEntry.Text)
140+
preferences.SetBool(runInBackgroundKey, runInBackgroundCheck.Checked)
132141
preferences.SetBool(smartboxModeKey, smartboxModeCheck.Checked)
133142
preferences.SetString(mupPkcsPathKey, mupPkcsEntry.Text)
134143
preferences.SetString(pksPkcsPathKey, pksPkcsEntry.Text)

internal/gui/ui.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fyne.io/fyne/v2"
88
"fyne.io/fyne/v2/app"
99
"fyne.io/fyne/v2/container"
10+
"fyne.io/fyne/v2/driver/desktop"
1011
"fyne.io/fyne/v2/layout"
1112
"fyne.io/fyne/v2/widget"
1213
"github.com/ubavic/bas-celik/v2/card"
@@ -34,6 +35,7 @@ type State struct {
3435
certsSelectorButtons []*widget.Button
3536
autoSaveMode AutoSaveMode
3637
autoSaveLocation string
38+
runInBackground bool
3739
}
3840

3941
var state State
@@ -60,6 +62,8 @@ func StartGui(version string) {
6062
mainContainer := container.New(layout.NewPaddedLayout())
6163
win.SetContent(mainContainer)
6264

65+
runInBackground := preferences.BoolWithFallback(runInBackgroundKey, false)
66+
6367
state = State{
6468
app: app,
6569
window: win,
@@ -71,6 +75,7 @@ func StartGui(version string) {
7175
statusBar: statusBar,
7276
autoSaveMode: AutoSaveMode(preferences.Int(autoSavePdfKey)),
7377
autoSaveLocation: preferences.String(autoSaveLocationKey),
78+
runInBackground: runInBackground,
7479
}
7580

7681
smartboxMode := preferences.BoolWithFallback(smartboxModeKey, false)
@@ -81,9 +86,30 @@ func StartGui(version string) {
8186
toolbar := widgets.NewToolbar(showAboutBox, showSettings, !smartboxMode)
8287
state.toolbar = toolbar
8388

89+
if runInBackground {
90+
setupTray()
91+
}
92+
8493
if smartboxMode {
8594
startSmartboxUI()
8695
} else {
8796
startCardReaderUI()
8897
}
8998
}
99+
100+
func setupTray() {
101+
desk, ok := state.app.(desktop.App)
102+
if !ok {
103+
return
104+
}
105+
106+
m := fyne.NewMenu("Baš Čelik",
107+
fyne.NewMenuItem(t("tray.show"), func() {
108+
state.window.Show()
109+
}))
110+
desk.SetSystemTrayMenu(m)
111+
112+
state.window.SetCloseIntercept(func() {
113+
state.window.Hide()
114+
})
115+
}

0 commit comments

Comments
 (0)