Skip to content

Commit

Permalink
Merge pull request #9 from mrf345/testing
Browse files Browse the repository at this point in the history
Update to latest `safelock-cli` and refactor BE status update
  • Loading branch information
mrf345 authored Sep 18, 2024
2 parents 2d8f7e9 + 63e690c commit 6d06f40
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v ?= 1.0.2
v ?= 1.1.0

pkg-some:
wails build -platform windows/amd64,windows/arm64,linux/amd64
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
### Performance
> ![NOTE]
> [!NOTE]
> Check [safelock-cli/performance](https://github.com/mrf345/safelock-cli?tab=readme-ov-file#performance) for more detailed benchmarks.
<p align="center">
Expand Down
2 changes: 1 addition & 1 deletion backend/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
Version = "1.0.2"
Version = "1.1.0"
Name = "Safelock"
statusUpdateKey = "status_update"
statusEndKey = "status_end"
Expand Down
6 changes: 2 additions & 4 deletions backend/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ func (a *App) Decrypt(path string, password string) (id string, err error) {
a.task.id = id
a.task.kind = kindDecrypt

a.task.lock.StatusObs.
On(sl.StatusUpdate.Str(), a.updateStatus).
On(sl.StatusEnd.Str(), a.resetTask)
a.task.lock.StatusObs.Subscribe(a.handleStatusUpdate)

go func() {
if err = a.task.lock.Decrypt(ctx, inputFile, outputPath, password); err == nil {
a.ShowInfoMsg("All set, and decrypted!")
} else if _, invalid := errors.Unwrap(err).(*slErrs.ErrFailedToAuthenticate); invalid {
} else if slErrs.Is[*slErrs.ErrFailedToAuthenticate](err) {
a.ShowErrMsg("Failure: invalid password or corrupted .sla file")
} else if !errors.Is(err, context.DeadlineExceeded) {
a.ShowErrMsg(fmt.Sprintf("Failure: %s", err.Error()))
Expand Down
4 changes: 1 addition & 3 deletions backend/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ func (a *App) Encrypt(paths []string, password string) (id string, err error) {
a.task.id = id
a.task.kind = kindEncrypt

a.task.lock.StatusObs.
On(sl.StatusUpdate.Str(), a.updateStatus).
On(sl.StatusEnd.Str(), a.resetTask)
a.task.lock.StatusObs.Subscribe(a.handleStatusUpdate)

go func() {
if err = a.task.lock.Encrypt(ctx, paths, outputFile, password); err == nil {
Expand Down
47 changes: 25 additions & 22 deletions backend/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,41 @@ import (
sl "github.com/mrf345/safelock-cli/safelock"
)

func (a *App) updateStatus(status string, percent float64) {
a.task.status = status
a.task.percent = percent
func (a *App) handleStatusUpdate(si sl.StatusItem) {
switch si.Event {
case sl.StatusEnd:
a.resetTask()
case sl.StatusUpdate:
a.updateStatus(si)
}
}

func (a *App) updateStatus(si sl.StatusItem) {
kind := a.task.kind.Str()

if percent > 0.0 {
if kind != "" && si.Percent > 0.0 {
a.task.status = si.Msg
a.task.percent = si.Percent

EventsEmit(
a.ctx,
statusUpdateKey,
si.Msg,
fmt.Sprintf("%.2f", si.Percent),
)
WindowSetTitle(
a.ctx, fmt.Sprintf(
"%sing (%.2f%%)",
strings.Title(a.task.kind.Str()), //nolint:all
percent,
strings.Title(kind), //nolint:all
si.Percent,
),
)
EventsEmit(
a.ctx,
statusUpdateKey,
status,
fmt.Sprintf("%.2f", percent),
)
}
}

func (a *App) resetTask() {
a.offTaskHandlers()
EventsEmit(a.ctx, statusEndKey)
WindowSetTitle(a.ctx, Name)
EventsEmit(a.ctx, statusEndKey)
a.task.lock.StatusObs.Unsubscribe()
a.task = Task{}
}

func (a App) offTaskHandlers() {
if a.task.lock != nil {
a.task.lock.StatusObs.
Off(sl.StatusUpdate.Str(), a.updateStatus).
Off(sl.StatusEnd.Str(), a.resetTask)
}
}
2 changes: 1 addition & 1 deletion bump.xsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

pre_version = "1.0.2"
pre_version = "1.1.0"

if 1 >= len(sys.argv) or sys.argv[1] == pre_version:
raise Exception("need to pass new version")
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ go 1.22
require (
github.com/google/uuid v1.3.0
github.com/mrf345/desktop-entry v0.2.0
github.com/mrf345/safelock-cli v0.4.4
github.com/mrf345/safelock-cli v0.6.0
github.com/stretchr/testify v1.9.0
github.com/wailsapp/wails/v2 v2.9.1
)

replace github.com/wailsapp/wails/v2 => github.com/mrf345/wails/v2 v2.0.0-20240906143800-035eb7c1ed2c

require (
github.com/GianlucaGuarini/go-observable v0.0.0-20171228155646-e39e699e0a00 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/bodgit/plumbing v1.3.0 // indirect
Expand Down Expand Up @@ -56,11 +55,11 @@ require (
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GianlucaGuarini/go-observable v0.0.0-20171228155646-e39e699e0a00 h1:4wp5bMTx9eV6in+ZKiUsyeOqYdp9ooqpw1YWXjwVHJo=
github.com/GianlucaGuarini/go-observable v0.0.0-20171228155646-e39e699e0a00/go.mod h1:2pqNiwoZ8Fj1HBGWyPTXW/iPD332sJzTp3Iy0dIcFMc=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
Expand Down Expand Up @@ -134,8 +132,8 @@ github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrS
github.com/mholt/archiver/v4 v4.0.0-alpha.8/go.mod h1:5f7FUYGXdJWUjESffJaYR4R60VhnHxb2X3T1teMyv5A=
github.com/mrf345/desktop-entry v0.2.0 h1:6RV6Rk1jpSngMtSvKgNL61mWbIRyAoczFheVn7diodE=
github.com/mrf345/desktop-entry v0.2.0/go.mod h1:I05CBP5fSBv7fa3ImKWBY5+0DEpbPzzzih+5y1XaYag=
github.com/mrf345/safelock-cli v0.4.4 h1:VpNNR2i2TzjfdKKAi/R0a0yZIL9UgxCizBMqhLABE/I=
github.com/mrf345/safelock-cli v0.4.4/go.mod h1:5JSG/xryFFU2+lxaca6j5JlPq1YcBrhuJmxhEJtkMHM=
github.com/mrf345/safelock-cli v0.6.0 h1:7IgbizTkU4vRj0NqwZw0pTFQzldDM4/rhdeKoRPkM5A=
github.com/mrf345/safelock-cli v0.6.0/go.mod h1:KA5CwRoXy6t5jiv3BYEQvazJqa+6fN3xJwlqoeuohhY=
github.com/mrf345/wails/v2 v2.0.0-20240906143800-035eb7c1ed2c h1:WNoJ0oF8O6uf+VsVf7AWBST9SMWHuBOb2+OC1m+7GaU=
github.com/mrf345/wails/v2 v2.0.0-20240906143800-035eb7c1ed2c/go.mod h1:7maJV2h+Egl11Ak8QZN/jlGLj2wg05bsQS+ywJPT0gI=
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 h1:e3mzJFJs4k83GXBEiTaQ5HgSc/kOK8q0rDaRO0MPaOk=
Expand Down Expand Up @@ -196,8 +194,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -285,13 +283,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -300,8 +298,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down

0 comments on commit 6d06f40

Please sign in to comment.