nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.4k stars 1.71k forks source link

Expose handlers.json from firefox profile #5617

Open quatquatt opened 2 weeks ago

quatquatt commented 2 weeks ago

Firefox provides a way to control which file types are opened in firefox, and which file types open separate apps. This is controlled via the file path .mozilla/firefox/profile_name/handlers.json.

Home-manager provides many ways to control the firefox configuration, yet it doesn't extend to these app types. It should be fairly simple to control declaratively, since it's controlled via a simple key-value pair structure.

Here's how my personal file is structured:

{ "defaultHandlersVersion": { }, "mimeTypes": { "application/pdf": { "action":3, "extensions":["pdf"] }, "image/webp": { "action":3, "extensions":["webp"] }, "image/avif": { "action":3, "extensions":["avif"] } }, "schemes": {

    "mailto":
    {
        "stubEntry":true,
        "handlers":
        [
            null,
            {
                "name":"Gmail",
                "uriTemplate":"https://mail.google.com/mail/?extsrc=mailto&url=%s"
            }
        ]
    },

    "vscode": 
    {
        "action":4
    }
},
"isDownloadsImprovementsAlreadyMigrated":false

}

Most of the functions seem fairly obvious. What I call "imports" are controlled in mimeTypes, and controls what files open firefox. There are several options for what to do with this filetype, numbered from 0. I'll list what the numbers correspond to below.

Then, there's what I call "exports", controlled in schemes. This manages urls of a certain scheme redirecting into an app, like Discord or VSCode. These seem to take the same actions as above. However, I haven't seem 0,or 3 used here. I'd assume that these would never occur, since it's a url, not a file. With this in mind, the only valid codes for exports would be 1, 2, or 4.

That's all the research I've done so far. Hope this helps!

quatquatt commented 2 weeks ago

Sorry, the file contents weren't properly formatted. This should help:

{
    "defaultHandlersVersion":
    {
    },
    "mimeTypes":
    {
        "application/pdf":
        {
            "action":3,
            "extensions":["pdf"]
        },
        "image/webp":
        {
            "action":3,
            "extensions":["webp"]
        },
        "image/avif":
        {
            "action":3,
            "extensions":["avif"]
        }
    },
    "schemes":
    {

            "mailto":
            {
            "stubEntry":true,
            "handlers":
            [
                    null,
                    {
                    "name":"Gmail",
                    "uriTemplate":"https://mail.google.com/mail/?extsrc=mailto&url=%s"
                    }
            ]
            },

            "vscode":
            {
            "action":4
            }
    },
    "isDownloadsImprovementsAlreadyMigrated":false
}
quatquatt commented 2 weeks ago

Found some documentation: https://mozilla.github.io/policy-templates/#handlers