Skip to content

Commit dee7a60

Browse files
authored
Duplicate file associations code from the app template (#82)
See briefcase-macOS-app-template#72
1 parent 42dab3c commit dee7a60

1 file changed

Lines changed: 50 additions & 28 deletions

File tree

  • {{ cookiecutter.format }}/{{ cookiecutter.class_name }}

{{ cookiecutter.format }}/{{ cookiecutter.class_name }}/Info.plist

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,81 @@
3030
<string>NSApplication</string>
3131
<key>MainModule</key>
3232
<string>{{ cookiecutter.module_name }}</string>
33-
{% if cookiecutter.document_types %}
33+
{% if cookiecutter.document_types -%}
3434
<key>CFBundleDocumentTypes</key>
3535
<array>
36-
{% for extension, doctype in cookiecutter.document_types.items() %}
36+
{% for document_type_id, document_type in cookiecutter.document_types.items() -%}
37+
{% set macOS = document_type.macOS | default({}) -%}
3738
<dict>
3839
<key>CFBundleTypeName</key>
39-
<string>{{ doctype.description }}</string>
40+
<string>{{ document_type.description }}</string>
4041
<key>CFBundleTypeIconFile</key>
41-
<string>{{ cookiecutter.app_name }}-{{ extension }}.icns</string>
42-
<key>CFBundleTypeExtensions</key>
43-
<array>
44-
<string>{{ extension }}</string>
45-
</array>
46-
<key>CFBundleTypeMIMETypes</key>
47-
<array/>
42+
<string>{{ cookiecutter.app_name }}-{{ document_type_id }}.icns</string>
4843
<key>CFBundleTypeRole</key>
49-
<string>Viewer</string>
44+
<string>{{ macOS.CFBundleTypeRole }}</string>
45+
<key>LSHandlerRank</key>
46+
<string>{{ macOS.LSHandlerRank }}</string>
5047
<key>LSItemContentTypes</key>
5148
<array>
52-
<string>{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}.{{ extension }}</string>
49+
{%- if macOS.LSItemContentTypes is defined %}
50+
<string>{{ macOS.LSItemContentTypes[0] }}</string>
51+
{%- else %}
52+
<string>{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}.{{ document_type_id }}</string>
53+
{%- endif %}
5354
</array>
54-
<key>LSTypeIsPackage</key>
55-
<integer>1</integer>
5655
</dict>
5756
{% endfor %}
5857
</array>
59-
<key>UTExportedTypeDeclarations</key>
60-
<array>
61-
{% for doctype_id, doctype in cookiecutter.document_types.items() %}
58+
{%- macro type_declaration(cookiecutter, document_type_id, document_type, macOS) -%}
6259
<dict>
63-
<key>UTTypeIdentifier</key>
64-
<string>{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}.{{ doctype_id }}</string>
65-
<key>UTTypeReferenceURL</key>
66-
<string>{{ doctype.url }}</string>
67-
<key>UTTypeIconFile</key>
68-
<string>{{ cookiecutter.app_name }}-{{ doctype_id }}.icns</string>
6960
<key>UTTypeConformsTo</key>
7061
<array>
71-
<string>com.apple.package</string>
62+
{%- for type in macOS.UTTypeConformsTo %}
63+
<string>{{ type }}</string>
64+
{%- endfor %}
7265
</array>
7366
<key>UTTypeDescription</key>
74-
<string>{{ doctype.description }}</string>
67+
<string>{{ document_type.description }}</string>
68+
<key>UTTypeIconFile</key>
69+
<string>{{ cookiecutter.app_name }}-{{ document_type_id }}.icns</string>
70+
<key>UTTypeIdentifier</key>
71+
{% if macOS.LSItemContentTypes is defined -%}
72+
<string>{{ macOS.LSItemContentTypes[0] }}</string>
73+
{%- else -%}
74+
<string>{{ cookiecutter.bundle }}.{{ cookiecutter.app_name }}.{{ document_type_id }}</string>
75+
{%- endif %}
76+
<key>UTTypeReferenceURL</key>
77+
<string>{{ document_type.url }}</string>
7578
<key>UTTypeTagSpecification</key>
7679
<dict>
7780
<key>public.filename-extension</key>
7881
<array>
79-
<string>{{ doctype.extension }}</string>
82+
<string>{{ document_type.extension }}</string>
8083
</array>
84+
<key>public.mime-type</key>
85+
<string>{% if document_type.get('mime_type') %}{{ document_type.mime_type }}{% else %}application/x-{{ cookiecutter.app_name }}-{{ document_type_id }}{% endif %}</string>
8186
</dict>
8287
</dict>
83-
{% endfor %}
88+
{% endmacro %}
89+
<key>UTExportedTypeDeclarations</key>
90+
<array>
91+
{% for document_type_id, document_type in cookiecutter.document_types.items() -%}
92+
{% set macOS = document_type.macOS | default({}) -%}
93+
{% if macOS.LSHandlerRank == "Owner" -%}
94+
{{ type_declaration(cookiecutter, document_type_id, document_type, macOS) }}
95+
{%- endif %}
96+
{%- endfor %}
97+
</array>
98+
<key>UTImportedTypeDeclarations</key>
99+
<array>
100+
{% for document_type_id, document_type in cookiecutter.document_types.items() -%}
101+
{% set macOS = document_type.macOS | default({}) -%}
102+
{% if macOS.is_core_type is false and macOS.LSHandlerRank != "Owner" -%}
103+
{{ type_declaration(cookiecutter, document_type_id, document_type, macOS) }}
104+
{%- endif %}
105+
{%- endfor %}
84106
</array>
85-
{% endif %}
107+
{%- endif -%}
86108
{%- if cookiecutter.info -%}
87109
{%- for permission, value in cookiecutter.info.items() %}
88110
<key>{{ permission }}</key>

0 commit comments

Comments
 (0)