Первая версия (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 {
ScreenIndex int `mapstructure:"screen_index"`
Interval int `mapstructure:"interval"`
ScreenIndex int `mapstructure:"screen_index"`
Interval int `mapstructure:"interval"`
Directory string `mapstructure:"directory"`
BufferCount int `mapstructure:"buffer_count"`
BufferCount int `mapstructure:"buffer_count"`
}
type CommunicationConfig struct {
@@ -84,8 +84,8 @@ func getDefaultConfig() Config {
},
Screenshot: ScreenshotConfig{
ScreenIndex: 0,
Interval: 5,
Directory: getTempDirectoryPath(),
Interval: 5,
Directory: getTempDirectoryPath(),
BufferCount: 5,
},
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)
if err == nil {
if parsedURL.Scheme != expectedURL.Scheme ||
parsedURL.Host != expectedURL.Host ||
parsedURL.Path != expectedURL.Path {
parsedURL.Host != expectedURL.Host ||
parsedURL.Path != expectedURL.Path {
v.log.Debug("URL doesn't match configured QR URL pattern",
"url", rawURL, "expected", v.config.Communication.QrUrl)
return "", false

View File

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

View File

@@ -42,6 +42,7 @@ var (
// AnalyzeImage implements Vision.
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)
img := gocv.IMRead(filePath, gocv.IMReadColor)