feat: implement custom attachment download feature with folder selection and automatic opening of Explorer
This commit is contained in:
56
main.go
56
main.go
@@ -4,11 +4,14 @@ import (
|
||||
"embed"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/options"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||
"github.com/wailsapp/wails/v2/pkg/options/windows"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
@@ -33,6 +36,12 @@ func main() {
|
||||
}
|
||||
defer CloseLogger()
|
||||
|
||||
// Load config.ini to get WebView2 paths
|
||||
configPath := filepath.Join(filepath.Dir(os.Args[0]), "config.ini")
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
configPath = "config.ini" // fallback to current directory
|
||||
}
|
||||
|
||||
// Check for custom args
|
||||
args := os.Args
|
||||
uniqueId := "emly-app-lock"
|
||||
@@ -74,6 +83,49 @@ func main() {
|
||||
}
|
||||
|
||||
// Create application with options
|
||||
// Configure WebView2 DataPath (user data folder)
|
||||
userDataPath := filepath.Join(os.Getenv("APPDATA"), "EMLy") // default
|
||||
downloadPath := filepath.Join(os.Getenv("USERPROFILE"), "Downloads") // default
|
||||
|
||||
// Helper function to expand Windows-style environment variables
|
||||
expandEnvVars := func(path string) string {
|
||||
// Match %%VAR%% or %VAR% patterns and replace with actual values
|
||||
re := regexp.MustCompile(`%%([^%]+)%%|%([^%]+)%`)
|
||||
return re.ReplaceAllStringFunc(path, func(match string) string {
|
||||
varName := strings.Trim(match, "%")
|
||||
return os.Getenv(varName)
|
||||
})
|
||||
}
|
||||
|
||||
// Load paths from config.ini if available
|
||||
if cfg, err := os.ReadFile(configPath); err == nil {
|
||||
// Simple INI parsing for these specific values
|
||||
lines := strings.Split(string(cfg), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "WEBVIEW2_USERDATA_PATH") {
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
path := strings.TrimSpace(parts[1])
|
||||
if path != "" {
|
||||
userDataPath = expandEnvVars(path)
|
||||
}
|
||||
}
|
||||
} else if strings.HasPrefix(line, "WEBVIEW2_DOWNLOAD_PATH") {
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
path := strings.TrimSpace(parts[1])
|
||||
if path != "" {
|
||||
downloadPath = expandEnvVars(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("WebView2 UserDataPath: %s", userDataPath)
|
||||
log.Printf("WebView2 DownloadPath: %s", downloadPath)
|
||||
|
||||
err := wails.Run(&options.App{
|
||||
Title: windowTitle,
|
||||
Width: windowWidth,
|
||||
@@ -94,6 +146,10 @@ func main() {
|
||||
MinWidth: 964,
|
||||
MinHeight: 690,
|
||||
Frameless: frameless,
|
||||
Windows: &windows.Options{
|
||||
WebviewUserDataPath: userDataPath,
|
||||
WebviewBrowserPath: "", // Empty = use system Edge WebView2
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user