Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log #53

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"prettier.requireConfig": true,
"html.format.enable": true,
"go.formatTool": "goimports",
"editor.formatOnSave": true
"editor.formatOnSave": true,
"files.eol": "\n"
}
90 changes: 76 additions & 14 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,100 @@ import (
"fmt"
"log"
"path/filepath"
"sync"

"github.com/getlantern/systray"
"github.com/masahide/OmniSSHAgent/pkg/cygwinsocket"
"github.com/masahide/OmniSSHAgent/pkg/namedpipe"
"github.com/masahide/OmniSSHAgent/pkg/pageant"
"github.com/masahide/OmniSSHAgent/pkg/sshkey"
"github.com/masahide/OmniSSHAgent/pkg/sshutil"
"github.com/masahide/OmniSSHAgent/pkg/store"
"github.com/masahide/OmniSSHAgent/pkg/unix"
"github.com/masahide/OmniSSHAgent/pkg/wintray"
"github.com/masahide/OmniSSHAgent/pkg/winopen"

//"github.com/masahide/OmniSSHAgent/pkg/wintray"
"github.com/masahide/OmniSSHAgent/icon"
"github.com/wailsapp/wails/v2/pkg/runtime"
)

// App application struct
type App struct {
ctx context.Context
ti *wintray.TrayIcon
ctx context.Context
//ti *wintray.TrayIcon
keyRing *sshutil.KeyRing
settings *store.Settings
wg sync.WaitGroup
}

// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}

func (a *App) systrayOnRedy() {
systray.SetIcon(icon.Data)
systray.SetTitle(AppName)
systray.SetTooltip(AppName)
mShowWindow := systray.AddMenuItem("ShowWindow", "Show main window")
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
mLogCheckBox := systray.AddMenuItemCheckbox("Debug log", "Enable debug log file output", false)
mLogDirOpen := systray.AddMenuItem("Open log directory", "open log directory")
mLogDirOpen.Disable()
go func() {
for {
select {
case <-mShowWindow.ClickedCh:
a.showWindow()
case <-mLogCheckBox.ClickedCh:
if mLogCheckBox.Checked() {
mLogCheckBox.Uncheck()
log.Print("Disable debug log")
Logger.SetEnable(false)
mLogDirOpen.Disable()
} else {
mLogCheckBox.Check()
Logger.SetEnable(true)
log.Print("Enable debug log")
mLogDirOpen.Enable()
}
case <-mQuit.ClickedCh:
log.Print("Quit was clicked on the menu")
a.Quit()
return
case <-mLogDirOpen.ClickedCh:
dir := filepath.Dir(Logger.FilePath)
winopen.Open(dir)
}
}
}()
}
func (a *App) systrayOnExit() {
//log.Print("systrayOnExit")
Logger.Close()
a.wg.Done()
}

// startup is called at application startup
func (a *App) startup(ctx context.Context) {
// Perform your setup here
a.ctx = ctx
a.ti = wintray.NewTrayIcon()
a.ti.BalloonClickFunc = a.showWindow
a.ti.TrayClickFunc = a.showWindow
go a.ti.RunTray()
/*
a.ti = wintray.NewTrayIcon()
a.ti.BalloonClickFunc = a.showWindow
a.ti.TrayClickFunc = a.showWindow
go a.ti.RunTray()
*/
a.wg.Add(1)
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("recover:%v", r)
}
a.Quit()
}()
systray.Run(a.systrayOnRedy, a.systrayOnExit)
}()

debug := false
a.keyRing = sshutil.NewKeyRing(a.settings)
Expand Down Expand Up @@ -93,12 +154,6 @@ func (a *App) domReady(ctx context.Context) {
// Add your action here
}

// shutdown is called at application termination
func (a *App) shutdown(ctx context.Context) {
a.ti.Dispose()
// Perform your teardown here
}

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s!", name)
Expand All @@ -110,10 +165,17 @@ func (a *App) showWindow() {
}

func (a *App) Quit() {
a.ti.Dispose()
log.Print("call a.Quit")
runtime.Quit(a.ctx)
}

// shutdown はruntime.Quitから呼ばれる
func (a *App) shutdown(ctx context.Context) {
log.Print("shutdown")
systray.Quit()
a.wg.Wait()
}

func (a *App) AddLocalFile(pk sshkey.PrivateKeyFile) error {
pk.Name = filepath.Base(pk.FilePath)
pk.StoreType = sshutil.LocalStore
Expand Down
35 changes: 21 additions & 14 deletions frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta content='width=device-width,initial-scale=1' name='viewport'>
<head>
<meta charset="utf-8" />
<meta content="width=device-width,initial-scale=1" name="viewport" />

<title>OmniSSHAgent</title>
<link rel="stylesheet" href="/iconfont/material-icons.css">
<link rel="stylesheet" href="/smui.css" media="(prefers-color-scheme: light)" />
<link rel="stylesheet" href="/smui-dark.css" media="screen and (prefers-color-scheme: dark)" />
<link rel="stylesheet" href="/global.css">
<link rel="stylesheet" href="/bundle.css">
<script defer src='bundle.js'></script>
</head>
<title>OmniSSHAgent</title>
<link rel="stylesheet" href="/iconfont/material-icons.css" />
<link
rel="stylesheet"
href="/smui.css"
media="(prefers-color-scheme: light)"
/>
<link
rel="stylesheet"
href="/smui-dark.css"
media="screen and (prefers-color-scheme: dark)"
/>
<link rel="stylesheet" href="/global.css" />
<link rel="stylesheet" href="/bundle.css" />
<script defer src="bundle.js"></script>
</head>

<body data-wails-drag>
</body>
<body data-wails-drag></body>
</html>
52 changes: 33 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,69 @@
module github.com/masahide/OmniSSHAgent

go 1.21

toolchain go1.21.5
go 1.22.3

require (
github.com/Microsoft/go-winio v0.6.1
github.com/Microsoft/go-winio v0.6.2
github.com/apenwarr/fixconsole v0.0.0-20191012055117-5a9f6489cc29
github.com/cwchiu/go-winapi v0.0.0-20130629162214-19f502a3f526
github.com/davidmz/go-pageant v1.0.2
github.com/google/go-cmp v0.5.8
github.com/google/uuid v1.5.0
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/kayrus/putty v1.0.4
github.com/kelseyhightower/envconfig v1.4.0
github.com/wailsapp/wails/v2 v2.7.1
github.com/zalando/go-keyring v0.2.3
golang.org/x/crypto v0.17.0
golang.org/x/sys v0.16.0
github.com/wailsapp/wails/v2 v2.8.2
github.com/zalando/go-keyring v0.2.4
golang.org/x/crypto v0.23.0
golang.org/x/sys v0.20.0
)

require (
github.com/getlantern/context v0.0.0-20220418194847-3d5e7a086201 // indirect
github.com/getlantern/errors v1.0.4 // indirect
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65 // indirect
github.com/getlantern/hex v0.0.0-20220104173244-ad7e4b9194dc // indirect
github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770 // indirect
github.com/getlantern/ops v0.0.0-20231025133620-f368ab734534 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
)

require (
github.com/alessio/shellescape v1.4.2 // indirect
github.com/apenwarr/w32 v0.0.0-20190407065021-aa00fece76ab // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/getlantern/systray v1.2.2
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/labstack/echo/v4 v4.11.4 // indirect
github.com/labstack/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/leaanthony/gosod v1.0.4 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
github.com/leaanthony/u v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/tkrajina/go-reflector v0.5.6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/wailsapp/go-webview2 v1.0.10 // indirect
github.com/wailsapp/mimetype v1.4.1 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/text v0.15.0 // indirect
)

// replace github.com/wailsapp/wails/v2 v2.0.0-beta.32 => /Users/cf0681/go/pkg/mod/github.com/wailsapp/wails/v2@v2.0.0-beta.32
Loading