-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
72 lines (61 loc) · 1.48 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
Nikki_data []Nikki_t
Setting_data Setting_t
setting_json_path string
}
// NewApp creates a new App application struct
func NewApp() *App {
app := &App{}
app.Setting_data = default_Setting_data
exe_path, err := os.Executable()
if err != nil {
panic(err)
}
app.setting_json_path = path.Join(filepath.Dir(exe_path), "nikki-book-setting.json")
return app
}
func TimeFormat_conv(v string) string {
reslut := v
reslut = strings.Replace(reslut, "YYYY", "2006", 1)
reslut = strings.Replace(reslut, "MM", "01", 1)
reslut = strings.Replace(reslut, "DD", "02", 1)
return reslut
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) Get_dir_fnames(dir_name string) []string {
dir_data, err := ioutil.ReadDir(dir_name)
if err != nil {
return []string{}
}
var fnames []string
for _, e := range dir_data {
fnames = append(fnames, e.Name())
}
return fnames
}
func (a *App) Select_Nikki_dir_Dialog() string {
path_data, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
DefaultDirectory: "",
Title: "日記を保存するディレクトリを選択してください",
})
if err != nil {
return ""
}
return path_data
}