generate plist from filetypes and inject into app bundle

This commit is contained in:
2025-05-03 15:43:44 -04:00
parent 4c0d9de1cd
commit b50e13a34e
7 changed files with 407 additions and 120 deletions

58
filetypes/cmd/gen.go Normal file
View File

@@ -0,0 +1,58 @@
package main
import (
"fmt"
"os"
"text/template"
"git.yetaga.in/alazyreader/why/filetypes"
)
func main() {
tpl, err := template.New("template").Parse(tmpl)
if err != nil {
fmt.Println(err)
return
}
fplist, err := os.Create("documentTypes.plist")
if err != nil {
fmt.Println(err)
return
}
defer fplist.Close()
if err := tpl.Execute(fplist, filetypes.Valid); err != nil {
fmt.Println(err)
return
}
}
var tmpl = `
<key>CFBundleDocumentTypes</key>
<array>{{ range . }}
<dict>
<key>CFBundleTypeExtensions</key>
<array>{{ range .MacExtensions }}
<string>{{ . }}</string>{{ end }}
</array>
<key>CFBundleTypeIconFile</key>
<string>{{ .IconFile }}</string>
<key>CFBundleTypeMIMETypes</key>
<array>{{ range .MIMETypes }}
<string>{{ . }}</string>{{ end }}
</array>
<key>CFBundleTypeName</key>
<string>{{ .TypeName }}</string>
<key>CFBundleTypeOSTypes</key>
<array>{{ range .OSTypes }}
<string>{{ . }}</string>{{ end }}
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>{{ .ItemContentTypes }}</string>
</array>
<key>LSTypeIsPackage</key>
<false/>
</dict>{{ end }}
`

86
filetypes/filetypes.go Normal file
View File

@@ -0,0 +1,86 @@
package filetypes
import (
"fmt"
tk "modernc.org/tk9.0"
)
type FileDescription struct {
TkType tk.FileType
MacExtensions []string
IconFile string
MIMETypes []string
TypeName string
OSTypes []string
ItemContentTypes string
}
var Valid = []FileDescription{
{
TkType: tk.FileType{TypeName: "BMP", Extensions: []string{".bmp"}},
MacExtensions: []string{"bmp", "BMP"},
IconFile: "bmp.icns",
MIMETypes: []string{"image/bmp"},
TypeName: "Windows Bitmap Image",
OSTypes: []string{"BMP ", "BMPf"},
ItemContentTypes: "com.microsoft.bmp",
},
{
TkType: tk.FileType{TypeName: "JPEG", Extensions: []string{".jpg", ".jpeg"}},
MacExtensions: []string{"jpg", "JPG", "jpeg", "JPEG"},
IconFile: "jpeg.icns",
MIMETypes: []string{"image/jpeg"},
TypeName: "JPEG Image",
OSTypes: []string{"JPEG"},
ItemContentTypes: "public.jpeg",
},
{
TkType: tk.FileType{TypeName: "GIF", Extensions: []string{".gif"}},
MacExtensions: []string{"gif", "GIF"},
IconFile: "gif.icns",
MIMETypes: []string{"image/gif"},
TypeName: "Graphics Interchange Format Image",
OSTypes: []string{"GIFf"},
ItemContentTypes: "com.compuserve.gif",
},
{
TkType: tk.FileType{TypeName: "PNG", Extensions: []string{".png"}},
MacExtensions: []string{"PNG", "png"},
IconFile: "png.icns",
MIMETypes: []string{"image/png"},
TypeName: "Portable Network Graphics Image",
OSTypes: []string{"PNGf"},
ItemContentTypes: "public.png",
},
{
TkType: tk.FileType{TypeName: "TGA", Extensions: []string{".tga"}},
MacExtensions: []string{"tga", "TGA"},
IconFile: "tga.icns",
MIMETypes: []string{"image/targa", "image/tga", "application/tga"},
TypeName: "Targa Image",
OSTypes: []string{"TPIC"},
ItemContentTypes: "com.truevision.tga-image",
},
{
TkType: tk.FileType{TypeName: "TIFF", Extensions: []string{".tiff"}},
MacExtensions: []string{"tiff", "TIFF", "tif", "TIF"},
IconFile: "tiff.icns",
MIMETypes: []string{"image/tiff"},
TypeName: "TIFF Image",
OSTypes: []string{"TIFF"},
ItemContentTypes: "public.tiff",
},
}
func GetTkTypes(fds []FileDescription) []tk.FileType {
fts := make([]tk.FileType, len(fds))
for i, fd := range fds {
fts[i] = fd.TkType
}
return fts
}
func main() {
fmt.Println("test")
}