mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Implement file association Open a file from Finder/Explorer (#2918)
* implement MacOS openFile/openFiles events * wip: windows file association * fix macro import * add file icon copy * try copy icon * keep only required part of scripts * update config schema * fix json * set fileAssociation for mac via config * proper iconName handling * add fileAssociation icon generator * fix file association icons bundle * don't break compatibility * remove mimeType as not supported linux for now * add documentation * adjust config schema * restore formatting * remove unused option in file association * get rid of openFiles mac os. change configuration structure * remove unused channel * fix documentation * fix typo --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
co-authored by
Lea Anthony
parent
42708e7f40
commit
6c46f6b41c
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/leaanthony/winicon"
|
||||
"github.com/tc-hib/winres"
|
||||
"github.com/tc-hib/winres/version"
|
||||
"github.com/wailsapp/wails/v2/internal/project"
|
||||
"image"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -95,12 +96,20 @@ func packageApplicationForDarwin(options *Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Generate Icons
|
||||
err = processApplicationIcon(options, resourceDir)
|
||||
// Generate App Icon
|
||||
err = processDarwinIcon(options.ProjectData, "appicon", resourceDir, "iconfile")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Generate FileAssociation Icons
|
||||
for _, fileAssociation := range options.ProjectData.Info.FileAssociations {
|
||||
err = processDarwinIcon(options.ProjectData, fileAssociation.IconName, resourceDir, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
options.CompiledBinary = packedBinaryPath
|
||||
|
||||
return nil
|
||||
@@ -124,8 +133,8 @@ func processPList(options *Options, contentsDirectory string) error {
|
||||
return os.WriteFile(targetFile, content, 0644)
|
||||
}
|
||||
|
||||
func processApplicationIcon(options *Options, resourceDir string) (err error) {
|
||||
appIcon, err := buildassets.ReadFile(options.ProjectData, "appicon.png")
|
||||
func processDarwinIcon(projectData *project.Project, iconName string, resourceDir string, destIconName string) (err error) {
|
||||
appIcon, err := buildassets.ReadFile(projectData, iconName+".png")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -135,7 +144,11 @@ func processApplicationIcon(options *Options, resourceDir string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
tgtBundle := filepath.Join(resourceDir, "iconfile.icns")
|
||||
if destIconName == "" {
|
||||
destIconName = iconName
|
||||
}
|
||||
|
||||
tgtBundle := filepath.Join(resourceDir, destIconName+".icns")
|
||||
dest, err := os.Create(tgtBundle)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -151,13 +164,21 @@ func processApplicationIcon(options *Options, resourceDir string) (err error) {
|
||||
}
|
||||
|
||||
func packageApplicationForWindows(options *Options) error {
|
||||
// Generate icon
|
||||
// Generate app icon
|
||||
var err error
|
||||
err = generateIcoFile(options)
|
||||
err = generateIcoFile(options, "appicon", "icon")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Generate FileAssociation Icons
|
||||
for _, fileAssociation := range options.ProjectData.Info.FileAssociations {
|
||||
err = generateIcoFile(options, fileAssociation.IconName, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Create syso file
|
||||
err = compileResources(options)
|
||||
if err != nil {
|
||||
@@ -171,13 +192,18 @@ func packageApplicationForLinux(_ *Options) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateIcoFile(options *Options) error {
|
||||
content, err := buildassets.ReadFile(options.ProjectData, "appicon.png")
|
||||
func generateIcoFile(options *Options, iconName string, destIconName string) error {
|
||||
content, err := buildassets.ReadFile(options.ProjectData, iconName+".png")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if destIconName == "" {
|
||||
destIconName = iconName
|
||||
}
|
||||
|
||||
// Check ico file exists already
|
||||
icoFile := buildassets.GetLocalPath(options.ProjectData, "windows/icon.ico")
|
||||
icoFile := buildassets.GetLocalPath(options.ProjectData, "windows/"+destIconName+".ico")
|
||||
if !fs.FileExists(icoFile) {
|
||||
if dir := filepath.Dir(icoFile); !fs.DirExists(dir) {
|
||||
if err := fs.MkDirs(dir, 0755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user