forge
forge copied to clipboard
Feature Request: Support file association properties in forge.config.js
Pre-flight checklist
- [X] I have read the contribution documentation for this project.
- [X] I agree to follow the code of conduct that this project uses.
- [X] I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem description
Other electron build systems allow the developer to specify custom file extensions for their built apps. For instance, if I wrote an app that was a editor for "Foo" files, I would want to be able to launch a file with the extension .foo in the system that would then open the application with that file. As a developer I could then handle the file's contents via the app open-file event handler. In addition, .foo files should have their own specific icon.
Currently providing this information via platform-specific configuration files (such as for Windows, OSX, and Linux) is cumbersome and the method for doing so is not always well documented, making cross-platform applications that much more difficult to create.
Proposed solution
I would suggest a set of forge configuration properties such as:
module.exports = {
packagerConfig: {
"fileAssociations": [
{
"ext": "foo",
"name": "Foo File",
"icon": "assets/icon/foofile.icns"
}
],
}
}
...where one or more file associations can be specified.
extis the name of the file extension to associate with one's Electron applicationnameis the label that the platform presents to users in the user interfaceiconis the path to the icon for this type of file
Refer to the fileAssociations section of https://www.electron.build/configuration/configuration.html for more information. Note that their set of configuration properties allows this feature to be used in OSX, Windows, and Linux applications.
Alternatives considered
Currently in order to implement this in OSX, a separate Info.plist file must be provided that contains the correct metadata to enable one or more file associations to work. In Windows a separate file containing file association properties must be generated as well. This is cumbersome for developers, who must currently deal with many sets of documentation to implement this feature on multiple platforms.
Additional information
No response
Im waiting for this too! It was so easy to do with electron-builder..
@KevinHughes Can you explain how to setup file association with a info.plist file? i assume there are more configurations to setup and its not just as easy as only creating the info.plist file with the proper settings.
Can you explain how to setup file association with a info.plist file?
@vandervidi – For Info.plist, you can use the extendInfo option to add anything, like this:
module.exports = {
packagerConfig: {
extendInfo: {
CFBundleDocumentTypes: [
{
CFBundleTypeName: "MyTextEditor",
CFBundleTypeRole: "Editor",
LSTypeIsPackage: true,
LSHandlerRank: "Default",
CFBundleTypeExtensions: ["txt"],
},
],
}
}
};
Windows would be tricky because "regular" win32 applications have to register these in the registry while Microsoft Store applications have to declare them in the appx manifest.
For Windows if you are using the Wix-Maker you can do the following:
interface ExtendedMakerWixConfig extends MakerWixConfig {
// see https://github.com/electron/forge/issues/3673
// this is an undocumented property of electron-wix-msi
associateExtensions?: string;
}
...
{
config: {
icon: path.join(process.cwd(), 'assets', 'icon.ico'), // I needed this path to be absolute
associateExtensions: 'ext',
},
beforeCreate: (creator: WixCreator) => {
// manually convert app icon to some other icon
// manipulate the fileAssociationTemplate
},
} satisfies ExtendedMakerWixConfig,