Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support file association properties in forge.config.js #3339

Open
3 tasks done
KevinHughes opened this issue Sep 7, 2023 · 4 comments
Open
3 tasks done

Comments

@KevinHughes
Copy link

KevinHughes commented Sep 7, 2023

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • 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.

  • ext is the name of the file extension to associate with one's Electron application
  • name is the label that the platform presents to users in the user interface
  • icon is 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

@vandervidi
Copy link

vandervidi commented Apr 3, 2024

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.

@davidcann
Copy link

davidcann commented Apr 3, 2024

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"],
        },
      ],
    }
  }
};

@mmarczell-graphisoft
Copy link

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.

@fras2560
Copy link
Contributor

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants