Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mohemohe committed Feb 5, 2024
2 parents a2a71c1 + 1bc2c05 commit c8bf016
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/common-creation/sim-applet-manager/util/cardreader"
"github.com/common-creation/sim-applet-manager/util/db"
"github.com/common-creation/sim-applet-manager/util/gp"
"github.com/common-creation/sim-applet-manager/util/log"

wailsRutime "github.com/wailsapp/wails/v2/pkg/runtime"
)
Expand All @@ -34,6 +35,7 @@ func NewApp() *App {
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
apppath.MustAppDirPath(ctx)
log.Rotate(ctx)
}

func (a *App) GetGpPath() string {
Expand Down
3 changes: 3 additions & 0 deletions util/gp/gp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/common-creation/sim-applet-manager/util/cap"
"github.com/common-creation/sim-applet-manager/util/command"
"github.com/common-creation/sim-applet-manager/util/db"
"github.com/common-creation/sim-applet-manager/util/log"

wailsRutime "github.com/wailsapp/wails/v2/pkg/runtime"
)
Expand Down Expand Up @@ -149,6 +150,8 @@ func Run(ctx context.Context, option RunOption) Result {
}
println("done!")

log.WriteString(ctx, outputBuilder.String())

return Result{
Success: cmd.ProcessState.Success(),
Output: outputBuilder.String(),
Expand Down
39 changes: 39 additions & 0 deletions util/log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package log

import (
"context"
"os"
"path"

"github.com/common-creation/sim-applet-manager/util/apppath"
)

func Rotate(ctx context.Context) {
appPath := apppath.MustAppDirPath(ctx)
oldLogPath := path.Join(appPath, "log.1.txt")
if _, err := os.Stat(oldLogPath); err == nil || !os.IsNotExist(err) {
if err := os.Remove(oldLogPath); err != nil {
// TODO: エラーダイアログ
}
}
currentLogPath := path.Join(appPath, "log.txt")
if _, err := os.Stat(currentLogPath); err == nil || !os.IsNotExist(err) {
if err := os.Rename(currentLogPath, oldLogPath); err != nil {
// TODO: エラーダイアログ
}
}
}

func WriteString(ctx context.Context, message string) {
appPath := apppath.MustAppDirPath(ctx)
currentLogPath := path.Join(appPath, "log.txt")
f, err := os.OpenFile(currentLogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
// TODO: エラーダイアログ
return
}
defer f.Close()
if _, err := f.WriteString(message); err != nil {
// TODO: エラーダイアログ
}
}
2 changes: 1 addition & 1 deletion wails.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"info": {
"productName": "SIMAppletManager",
"productVersion": "1.0.4",
"productVersion": "1.0.5",
"companyName": "COMMON CREATION, Co., Ltd.",
"copyright": "© 2024 COMMON CREATION, Co., Ltd. All rights reserved."
}
Expand Down

0 comments on commit c8bf016

Please sign in to comment.