feat: add custom sound upload and fix localization
This commit is contained in:
@@ -508,3 +508,105 @@ func (a *App) DownloadAndInstallUpdate() error {
|
||||
func (a *App) RestartApp() error {
|
||||
return a.updater.RestartApp()
|
||||
}
|
||||
|
||||
// Sound Management
|
||||
|
||||
func (a *App) getSoundsDir() (string, error) {
|
||||
configDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
soundsDir := filepath.Join(configDir, "DailyTimer", "sounds")
|
||||
if err := os.MkdirAll(soundsDir, 0755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return soundsDir, nil
|
||||
}
|
||||
|
||||
func (a *App) SelectCustomSound(soundType string) (string, error) {
|
||||
// Validate sound type
|
||||
validTypes := map[string]bool{"warning": true, "timeup": true, "meeting_end": true}
|
||||
if !validTypes[soundType] {
|
||||
return "", fmt.Errorf("invalid sound type: %s", soundType)
|
||||
}
|
||||
|
||||
// Open file dialog
|
||||
selection, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
|
||||
Title: "Select Sound File",
|
||||
Filters: []runtime.FileFilter{
|
||||
{DisplayName: "Audio Files", Pattern: "*.mp3;*.wav;*.m4a;*.ogg"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if selection == "" {
|
||||
return "", nil // User cancelled
|
||||
}
|
||||
|
||||
// Get sounds directory
|
||||
soundsDir, err := a.getSoundsDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Determine destination filename
|
||||
ext := filepath.Ext(selection)
|
||||
destPath := filepath.Join(soundsDir, soundType+ext)
|
||||
|
||||
// Copy file
|
||||
src, err := os.Open(selection)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer func() { _ = src.Close() }()
|
||||
|
||||
dst, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer func() { _ = dst.Close() }()
|
||||
|
||||
if _, err := dst.ReadFrom(src); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return destPath, nil
|
||||
}
|
||||
|
||||
func (a *App) GetCustomSoundPath(soundType string) string {
|
||||
soundsDir, err := a.getSoundsDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Check for common audio extensions
|
||||
extensions := []string{".mp3", ".wav", ".m4a", ".ogg"}
|
||||
for _, ext := range extensions {
|
||||
path := filepath.Join(soundsDir, soundType+ext)
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (a *App) ClearCustomSound(soundType string) error {
|
||||
soundsDir, err := a.getSoundsDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
extensions := []string{".mp3", ".wav", ".m4a", ".ogg"}
|
||||
for _, ext := range extensions {
|
||||
path := filepath.Join(soundsDir, soundType+ext)
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
if err := os.Remove(path); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user