Первая версия (CLI-only) #1

Merged
weirdcat merged 26 commits from develop into main 2025-11-27 13:09:27 +03:00
8 changed files with 29 additions and 27 deletions
Showing only changes of commit a857f12cb5 - Show all commits

View File

@@ -46,10 +46,10 @@ type AppConfig struct {
} }
type ScreenshotConfig struct { type ScreenshotConfig struct {
ScreenIndex int `mapstructure:"screen_index"` ScreenIndex int `mapstructure:"screen_index"`
Interval int `mapstructure:"interval"` Interval int `mapstructure:"interval"`
Directory string `mapstructure:"directory"` Directory string `mapstructure:"directory"`
BufferCount int `mapstructure:"buffer_count"` BufferCount int `mapstructure:"buffer_count"`
} }
type CommunicationConfig struct { type CommunicationConfig struct {
@@ -84,8 +84,8 @@ func getDefaultConfig() Config {
}, },
Screenshot: ScreenshotConfig{ Screenshot: ScreenshotConfig{
ScreenIndex: 0, ScreenIndex: 0,
Interval: 5, Interval: 5,
Directory: getTempDirectoryPath(), Directory: getTempDirectoryPath(),
BufferCount: 5, BufferCount: 5,
}, },
Logging: LoggingConfig{ Logging: LoggingConfig{

View File

@@ -53,8 +53,8 @@ func (v *linkValidatorImpl) ValidateLink(rawURL string) (token string, ok bool)
expectedURL, err := url.Parse(v.config.Communication.QrUrl) expectedURL, err := url.Parse(v.config.Communication.QrUrl)
if err == nil { if err == nil {
if parsedURL.Scheme != expectedURL.Scheme || if parsedURL.Scheme != expectedURL.Scheme ||
parsedURL.Host != expectedURL.Host || parsedURL.Host != expectedURL.Host ||
parsedURL.Path != expectedURL.Path { parsedURL.Path != expectedURL.Path {
v.log.Debug("URL doesn't match configured QR URL pattern", v.log.Debug("URL doesn't match configured QR URL pattern",
"url", rawURL, "expected", v.config.Communication.QrUrl) "url", rawURL, "expected", v.config.Communication.QrUrl)
return "", false return "", false

View File

@@ -43,15 +43,15 @@ var (
type wholeScreenCapturer struct { type wholeScreenCapturer struct {
config *config.Config config *config.Config
log *logger.Logger log *logger.Logger
displayIndex int displayIndex int
displayBounds image.Rectangle displayBounds image.Rectangle
interval int interval int
bufferCount int bufferCount int
tempDirectory string tempDirectory string
initialized bool initialized bool
running bool running bool
files []string files []string
latest string latest string
@@ -189,7 +189,7 @@ func (w *wholeScreenCapturer) captureAndSave() (string, error) {
func (w *wholeScreenCapturer) addToBuffer(fp string) { func (w *wholeScreenCapturer) addToBuffer(fp string) {
w.mu.Lock() w.mu.Lock()
defer w.mu.Unlock() defer w.mu.Unlock()
w.files = append(w.files, fp) w.files = append(w.files, fp)
w.latest = fp w.latest = fp
@@ -208,14 +208,16 @@ func (w *wholeScreenCapturer) createTempDirectory() (path string, err error) {
return os.MkdirTemp(w.config.Screenshot.Directory, constants.AppName+"-*") return os.MkdirTemp(w.config.Screenshot.Directory, constants.AppName+"-*")
} }
func NewWholeScreenCapturer(lc fx.Lifecycle, config *config.Config, log *logger.Logger) ScreenCapturer { func NewWholeScreenCapturer(
lc fx.Lifecycle, config *config.Config, log *logger.Logger,
) ScreenCapturer {
capturer := &wholeScreenCapturer{ capturer := &wholeScreenCapturer{
config: config, config: config,
log: log, log: log,
done: make(chan struct{}), done: make(chan struct{}),
} }
lc.Append(fx.StopHook(func(ctx context.Context) error { lc.Append(fx.StopHook(func(ctx context.Context) error {
if (!capturer.initialized) { if !capturer.initialized {
log.Debug("wholescreencapturer not initialized, nothing to do") log.Debug("wholescreencapturer not initialized, nothing to do")
return nil return nil
} }
@@ -237,4 +239,3 @@ func NewWholeScreenCapturer(lc fx.Lifecycle, config *config.Config, log *logger.
})) }))
return capturer return capturer
} }

View File

@@ -42,6 +42,7 @@ var (
// AnalyzeImage implements Vision. // AnalyzeImage implements Vision.
func (v *visionImpl) AnalyzeImage(filePath string) (data VisionData, err error) { func (v *visionImpl) AnalyzeImage(filePath string) (data VisionData, err error) {
// TODO: scanning for multiple QR-codes at once
v.log.Debug("analyzing image for qr codes", "filePath", filePath) v.log.Debug("analyzing image for qr codes", "filePath", filePath)
img := gocv.IMRead(filePath, gocv.IMReadColor) img := gocv.IMRead(filePath, gocv.IMReadColor)