@@ -13,6 +13,9 @@ const EXEC_PATH: &str = "Contents/MacOS";
1313const FRAMEWORKS_PATH : & str = "Contents/Frameworks" ;
1414const RESOURCES_PATH : & str = "Contents/Resources" ;
1515const CEF_FRAMEWORK : & str = "Chromium Embedded Framework.framework" ;
16+ const GRAPHITE_DOCUMENT_TYPE : & str = "art.graphite.document" ;
17+ const GRAPHITE_FILE_EXTENSION : & str = "graphite" ;
18+ const GRAPHITE_MIME_TYPE : & str = "application/graphite+json" ;
1619
1720pub fn main ( ) -> Result < ( ) , Box < dyn Error > > {
1821 let app_bin = build_bin ( "graphite-desktop-platform-mac" , None ) ?;
@@ -73,7 +76,7 @@ fn create_info_plist(dir: &Path, id: &str, exec_name: &str, is_helper: bool) ->
7376 cf_bundle_identifier : id. to_string ( ) ,
7477 cf_bundle_display_name : exec_name. to_string ( ) ,
7578 cf_bundle_executable : exec_name. to_string ( ) ,
76- cf_bundle_icon_file : ICONS_FILE_NAME . to_string ( ) ,
79+ cf_bundle_icon_file : if is_helper { None } else { Some ( ICONS_FILE_NAME . to_string ( ) ) } ,
7780 cf_bundle_info_dictionary_version : "6.0" . to_string ( ) ,
7881 cf_bundle_package_type : "APPL" . to_string ( ) ,
7982 cf_bundle_signature : "????" . to_string ( ) ,
@@ -85,13 +88,56 @@ fn create_info_plist(dir: &Path, id: &str, exec_name: &str, is_helper: bool) ->
8588 ls_minimum_system_version : "11.0" . to_string ( ) ,
8689 ls_ui_element : if is_helper { Some ( "1" . to_string ( ) ) } else { None } ,
8790 ns_supports_automatic_graphics_switching : true ,
91+ cf_bundle_document_types : ( !is_helper) . then ( document_types) ,
92+ ut_exported_type_declarations : ( !is_helper) . then ( exported_type_declarations) ,
8893 } ;
8994
9095 let plist_file = dir. join ( "Info.plist" ) ;
9196 plist:: to_file_xml ( plist_file, & info) ?;
9297 Ok ( ( ) )
9398}
9499
100+ fn document_types ( ) -> Vec < DocumentType > {
101+ vec ! [
102+ DocumentType {
103+ cf_bundle_type_name: "Graphite Document" . to_string( ) ,
104+ cf_bundle_type_role: "Editor" . to_string( ) ,
105+ cf_bundle_type_extensions: Some ( vec![ GRAPHITE_FILE_EXTENSION . to_string( ) ] ) ,
106+ cf_bundle_type_icon_file: Some ( ICONS_FILE_NAME . to_string( ) ) ,
107+ ls_handler_rank: Some ( "Owner" . to_string( ) ) ,
108+ ls_item_content_types: vec![ GRAPHITE_DOCUMENT_TYPE . to_string( ) ] ,
109+ } ,
110+ DocumentType {
111+ cf_bundle_type_name: "SVG Image" . to_string( ) ,
112+ cf_bundle_type_role: "Editor" . to_string( ) ,
113+ cf_bundle_type_extensions: Some ( vec![ "svg" . to_string( ) ] ) ,
114+ cf_bundle_type_icon_file: None ,
115+ ls_handler_rank: Some ( "Alternate" . to_string( ) ) ,
116+ ls_item_content_types: vec![ "public.svg-image" . to_string( ) ] ,
117+ } ,
118+ DocumentType {
119+ cf_bundle_type_name: "Image" . to_string( ) ,
120+ cf_bundle_type_role: "Editor" . to_string( ) ,
121+ cf_bundle_type_extensions: None ,
122+ cf_bundle_type_icon_file: None ,
123+ ls_handler_rank: Some ( "Alternate" . to_string( ) ) ,
124+ ls_item_content_types: vec![ "public.image" . to_string( ) ] ,
125+ } ,
126+ ]
127+ }
128+
129+ fn exported_type_declarations ( ) -> Vec < ExportedTypeDeclaration > {
130+ vec ! [ ExportedTypeDeclaration {
131+ ut_type_identifier: GRAPHITE_DOCUMENT_TYPE . to_string( ) ,
132+ ut_type_description: "Graphite Document" . to_string( ) ,
133+ ut_type_conforms_to: vec![ "public.json" . to_string( ) ] ,
134+ ut_type_tag_specification: TypeTagSpecification {
135+ public_filename_extension: vec![ GRAPHITE_FILE_EXTENSION . to_string( ) ] ,
136+ public_mime_type: GRAPHITE_MIME_TYPE . to_string( ) ,
137+ } ,
138+ } ]
139+ }
140+
95141#[ derive( serde:: Serialize ) ]
96142struct InfoPlist {
97143 #[ serde( rename = "CFBundleName" ) ]
@@ -103,7 +149,8 @@ struct InfoPlist {
103149 #[ serde( rename = "CFBundleExecutable" ) ]
104150 cf_bundle_executable : String ,
105151 #[ serde( rename = "CFBundleIconFile" ) ]
106- cf_bundle_icon_file : String ,
152+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
153+ cf_bundle_icon_file : Option < String > ,
107154 #[ serde( rename = "CFBundleInfoDictionaryVersion" ) ]
108155 cf_bundle_info_dictionary_version : String ,
109156 #[ serde( rename = "CFBundlePackageType" ) ]
@@ -123,7 +170,53 @@ struct InfoPlist {
123170 #[ serde( rename = "LSMinimumSystemVersion" ) ]
124171 ls_minimum_system_version : String ,
125172 #[ serde( rename = "LSUIElement" ) ]
173+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
126174 ls_ui_element : Option < String > ,
127175 #[ serde( rename = "NSSupportsAutomaticGraphicsSwitching" ) ]
128176 ns_supports_automatic_graphics_switching : bool ,
177+ #[ serde( rename = "CFBundleDocumentTypes" ) ]
178+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
179+ cf_bundle_document_types : Option < Vec < DocumentType > > ,
180+ #[ serde( rename = "UTExportedTypeDeclarations" ) ]
181+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
182+ ut_exported_type_declarations : Option < Vec < ExportedTypeDeclaration > > ,
183+ }
184+
185+ #[ derive( serde:: Serialize ) ]
186+ struct DocumentType {
187+ #[ serde( rename = "CFBundleTypeName" ) ]
188+ cf_bundle_type_name : String ,
189+ #[ serde( rename = "CFBundleTypeRole" ) ]
190+ cf_bundle_type_role : String ,
191+ #[ serde( rename = "CFBundleTypeExtensions" ) ]
192+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
193+ cf_bundle_type_extensions : Option < Vec < String > > ,
194+ #[ serde( rename = "CFBundleTypeIconFile" ) ]
195+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
196+ cf_bundle_type_icon_file : Option < String > ,
197+ #[ serde( rename = "LSHandlerRank" ) ]
198+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
199+ ls_handler_rank : Option < String > ,
200+ #[ serde( rename = "LSItemContentTypes" ) ]
201+ ls_item_content_types : Vec < String > ,
202+ }
203+
204+ #[ derive( serde:: Serialize ) ]
205+ struct ExportedTypeDeclaration {
206+ #[ serde( rename = "UTTypeIdentifier" ) ]
207+ ut_type_identifier : String ,
208+ #[ serde( rename = "UTTypeDescription" ) ]
209+ ut_type_description : String ,
210+ #[ serde( rename = "UTTypeConformsTo" ) ]
211+ ut_type_conforms_to : Vec < String > ,
212+ #[ serde( rename = "UTTypeTagSpecification" ) ]
213+ ut_type_tag_specification : TypeTagSpecification ,
214+ }
215+
216+ #[ derive( serde:: Serialize ) ]
217+ struct TypeTagSpecification {
218+ #[ serde( rename = "public.filename-extension" ) ]
219+ public_filename_extension : Vec < String > ,
220+ #[ serde( rename = "public.mime-type" ) ]
221+ public_mime_type : String ,
129222}
0 commit comments