Skip to content

Commit 877c338

Browse files
authored
Merge pull request #6 from mrf345/testing
Add open .sla files support, and refactor title updates
2 parents 559b42f + 2b7c8d9 commit 877c338

File tree

16 files changed

+97
-37
lines changed

16 files changed

+97
-37
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ jobs:
8484
- name: Build Windows NSIS installer (Normal)
8585
if: runner.os == 'Windows' && startsWith(matrix.build.tag, 'windows-a')
8686
shell: bash
87-
run: wails build -platform ${{ matrix.build.platform }} -nsis -windowsconsole -ldflags "-X main.version=v${{ steps.normalize_version.outputs.version }}"
87+
run: wails build -platform ${{ matrix.build.platform }} -nsis -ldflags "-X main.version=v${{ steps.normalize_version.outputs.version }}"
8888

8989
- name: Build Windows NSIS installer (Portable)
9090
if: runner.os == 'Windows' && startsWith(matrix.build.tag, 'windows-portable')
9191
shell: bash
92-
run: wails build -platform ${{ matrix.build.platform }} -nsis -ldflags "-X main.version=v${{ steps.normalize_version.outputs.version }} -X main.portablebuild=true" -windowsconsole
92+
run: wails build -platform ${{ matrix.build.platform }} -nsis -ldflags "-X main.version=v${{ steps.normalize_version.outputs.version }} -X main.portablebuild=true"
9393

9494
# Packaging
9595

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
v ?= 1.0.0
1+
v ?= 1.0.1
22

33
pkg-some:
44
wails build -platform windows/amd64,windows/arm64,linux/amd64

backend/app.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package backend
22

33
import (
44
"embed"
5+
"os"
6+
"path/filepath"
57
"runtime"
68

79
desktopEntry "github.com/mrf345/desktop-entry"
810
"github.com/wailsapp/wails/v2/pkg/options"
911
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
1012
"github.com/wailsapp/wails/v2/pkg/options/linux"
13+
"github.com/wailsapp/wails/v2/pkg/options/mac"
1114
)
1215

1316
func NewApp(icon []byte, assets embed.FS) (*App, *options.App) {
@@ -35,6 +38,7 @@ func NewApp(icon []byte, assets embed.FS) (*App, *options.App) {
3538
AssetServer: &assetserver.Options{Assets: assets},
3639
Bind: []interface{}{app},
3740
Linux: &linux.Options{Icon: icon},
41+
Mac: &mac.Options{OnFileOpen: app.openFileForMac},
3842
DragAndDrop: &options.DragAndDrop{
3943
EnableFileDrop: true,
4044
},
@@ -45,5 +49,10 @@ func NewDesktopEntry(icon []byte) *desktopEntry.DesktopEntry {
4549
entry := desktopEntry.New(Name, Version, icon)
4650
entry.Comment = "Fast & simple drag & drop files encryption tool"
4751
entry.Categories = "Utility;Security;"
52+
entry.MimeType.Path = filepath.Join(os.Getenv("HOME"), ".local/share/mime")
53+
entry.MimeType.Type = "application/x-safelock"
54+
entry.MimeType.GenericIcon = "package-x-generic"
55+
entry.MimeType.Comment = "Safelock encrypted file"
56+
entry.MimeType.Patterns = []string{"*.sla"}
4857
return entry
4958
}

backend/common.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package backend
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"strings"
78
"time"
@@ -11,27 +12,34 @@ import (
1112
)
1213

1314
const (
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+
2330
var (
2431
MessageDialog = runtime.MessageDialog
2532
SaveFileDialog = runtime.SaveFileDialog
2633
OpenDirectoryDialog = runtime.OpenDirectoryDialog
2734
EventsEmit = runtime.EventsEmit
35+
WindowSetTitle = runtime.WindowSetTitle
2836
)
2937

3038
type 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
}

backend/decrypt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (a *App) Decrypt(path string, password string) (id string, err error) {
6363
}
6464

6565
inputFile.Close()
66+
WindowSetTitle(a.ctx, Name)
6667
}()
6768

6869
return

backend/decrypt_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestDecrypt(t *testing.T) {
3333

3434
mockOpenDirectoryDialog(tempDir, nil)
3535
mockEventsEmit()
36+
mockWindowSetTitle()
3637
dTypeChan := mockMessageDialog()
3738
_, err := app.Decrypt(outputPath, pwd)
3839
dialogType := <-dTypeChan
@@ -55,6 +56,7 @@ func TestDecryptFail(t *testing.T) {
5556

5657
mockOpenDirectoryDialog(tempDir, nil)
5758
mockEventsEmit()
59+
mockWindowSetTitle()
5860
dTypeChan := mockMessageDialog()
5961
_, err := app.Decrypt(outputPath, "wrong pass")
6062
dialogType := <-dTypeChan

backend/encrypt.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func (a *App) Encrypt(paths []string, password string) (id string, err error) {
3737
return "", err
3838
}
3939

40-
if outputFile, err = os.OpenFile(outputPath, os.O_RDWR|os.O_CREATE, 0755); err != nil {
40+
fileFlags := os.O_RDWR | os.O_CREATE | os.O_TRUNC
41+
42+
if outputFile, err = os.OpenFile(outputPath, fileFlags, 0755); err != nil {
4143
a.ShowErrMsg(fmt.Sprintf("Failure: %s", err.Error()))
4244
cancel()
4345
return
@@ -62,6 +64,8 @@ func (a *App) Encrypt(paths []string, password string) (id string, err error) {
6264
outputFile.Close()
6365
_ = os.Remove(outputFile.Name())
6466
}
67+
68+
WindowSetTitle(a.ctx, Name)
6569
}()
6670

6771
return

backend/encrypt_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestEncrypt(t *testing.T) {
3535

3636
mockSaveFileDialog(outputPath, nil)
3737
mockEventsEmit()
38+
mockWindowSetTitle()
3839
dTypeChan := mockMessageDialog()
3940
_, err := app.Encrypt(inputs, pwd)
4041
dialogType := <-dTypeChan
@@ -59,6 +60,7 @@ func TestEncryptFail(t *testing.T) {
5960

6061
mockSaveFileDialog(outputPath, nil)
6162
mockEventsEmit()
63+
mockWindowSetTitle()
6264
dTypeChan := mockMessageDialog()
6365
_, err := app.Encrypt(inputs, pwd)
6466
dialogType := <-dTypeChan
@@ -95,3 +97,11 @@ func mockEventsEmit() chan string {
9597
}
9698
return event
9799
}
100+
101+
func mockWindowSetTitle() chan string {
102+
titles := make(chan string, 10000)
103+
WindowSetTitle = func(ctx context.Context, title string) {
104+
titles <- title
105+
}
106+
return titles
107+
}

backend/helpers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package backend
22

33
import (
44
"fmt"
5+
"strings"
56

67
sl "github.com/mrf345/safelock-cli/safelock"
78
)
@@ -11,6 +12,13 @@ func (a *App) updateStatus(status string, percent float64) {
1112
a.task.percent = percent
1213

1314
if percent > 0.0 {
15+
WindowSetTitle(
16+
a.ctx, fmt.Sprintf(
17+
"%sing (%.2f%%)",
18+
strings.Title(a.task.kind.Str()), //nolint:all
19+
percent,
20+
),
21+
)
1422
EventsEmit(
1523
a.ctx,
1624
statusUpdateKey,
@@ -23,10 +31,11 @@ func (a *App) updateStatus(status string, percent float64) {
2331
func (a *App) resetTask() {
2432
a.offTaskHandlers()
2533
EventsEmit(a.ctx, statusEndKey)
34+
WindowSetTitle(a.ctx, Name)
2635
a.task = Task{}
2736
}
2837

29-
func (a *App) offTaskHandlers() {
38+
func (a App) offTaskHandlers() {
3039
if a.task.lock != nil {
3140
a.task.lock.StatusObs.
3241
Off(sl.StatusUpdate.Str(), a.updateStatus).

frontend/global.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ declare global {
88
OnFileDrop(callback: (x: number, y: number, paths: string[]) => void, useDropTarget: boolean) :void
99
OnFileDropOff(): void
1010
BrowserOpenURL(url: string): void
11-
WindowSetTitle(title: string): void
1211
}
1312
}
1413
}

0 commit comments

Comments
 (0)