Skip to content

Commit

Permalink
getting closer to the settings update
Browse files Browse the repository at this point in the history
  • Loading branch information
kociumba committed Oct 9, 2024
1 parent 7907f52 commit 89ecc15
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .task/checksum/build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1ecad4500d5674d995a870bbe0f51c9e
4b0bf220c6b1a17111459c48c118e677
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Website = "https://github.com/kociumba/Kinjector"
Name = "Kinjector"
ID = "org.kociumba.kinjector"
Version = "1.0.0"
Build = 57
Build = 58
250 changes: 106 additions & 144 deletions injector.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// DLL Injector
package main

import (
"encoding/json"
"flag"
"fmt"
"image/color"
"image/png"
"os"
"path/filepath"
"strings"
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
Expand Down Expand Up @@ -179,15 +182,6 @@ func main() {
clog.Warn("Failed to load profiles:", err)
}
appIcon := fyne.NewStaticResource(resourceIconPng.StaticName, resourceIconPng.StaticContent)
// pathToKinjector, err := os.Executable()
// if err != nil {
// clog.Fatal(err)
// }

// pathToKinjector, err = filepath.EvalSymlinks(pathToKinjector)
// if err != nil {
// clog.Fatal(err)
// }

if *dbg {
clog.SetLevel(clog.DebugLevel)
Expand Down Expand Up @@ -251,6 +245,7 @@ func main() {
}
}),
)
m.Label = "Kinjector"
desk.SetSystemTrayMenu(m)
desk.SetSystemTrayIcon(appIcon)
}
Expand Down Expand Up @@ -330,68 +325,6 @@ func main() {
userSelection.UnsafeUnload = checked
})

// Create the unload button with confirmation dialog
// unloadButton := widget.NewButtonWithIcon("Unload", theme.CancelIcon(), func() {
// if userSelection.UnsafeUnload {
// dialog.NewConfirm(
// "Unsafe Unload",
// "Warning: Unsafe unload may cause memory leaks or crash the target process. Proceed?",
// func(confirm bool) {
// if confirm {
// performUnload(userSelection, w)
// }
// },
// w,
// ).Show()
// } else {
// performUnload(userSelection, w)
// }
// })

// // create the app layout
// //
// //
// clog.Info("Creating GUI")
// // Create the main injection tab
// injectionTab := container.NewVBox(
// widget.NewLabelWithStyle("Select the process to inject: ", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
// procSelect,
// widget.NewSeparator(),
// widget.NewButtonWithIcon("Select dll to load", theme.FolderOpenIcon(), func() {
// userSelection.SelectedDll, err = zenity.SelectFile(zenity.Filename(os.ExpandEnv("$HOME")), zenity.FileFilter{Patterns: []string{"*.dll"}})
// userSelection.DllFile = trimFilePath(userSelection.SelectedDll)
// dllDisplay.SetText("Dll selected: " + userSelection.DllFile)
// }),
// dllDisplay,
// // widget.NewSeparator(),
// widget.NewButtonWithIcon("Inject", theme.ConfirmIcon(), func() {
// dialog.NewConfirm(
// "Inject ?",
// "Inject "+userSelection.SelectedProc+" with "+userSelection.DllFile+" ?",
// func(b bool) {
// if b {
// err := Inject(userSelection)
// injection.Start()
// if err != nil {
// dialog.NewError(err, w).Show()
// clog.Warn(err)
// injection.Stop()
// } else {
// dialog.NewInformation("Success", "Injected into "+userSelection.SelectedProc+" !", w).Show()
// injection.Stop()
// }
// }
// },
// w,
// ).Show()
// }),
// // triggers the unloader
// // widget.NewSeparator(),
// widget.NewSeparator(),
// unsafeUnloadCheck,
// unloadButton,
// )

// Damn this shit stupid
selectDllButton := widget.NewButton("", func() {})

Expand All @@ -413,29 +346,46 @@ func main() {
{Text: "Unsafe Unload", Widget: unsafeUnloadCheck},
},
OnSubmit: func() {
dialog.NewConfirm(
"Inject ?",
fmt.Sprintf("Inject %s with %s ?", userSelection.SelectedProc, userSelection.DllFile),
func(b bool) {
if b {
err := Inject(userSelection)
injection.Start()
if err != nil {
dialog.NewError(err, w).Show()
clog.Warn(err)
injection.Stop()
} else {
dialog.NewInformation("Success", "Injected into "+userSelection.SelectedProc+" !", w).Show()
injection.Stop()
}
}
},
w,
).Show()
// dialog.NewConfirm(
// "Inject ?",
// fmt.Sprintf("Inject %s with %s ?", userSelection.SelectedProc, userSelection.DllFile),
// func(b bool) {
// if b {
// err := Inject(userSelection)
// injection.Start()
// if err != nil {
// dialog.NewError(err, w).Show()
// clog.Warn(err)
// injection.Stop()
// } else {
// dialog.NewInformation("Success", "Injected into "+userSelection.SelectedProc+" !", w).Show()
// injection.Stop()
// }
// }
// },
// w,
// ).Show()

// INFO: no more dialog, to make the shortcut actually usable
err := Inject(userSelection)
injection.Start()
if err != nil {
dialog.NewError(err, w).Show()
clog.Warn(err)
injection.Stop()
} else {
dialog.NewInformation("Success", "Injected into "+userSelection.SelectedProc+" !", w).Show()
injection.Stop()
}
},
OnCancel: func() {
// INFO: here to disable unloading if the user has the setting off
if !settingsSelection.AllowUnload {
dialog.NewInformation(
"Settings blocked dll unloading",
"Application settings do not allow unloading right now. Change this in the settings tab.",
w,
).Show()
return
}
if userSelection.UnsafeUnload {
Expand All @@ -459,14 +409,29 @@ func main() {
// return "Unload"
// } else {
// return ""
// }
// }(),
// }(),
CancelText: "Unload",
}

injectionTab := container.NewVBox(
widget.NewLabelWithStyle("Manage Injection", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
injectionForm,
injectShortcutText := canvas.NewText("inject: CTRL+SHIFT+J", color.RGBA{150, 150, 150, 255})
injectShortcutText.TextStyle.Italic = true
injectShortcutText.Alignment = fyne.TextAlignCenter
quitShortcutText := canvas.NewText("quit: CTRL+Q", color.RGBA{150, 150, 150, 255})
quitShortcutText.TextStyle.Italic = true
quitShortcutText.Alignment = fyne.TextAlignCenter

injectionTab := container.NewBorder(
container.NewVBox(
widget.NewLabelWithStyle("Manage Injection", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
injectionForm,
),

container.NewVBox(
injectShortcutText,
quitShortcutText,
),
nil,
nil,
)

// Create the profile management tab
Expand Down Expand Up @@ -540,61 +505,13 @@ func main() {
CancelText: "Delete Profile",
}

// saveProfileButton := widget.NewButtonWithIcon("Save Profile", theme.DocumentSaveIcon(), func() {
// if profileName.Text != "" {
// err := userSelection.SaveProfile(profileName.Text)
// if err != nil {
// dialog.ShowError(err, w)
// } else {
// dialog.ShowInformation("Success", "Profile saved", w)
// updateProfileList()
// }
// } else {
// dialog.ShowInformation("Error", "Please enter a profile name", w)
// }
// })

// deleteProfileButton := widget.NewButtonWithIcon("Delete Profile", theme.DeleteIcon(), func() {
// if loadProfileSelect.Selected == "" {
// dialog.ShowInformation("Error", "Please select a profile to delete", w)
// return
// }
// dialog.NewConfirm(
// "Delete Profile",
// "Are you sure you want to delete the profile '"+loadProfileSelect.Selected+"'?",
// func(confirm bool) {
// if confirm {
// err := userSelection.DeleteProfile(loadProfileSelect.Selected)
// if err != nil {
// dialog.ShowError(err, w)
// } else {
// dialog.ShowInformation("Success", "Profile deleted", w)
// updateProfileList()
// loadProfileSelect.SetSelected("")
// }
// }
// },
// w,
// ).Show()
// })

updateProfileList()

profileTab := container.NewVBox(
widget.NewLabelWithStyle("Profile Management", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
profileForm,
)

// profileTab := container.NewVBox(
// widget.NewLabelWithStyle("Profile Management", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
// profileName,
// saveProfileButton,
// widget.NewSeparator(),
// widget.NewLabel("Load Profile:"),
// loadProfileSelect,
// deleteProfileButton,
// )

initSettings()

// Create tabs
Expand All @@ -621,6 +538,51 @@ func main() {
)

w.SetContent(content)
w.Canvas().AddShortcut(
&desktop.CustomShortcut{
KeyName: fyne.KeyJ,
Modifier: fyne.KeyModifierControl | fyne.KeyModifierShift,
},
func(shortcut fyne.Shortcut) {
injectionForm.OnSubmit()
})

w.Canvas().AddShortcut(
&desktop.CustomShortcut{
KeyName: fyne.KeyQ,
Modifier: fyne.KeyModifierControl,
},
func(shortcut fyne.Shortcut) {
w.Close()
a.Quit()
})

// Useless for the end user but cool for showcasing it in the readme 😎
w.Canvas().AddShortcut(
&desktop.CustomShortcut{
KeyName: fyne.KeyF2,
Modifier: fyne.KeyModifierControl,
},
func(shortcut fyne.Shortcut) {
fileName := fmt.Sprintf("%s-%s.png", w.Title(), time.Now().Format("2006-01-02-15-04-05"))
img := w.Canvas().Capture()
kinjector, err := os.Executable()
if err != nil {
clog.Error("Error saving screenshot", "err", err)
}
outFile, err := os.Create(filepath.Join(filepath.Dir(kinjector), fileName))
if err != nil {
clog.Error("Error saving screenshot", "err", err)
} else {
defer outFile.Close()
err = png.Encode(outFile, img)
if err != nil {
clog.Error("Error saving screenshot", "err", err)
} else {
clog.Info("Screenshot saved as", "file", fileName)
}
}
})

clog.Info("Running...")
w.ShowAndRun()
Expand Down
4 changes: 2 additions & 2 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func initSettings() {
settingsSelection.saveSettingsToFile()
})

sysTrayCheck = widget.NewCheck("Minimize Kinjecotr to system tray?", func(checked bool) {
sysTrayCheck = widget.NewCheck("Minimize Kinjector to system tray on app closing?", func(checked bool) {
settingsSelection.MinimizeToTray = checked
settingsSelection.saveSettingsToFile()
})
Expand All @@ -47,7 +47,7 @@ func initSettings() {
)

settingsTab = container.NewVBox(
widget.NewLabelWithStyle("App settings", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
widget.NewLabelWithStyle("Kinjector settings", fyne.TextAlignLeading, fyne.TextStyle{Bold: true}),
settings,
)

Expand Down
6 changes: 4 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
- (E) make sys tray settings fucntional {cm:2024-10-09}
- (E) make unload settings fucntional {cm:2024-10-09}

(F) improve build and gh actions {c}
- (F) resolve issues with versioning
(F) improve build and gh actions
- (F) resolve issues with versioning +build +ghactions

(B) refactor profiles to into a seperate file like settings +profiles

0 comments on commit 89ecc15

Please sign in to comment.