Polarr is an electron app packaged with Snap. Ubuntu users have been asking for the ability to open image files on with either double click or right click > open with > Polarr. I wrote the code but now it’s not working with Snap.
Problem #1: electron-builder fileAssociations isn’t working?
I followed the instructions at https://www.electron.build/configuration/configuration#PlatformSpecificBuildOptions-fileAssociations and added fileAssociations
to my package.json:
package.json
{
"name": "polarr",
"version": "5.1.2",
"description": "Powerful and easy-to-use photo editor.",
"main": "main.js",
"author": "Polarr, Inc",
"scripts": {
"start": "electron . --dev",
"build:mac": "electron-packager . Polarr --name=Polarr --platform=darwin --arch=x64 --icon=icon.icns --asar --overwrite --version-string.ProductName=Polarr",
"build:win": "node build_win.js",
"build:linux": "node build_linux.js",
"docker": "bash run-docker.sh",
"snap:linux": "electron-builder",
"build_win_zh": "node build_win_zh.js"
},
"build": {
"appId": "co.polarr.photoeditor",
"linux": {
"icon": "icon",
"synopsis": "Powerful and easy-to-use photo editor.",
"description": "Used by the world's most professional portrait and landscape photographers, Polarr offers advanced auto-enhance tools and sophisticated filters to edit every detail of your photo.",
"category": "Graphics;Photography",
"target": [
"snap"
]
},
"fileAssociations": [
{
"ext": [
"tiff",
"tif",
"3fr",
"ari",
"arw",
"bay",
"crw",
"cr2",
"cap",
"dcs",
"dcr",
"dng",
"drf",
"eip",
"erf",
"fff",
"iiq",
"k25",
"kdc",
"mef",
"mos",
"mrw",
"nef",
"nrw",
"obm",
"orf",
"pef",
"ptx",
"pxn",
"r3d",
"raf",
"raw",
"rwl",
"rw2",
"rwz",
"sr2",
"srf",
"srw",
"x3f"
],
"name": "Raw Image"
},
{
"ext": ["jpg", "jpeg", "png", "bmp", "gif"],
"name": "Image"
}
],
"extraResources": [
"node_modules/sharp/vendor/lib"
],
"appImage": {},
"snap": {
"confinement": "strict",
"summary": "Powerful and easy-to-use photo editor.",
"grade": "stable",
"stagePackages": [
"default",
"libcanberra-gtk-module",
"libgail-3-0",
"libatk1.0-0",
"unity-gtk-module-common"
],
"plugs": [
"default",
"removable-media"
],
"environment": {
"LD_LIBRARY_PATH": "$SNAP/usr/lib:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/app/resources/node_modules/sharp/vendor/lib"
}
}
},
"devDependencies": {
"asar": "^0.14.3",
"electron": "^2.0.0",
"electron-builder": "^20.8.2",
"electron-packager": "^12.1.0",
"electron-squirrel-startup": "^1.0.0",
"electron-winstaller": "^2.6.4",
"env-paths": "^1.0.0",
"grunt": "^1.0.2",
"grunt-electron-installer": "^2.1.0",
"iconv-lite": "^0.4.18",
"locate-path": "^3.0.0",
"universalify": "^0.1.0"
},
"dependencies": {
"electron-fetch": "^1.0.0",
"get-pixels": "^3.3.0",
"libraw": "file:libraw",
"readable-stream": "^3.0.1",
"sharp": "^0.20.5",
"temp": "^0.8.3",
"url-exists": "^1.0.3"
}
}
sudo snap install --dangerous dist/polarr_5.1.2_amd64.snap
- Right click a .png file in Files.
- Open with Other Application.
- View All Applications.
- Polarr is missing from the list.
Problem #2: Snap isn’t giving my application command line arguments?
At the beginning of main.js
, I print out the command line arguments:
console.log("process.argv", process.argv)
When run my application not in a snap (./node_modules/electron/dist/electron . /path/to/image.png
), the parameterized image path will be in the printed arguments array and the editor will open the image as expected. Once I snap the application, process.argv prints
process.argv [ '/snap/polarr/x2/app/polarr' ]
regardless of how many arguments are passed in to it. So opening files is somehow broken for Snap.