@@ -2,6 +2,7 @@ package backend
22
33import (
44 "context"
5+ "fmt"
56 "os"
67 "strings"
78 "time"
@@ -11,27 +12,34 @@ import (
1112)
1213
1314const (
14- Version = "1.0.0 "
15- Name = "Safelock"
16- statusUpdateKey = "status_update"
17- statusEndKey = "status_end"
18- openedSlaKey = "opened_sla_file"
19- kindEncrypt = "encrypt"
20- kindDecrypt = "decrypt"
15+ Version = "1.0.1 "
16+ Name = "Safelock"
17+ statusUpdateKey = "status_update"
18+ statusEndKey = "status_end"
19+ openedSlaKey = "opened_sla_file"
20+ kindEncrypt taskKind = "encrypt"
21+ kindDecrypt taskKind = "decrypt"
2122)
2223
24+ type taskKind string
25+
26+ func (tk taskKind ) Str () string {
27+ return string (tk )
28+ }
29+
2330var (
2431 MessageDialog = runtime .MessageDialog
2532 SaveFileDialog = runtime .SaveFileDialog
2633 OpenDirectoryDialog = runtime .OpenDirectoryDialog
2734 EventsEmit = runtime .EventsEmit
35+ WindowSetTitle = runtime .WindowSetTitle
2836)
2937
3038type Task struct {
3139 id string
3240 status string
3341 percent float64
34- kind string
42+ kind taskKind
3543 lock * safelock.Safelock
3644 cancel context.CancelFunc
3745}
@@ -45,7 +53,7 @@ func (a *App) startup(ctx context.Context) {
4553 a .ctx = ctx
4654}
4755
48- func (a * App ) domReady (ctx context.Context ) {
56+ func (a App ) domReady (ctx context.Context ) {
4957 runtime .WindowCenter (ctx )
5058
5159 isSlaFileOpened := len (os .Args ) > 1 && strings .HasSuffix (os .Args [1 ], ".sla" )
@@ -59,27 +67,37 @@ func (a *App) domReady(ctx context.Context) {
5967 }
6068}
6169
62- func (a * App ) GetVersion () string {
70+ func (a App ) openFileForMac (path string ) {
71+ if ! strings .HasSuffix (path , ".sla" ) {
72+ a .ShowErrMsg (fmt .Sprintf ("Unsupported file format (%s)" , path ))
73+ return
74+ }
75+
76+ EventsEmit (a .ctx , openedSlaKey , path )
77+ runtime .WindowShow (a .ctx )
78+ }
79+
80+ func (a App ) GetVersion () string {
6381 return Version
6482}
6583
66- func (a * App ) ShowErrMsg (msg string ) {
84+ func (a App ) ShowErrMsg (msg string ) {
6785 _ , _ = MessageDialog (a .ctx , runtime.MessageDialogOptions {
6886 Type : runtime .ErrorDialog ,
6987 Title : "😞 Failure" ,
7088 Message : msg ,
7189 })
7290}
7391
74- func (a * App ) ShowInfoMsg (msg string ) {
92+ func (a App ) ShowInfoMsg (msg string ) {
7593 _ , _ = MessageDialog (a .ctx , runtime.MessageDialogOptions {
7694 Type : runtime .InfoDialog ,
7795 Title : "🎉 Success" ,
7896 Message : msg ,
7997 })
8098}
8199
82- func (a * App ) Cancel () {
100+ func (a App ) Cancel () {
83101 if len (a .task .id ) > 0 {
84102 a .task .cancel ()
85103 }
0 commit comments