Skip to content

Commit

Permalink
Merge branch 'global-shortcut-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
shivas committed Jul 1, 2021
2 parents c11077a + 1140320 commit 7e77697
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 107 deletions.
61 changes: 59 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
# all available settings of specific linters
linters-settings:
errcheck:
check-type-assertions: true
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
check-shadowing: true
disable:
- unsafeptr
- unsafeptr

nolintlint:
require-explanation: true
require-specific: true

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nolintlint
- nakedret
- prealloc
- predeclared
- revive
- staticcheck
- structcheck
- stylecheck
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- varcheck
- whitespace
- wsl

run:
issues-exit-code: 1
99 changes: 81 additions & 18 deletions cmd/abyss-blackbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ type captureConfig struct {
EVEClientWindowTitle string
EVEGameLogsFolder string
TestServer bool
RecorderShortcutText string
RecorderShortcut walk.Shortcut
}

// SetRecorderShortcut satisfies ShortcutSetter interface.
func (c *captureConfig) SetRecorderShortcut(s walk.Shortcut) {
c.RecorderShortcut = s
c.RecorderShortcutText = s.String()
}

func main() {
var err error

currentSettings, err := readConfig()
if err != nil {
log.Fatal(err)
Expand All @@ -54,6 +64,7 @@ func main() {
clr := combatlog.NewReader(currentSettings.EVEGameLogsFolder)
recorder = NewRecorder(recordingChannel, currentSettings, notificationChannel, clr)
recorder.StartLoop()

defer recorder.StopLoop()

foundEVEClientWindows, err := screen.FindWindow(regexp.MustCompile(EVEClientWindowRe))
Expand All @@ -63,7 +74,7 @@ func main() {
comboModel = append(comboModel, &mainwindow.WindowComboBoxItem{WindowTitle: title, WindowHandle: handle})
}

logFiles, _ := clr.GetLogFiles(time.Now(), time.Duration(24*time.Hour))
logFiles, _ := clr.GetLogFiles(time.Now(), time.Duration(24)*time.Hour)
charMap := clr.MapCharactersToFiles(logFiles)

armw := mainwindow.NewAbyssRecorderWindow(currentSettings, drawStuff, comboModel)
Expand All @@ -79,7 +90,7 @@ func main() {
if accepted {
_ = armw.EVEGameLogsFolderLabel.SetText(fd.FilePath)
clr.SetLogFolder(fd.FilePath)
logFiles, err := clr.GetLogFiles(time.Now(), time.Duration(24*time.Hour))
logFiles, err = clr.GetLogFiles(time.Now(), time.Duration(24)*time.Hour)
if err != nil {
return
}
Expand All @@ -101,16 +112,17 @@ func main() {
}
}(notificationChannel, notificationIcon)

armw.RecordingButton.Clicked().Attach(func() {
if recorder.Status() == RECORDER_STOPPED {

recordingButtonHandler := func() {
if recorder.Status() == RecorderStopped {
charsChecked := []string{}

checkboxes := armw.CombatLogCharacterGroup.Children()
for i := 0; i < checkboxes.Len(); i++ {
cb, ok := checkboxes.At(i).(*walk.CheckBox)
if !ok {
continue
}

if cb.Checked() {
charsChecked = append(charsChecked, cb.Text())
}
Expand All @@ -127,9 +139,8 @@ func main() {
armw.ChooseLogDirButton.SetEnabled(false)
armw.TestServer.SetEnabled(false)
_ = armw.RecordingButton.SetText("Stop recording")

} else {
err := recorder.Stop()
err = recorder.Stop()
if err != nil {
walk.MsgBox(armw.MainWindow, "Error writing recording", err.Error(), walk.MsgBoxIconWarning)
}
Expand All @@ -139,19 +150,49 @@ func main() {
armw.TestServer.SetEnabled(true)
_ = armw.RecordingButton.SetText("Start recording")
}
}

armw.RecordingButton.Clicked().Attach(recordingButtonHandler)
armw.MainWindow.Hotkey().Attach(func(hkid int) {
if hkid == 1 {
recordingButtonHandler()
}
})

go func(cw *walk.CustomWidget) {
walk.RegisterGlobalHotKey(armw.MainWindow, 1, currentSettings.RecorderShortcut)

shortcutRecorderHandler := func() {
if !armw.RecorderShortcutEdit.Enabled() { // start recording
armw.RecorderShortcutEdit.SetEnabled(true)
_ = armw.RecorderShortcutEdit.SetFocus()
_ = armw.RecorderShortcutRecordButton.SetText("Save")

if !win.UnregisterHotKey(armw.MainWindow.Handle(), 1) {
walk.MsgBox(armw.MainWindow, "Failed unregistering hotkey", "failed unregistering key, please restart application", walk.MsgBoxIconWarning)
return
}
} else { // persist new shortcut and rebind
armw.RecorderShortcutEdit.SetEnabled(false)
_ = armw.RecorderShortcutRecordButton.SetText("Record shortcut")
if !walk.RegisterGlobalHotKey(armw.MainWindow, 1, currentSettings.RecorderShortcut) {
walk.MsgBox(armw.MainWindow, "Failed registering new hotkey", "failed registering new shortcut key, please restart application", walk.MsgBoxIconWarning)
return
}
_ = writeConfig(currentSettings)
}
}

armw.RecorderShortcutRecordButton.Clicked().Attach(shortcutRecorderHandler)

go func(cw *walk.CustomWidget) {
t := time.NewTicker(time.Second)

for range t.C {

img, err := screen.CaptureWindowArea(
img, errr := screen.CaptureWindowArea(
foundEVEClientWindows.GetHandleByTitle(currentSettings.EVEClientWindowTitle),
image.Rectangle{Min: image.Point{X: currentSettings.X, Y: currentSettings.Y}, Max: image.Point{X: currentSettings.X + 255, Y: currentSettings.Y + currentSettings.H}},
)
if err != nil {
if errr != nil {
walk.MsgBox(armw.MainWindow, "Error capturing window area, restart of application is needed.", err.Error(), walk.MsgBoxIconWarning)
fmt.Printf("error lost capture window: %v", err)
os.Exit(1) // exit
Expand All @@ -173,7 +214,6 @@ func main() {
default:
log.Println("preview channel full, dropping frame")
}

}

select {
Expand All @@ -184,7 +224,6 @@ func main() {

win.InvalidateRect(cw.Handle(), nil, false)
}

}(armw.CaptureWidget)

walk.Clipboard().ContentsChanged().Attach(recorder.ClipboardListener)
Expand Down Expand Up @@ -222,6 +261,7 @@ func CreateNotificationIcon(mw *walk.MainWindow) *walk.NotifyIcon {
if err := ni.SetIcon(icon); err != nil {
log.Fatal(err)
}

if err := ni.SetToolTip("Click for info or use the context menu to exit."); err != nil {
log.Fatal(err)
}
Expand All @@ -233,6 +273,7 @@ func CreateNotificationIcon(mw *walk.MainWindow) *walk.NotifyIcon {
}

exitAction.Triggered().Attach(func() { walk.App().Exit(0) })

if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
log.Fatal(err)
}
Expand All @@ -252,6 +293,7 @@ func drawStuff(canvas *walk.Canvas, updateBounds walk.Rectangle) error {
if err != nil {
return err
}

defer bmp.Dispose()

err = canvas.DrawImagePixels(bmp, walk.Point{X: 0, Y: 0})
Expand All @@ -261,6 +303,7 @@ func drawStuff(canvas *walk.Canvas, updateBounds walk.Rectangle) error {
default:
return nil
}

return nil
}

Expand All @@ -269,22 +312,25 @@ func paletted(img *image.NRGBA, cutoff uint32) *image.Paletted {
palette := []color.Color{color.White, color.Black}
buffimg := image.NewPaletted(img.Rect, palette)

var threshold uint32 = cutoff << 8
var threshold = cutoff << 8

for y := 0; y < img.Rect.Dy(); y++ {
for x := 0; x < img.Rect.Dx(); x++ {
c := img.At(x, y)
r, _, _, _ := c.RGBA()

if r > threshold {
buffimg.SetColorIndex(x, y, 0)
continue
}

if r <= threshold {
buffimg.SetColorIndex(x, y, 1)
continue
}
}
}

return buffimg
}

Expand All @@ -296,18 +342,34 @@ func readConfig() (*captureConfig, error) {
}

var c *captureConfig

load := true
settingsFilename := filepath.Join(appDir, "settings.json")

_, err = os.Stat(settingsFilename)
if os.IsNotExist(err) {
// fetch current user folder and try to point to Gamelogs folder
usr, err := user.Current()
if err != nil {
return nil, err
usr, errr := user.Current()
if errr != nil {
return nil, errr
}

eveGameLogsFolder := filepath.Join(usr.HomeDir, "Documents", "EVE", "logs", "Gamelogs")

c = &captureConfig{AppRoot: appDir, X: 10, Y: 10, H: 400, Recordings: filepath.Join(appDir, "recordings"), FilterThreshold: 110, FilteredPreview: false, EVEGameLogsFolder: eveGameLogsFolder}
defaultShortcut := walk.Shortcut{Modifiers: walk.ModControl | walk.ModAlt, Key: walk.KeyEnd}

c = &captureConfig{
AppRoot: appDir,
X: 10,
Y: 10,
H: 400,
Recordings: filepath.Join(appDir, "recordings"),
FilterThreshold: 110,
FilteredPreview: false,
EVEGameLogsFolder: eveGameLogsFolder,
RecorderShortcutText: defaultShortcut.String(),
RecorderShortcut: defaultShortcut,
}
load = false
} else if err != nil {
return c, err
Expand All @@ -332,6 +394,7 @@ func readConfig() (*captureConfig, error) {
// writeConfig saves configuration to json file
func writeConfig(c *captureConfig) error {
settingsFilename := filepath.Join(c.AppRoot, "settings.json")

f, err := os.Create(settingsFilename)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 7e77697

Please sign in to comment.