Первая версия (CLI-only) #1
@@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
App AppConfig `mapstructure:"app"`
|
App AppConfig `mapstructure:"app"`
|
||||||
|
Screenshot ScreenshotConfig `mapstructure:"screenshot"`
|
||||||
Communication CommunicationConfig `mapstructure:"communication"`
|
Communication CommunicationConfig `mapstructure:"communication"`
|
||||||
Telemetry TelemetryConfig `mapstructure:"telemetry"`
|
Telemetry TelemetryConfig `mapstructure:"telemetry"`
|
||||||
Logging LoggingConfig `mapstructure:"logging"`
|
Logging LoggingConfig `mapstructure:"logging"`
|
||||||
@@ -44,6 +45,13 @@ type AppConfig struct {
|
|||||||
EnableCheckingUpdates bool `mapstructure:"enable_checking_updates"`
|
EnableCheckingUpdates bool `mapstructure:"enable_checking_updates"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ScreenshotConfig struct {
|
||||||
|
ScreenIndex int `mapstructure:"screen_index"`
|
||||||
|
Interval int `mapstructure:"interval"`
|
||||||
|
Directory string `mapstructure:"directory"`
|
||||||
|
BufferCount int `mapstructure:"buffer_count"`
|
||||||
|
}
|
||||||
|
|
||||||
type CommunicationConfig struct {
|
type CommunicationConfig struct {
|
||||||
QrUrl string `mapstructure:"self_approve_url"`
|
QrUrl string `mapstructure:"self_approve_url"`
|
||||||
QrQueryToken string `mapstructure:"qr_query_token"`
|
QrQueryToken string `mapstructure:"qr_query_token"`
|
||||||
@@ -60,6 +68,10 @@ type LoggingConfig struct {
|
|||||||
Output string `mapstructure:"output"`
|
Output string `mapstructure:"output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTempDirectoryPath() string {
|
||||||
|
return os.TempDir()
|
||||||
|
}
|
||||||
|
|
||||||
func getDefaultConfig() Config {
|
func getDefaultConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
App: AppConfig{
|
App: AppConfig{
|
||||||
@@ -70,6 +82,12 @@ func getDefaultConfig() Config {
|
|||||||
Browser: "firefox",
|
Browser: "firefox",
|
||||||
EnableCheckingUpdates: true,
|
EnableCheckingUpdates: true,
|
||||||
},
|
},
|
||||||
|
Screenshot: ScreenshotConfig{
|
||||||
|
ScreenIndex: 0,
|
||||||
|
Interval: 5,
|
||||||
|
Directory: getTempDirectoryPath(),
|
||||||
|
BufferCount: 5,
|
||||||
|
},
|
||||||
Logging: LoggingConfig{
|
Logging: LoggingConfig{
|
||||||
Level: "info",
|
Level: "info",
|
||||||
Output: "stdout",
|
Output: "stdout",
|
||||||
@@ -117,6 +135,11 @@ func initializeViper(appName string) (*viper.Viper, string, error) {
|
|||||||
v.SetDefault("app.browser", defaults.App.Browser)
|
v.SetDefault("app.browser", defaults.App.Browser)
|
||||||
v.SetDefault("app.enable_checking_updates", defaults.App.EnableCheckingUpdates)
|
v.SetDefault("app.enable_checking_updates", defaults.App.EnableCheckingUpdates)
|
||||||
|
|
||||||
|
v.SetDefault("screenshot.screen_index", defaults.Screenshot.ScreenIndex)
|
||||||
|
v.SetDefault("screenshot.interval", defaults.Screenshot.Interval)
|
||||||
|
v.SetDefault("screenshot.directory", defaults.Screenshot.Directory)
|
||||||
|
v.SetDefault("screenshot.buffer_count", defaults.Screenshot.BufferCount)
|
||||||
|
|
||||||
v.SetDefault("logging.level", defaults.Logging.Level)
|
v.SetDefault("logging.level", defaults.Logging.Level)
|
||||||
v.SetDefault("logging.output", defaults.Logging.Output)
|
v.SetDefault("logging.output", defaults.Logging.Output)
|
||||||
|
|
||||||
@@ -127,35 +150,40 @@ func initializeViper(appName string) (*viper.Viper, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Save() error {
|
func (c *Config) Save() error {
|
||||||
v, _, err := initializeViper(constants.AppName)
|
v, _, err := initializeViper(constants.AppName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to initialize viper: %w", err)
|
return fmt.Errorf("failed to initialize viper: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
v.Set("app.settings_reviewed", c.App.SettingsReviewed)
|
v.Set("app.settings_reviewed", c.App.SettingsReviewed)
|
||||||
v.Set("app.enable_alarm", c.App.EnableAlarm)
|
v.Set("app.enable_alarm", c.App.EnableAlarm)
|
||||||
v.Set("app.enable_link_opening", c.App.EnableLinkOpening)
|
v.Set("app.enable_link_opening", c.App.EnableLinkOpening)
|
||||||
v.Set("app.use_attendance_journal_api", c.App.UseAttendanceJounralApi)
|
v.Set("app.use_attendance_journal_api", c.App.UseAttendanceJounralApi)
|
||||||
v.Set("app.browser", c.App.Browser)
|
v.Set("app.browser", c.App.Browser)
|
||||||
v.Set("app.enable_checking_updates", c.App.EnableCheckingUpdates)
|
v.Set("app.enable_checking_updates", c.App.EnableCheckingUpdates)
|
||||||
|
|
||||||
v.Set("logging.level", c.Logging.Level)
|
v.Set("screenshot.screen_index", c.Screenshot.ScreenIndex)
|
||||||
v.Set("logging.output", c.Logging.Output)
|
v.Set("screenshot.interval", c.Screenshot.Interval)
|
||||||
|
v.Set("screenshot.directory", c.Screenshot.Directory)
|
||||||
|
v.Set("screenshot.buffer_count", c.Screenshot.BufferCount)
|
||||||
|
|
||||||
v.Set("telemetry.enable_statistics_collection", c.Telemetry.EnableStatisticsCollection)
|
v.Set("logging.level", c.Logging.Level)
|
||||||
v.Set("telemetry.enable_anonymous_error_reports", c.Telemetry.EnableAnonymousErrorReports)
|
v.Set("logging.output", c.Logging.Output)
|
||||||
|
|
||||||
if c.Communication.QrUrl != "" {
|
v.Set("telemetry.enable_statistics_collection", c.Telemetry.EnableStatisticsCollection)
|
||||||
v.Set("communication.self_approve_url", c.Communication.QrUrl)
|
v.Set("telemetry.enable_anonymous_error_reports", c.Telemetry.EnableAnonymousErrorReports)
|
||||||
}
|
|
||||||
if c.Communication.QrQueryToken != "" {
|
|
||||||
v.Set("communication.qr_query_token", c.Communication.QrQueryToken)
|
|
||||||
}
|
|
||||||
if c.Communication.ApiSelfApproveMethod != "" {
|
|
||||||
v.Set("communication.api_self_approve_method", c.Communication.ApiSelfApproveMethod)
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.WriteConfig()
|
if c.Communication.QrUrl != "" {
|
||||||
|
v.Set("communication.self_approve_url", c.Communication.QrUrl)
|
||||||
|
}
|
||||||
|
if c.Communication.QrQueryToken != "" {
|
||||||
|
v.Set("communication.qr_query_token", c.Communication.QrQueryToken)
|
||||||
|
}
|
||||||
|
if c.Communication.ApiSelfApproveMethod != "" {
|
||||||
|
v.Set("communication.api_self_approve_method", c.Communication.ApiSelfApproveMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v.WriteConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
|
|||||||
26
src/internal/screencapturer/interface.go
Normal file
26
src/internal/screencapturer/interface.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (c) 2025 Nikolai Papin
|
||||||
|
//
|
||||||
|
// This file is part of the Auto Attendance app that looks for
|
||||||
|
// self-attend QR-codes during lectures and opens their URLs in your
|
||||||
|
// browser.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||||
|
// the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package screencapturer
|
||||||
|
|
||||||
|
type ScreenCapturer interface {
|
||||||
|
Start() error
|
||||||
|
Stop() error
|
||||||
|
Screenshot() (filepath string)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user