Skip to content

Commit

Permalink
feat(linux): add fileAssociation support for fpm target
Browse files Browse the repository at this point in the history
  • Loading branch information
patsimm authored and develar committed Jul 18, 2019
1 parent 1acd5b3 commit c11fa1f
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- deps-{{ checksum "yarn.lock" }}
- restore_cache:
keys:
- v-5.0.5-electron
- v-5.0.7-electron
- run:
command: yarn --frozen-lockfile
- run:
Expand All @@ -23,7 +23,7 @@ jobs:
- run:
command: node ./test/out/helpers/downloadElectron.js
- save_cache:
key: v-5.0.5-electron
key: v-5.0.7-electron
paths:
- ~/.cache/electron

Expand All @@ -41,7 +41,7 @@ jobs:
- deps-{{ checksum "yarn.lock" }}
- restore_cache:
keys:
- v-5.0.5-electron
- v-5.0.7-electron
# because in the build job we use circleci docker image and circleci restores cache to original user home
- run:
command: |
Expand Down
31 changes: 31 additions & 0 deletions packages/app-builder-lib/src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const installPrefix = "/opt"
export class LinuxTargetHelper {
private readonly iconPromise = new Lazy(() => this.computeDesktopIcons())

private readonly mimeTypeFilesPromise = new Lazy(() => this.computeMimeTypeFiles())

maxIconPath: string | null = null

constructor(private packager: LinuxPackager) {
Expand All @@ -19,6 +21,35 @@ export class LinuxTargetHelper {
return this.iconPromise.value
}

get mimeTypeFiles(): Promise<string | null> {
return this.mimeTypeFilesPromise.value
}

private async computeMimeTypeFiles(): Promise<string | null> {
const items: Array<string> = []
for (const fileAssociation of this.packager.fileAssociations) {
if (!fileAssociation.mimeType) {
continue
}

const data = `<mime-type type="${fileAssociation.mimeType}">
<glob pattern="*.${fileAssociation.ext}"/>
${fileAssociation.description ? `<comment>${fileAssociation.description}</comment>` : ""}
<icon name="x-office-document" />
</mime-type>
</mime-info>`
items.push(data)
}

if (items.length === 0) {
return null
}

const file = await this.packager.getTempFile(".xml")
await outputFile(file, '<?xml version="1.0" encoding="utf-8"?>\n<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">\n' + items.join("\n") + "\n</mime-info>")
return file
}

// must be name without spaces and other special characters, but not product name used
private async computeDesktopIcons(): Promise<Array<IconInfo>> {
const packager = this.packager
Expand Down
5 changes: 5 additions & 0 deletions packages/app-builder-lib/src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ export default class FpmTarget extends Target {
args.push(`${icon.file}=/usr/share/icons/hicolor/${sizeName}/apps/${packager.executableName}${extWithDot}`)
}

const mimeTypeFilePath = await this.helper.mimeTypeFiles
if (mimeTypeFilePath != null) {
args.push(`${mimeTypeFilePath}=/usr/share/mime/packages/${packager.executableName}.xml`)
}

const desktopFilePath = await this.helper.writeDesktopEntry(this.options)
args.push(`${desktopFilePath}=/usr/share/applications/${packager.executableName}.desktop`)

Expand Down
3 changes: 3 additions & 0 deletions packages/app-builder-lib/templates/linux/after-install.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# Link to the binary
ln -sf '/opt/${productFilename}/${executable}' '/usr/bin/${executable}'

update-mime-database /usr/share/mime || true
update-desktop-database /usr/share/applications || true
2 changes: 1 addition & 1 deletion test/fixtures/test-app-build-sub/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
electronVersion: 5.0.5
electronVersion: 5.0.7
appId: org.electron-builder.testApp
compression: store
npmRebuild: false
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "5.0.5",
"electronVersion": "5.0.7",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "5.0.5",
"electronVersion": "5.0.7",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "5.0.5",
"electronVersion": "5.0.7",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Foo Bar <[email protected]>",
"license": "MIT",
"build": {
"electronVersion": "5.0.5",
"electronVersion": "5.0.7",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"build": {
"electronVersion": "5.0.5",
"electronVersion": "5.0.7",
"appId": "org.electron-builder.testApp",
"compression": "store",
"npmRebuild": false,
Expand Down
88 changes: 88 additions & 0 deletions test/out/linux/__snapshots__/debTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,94 @@ Object {

exports[`deb 4`] = `"Test Application (test quite “ #378)"`;

exports[`deb file associations 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "TestApp_1.1.0_amd64.deb",
},
],
}
`;

exports[`deb file associations 2`] = `
Array [
"/",
"/opt/",
"/usr/",
"/opt/Test App ßW/",
"/opt/Test App ßW/chrome-sandbox",
"/opt/Test App ßW/chrome_100_percent.pak",
"/opt/Test App ßW/chrome_200_percent.pak",
"/opt/Test App ßW/icudtl.dat",
"/opt/Test App ßW/libEGL.so",
"/opt/Test App ßW/libffmpeg.so",
"/opt/Test App ßW/libGLESv2.so",
"/opt/Test App ßW/LICENSE.electron.txt",
"/opt/Test App ßW/LICENSES.chromium.html",
"/opt/Test App ßW/natives_blob.bin",
"/opt/Test App ßW/resources.pak",
"/opt/Test App ßW/snapshot_blob.bin",
"/opt/Test App ßW/testapp",
"/opt/Test App ßW/v8_context_snapshot.bin",
"/usr/share/",
"/opt/Test App ßW/resources/",
"/opt/Test App ßW/resources/app.asar",
"/opt/Test App ßW/resources/electron.asar",
"/opt/Test App ßW/swiftshader/",
"/opt/Test App ßW/swiftshader/libEGL.so",
"/opt/Test App ßW/swiftshader/libGLESv2.so",
"/usr/share/applications/",
"/usr/share/applications/testapp.desktop",
"/usr/share/doc/",
"/usr/share/icons/",
"/usr/share/mime/",
"/usr/share/doc/testapp/",
"/usr/share/doc/testapp/changelog.gz",
"/usr/share/icons/hicolor/",
"/usr/share/mime/packages/",
"/usr/share/mime/packages/testapp.xml",
"/usr/share/icons/hicolor/128x128/",
"/usr/share/icons/hicolor/16x16/",
"/usr/share/icons/hicolor/256x256/",
"/usr/share/icons/hicolor/32x32/",
"/usr/share/icons/hicolor/48x48/",
"/usr/share/icons/hicolor/512x512/",
"/usr/share/icons/hicolor/64x64/",
"/usr/share/icons/hicolor/128x128/apps/",
"/usr/share/icons/hicolor/128x128/apps/testapp.png",
"/usr/share/icons/hicolor/16x16/apps/",
"/usr/share/icons/hicolor/16x16/apps/testapp.png",
"/usr/share/icons/hicolor/256x256/apps/",
"/usr/share/icons/hicolor/256x256/apps/testapp.png",
"/usr/share/icons/hicolor/32x32/apps/",
"/usr/share/icons/hicolor/32x32/apps/testapp.png",
"/usr/share/icons/hicolor/48x48/apps/",
"/usr/share/icons/hicolor/48x48/apps/testapp.png",
"/usr/share/icons/hicolor/512x512/apps/",
"/usr/share/icons/hicolor/512x512/apps/testapp.png",
"/usr/share/icons/hicolor/64x64/apps/",
"/usr/share/icons/hicolor/64x64/apps/testapp.png",
]
`;

exports[`deb file associations 3`] = `
Object {
"Architecture": "amd64",
"Depends": "libgtk-3-0, libnotify4, libnss3, libxss1, libxtst6, xdg-utils, libatspi2.0-0, libuuid1, libappindicator3-1, libsecret-1-0, gir1.2-gnomekeyring-1.0",
"Homepage": "http://foo.example.com",
"License": "MIT",
"Maintainer": "Foo Bar <[email protected]>",
"Package": "testapp",
"Priority": "extra",
"Section": "devel",
"Vendor": "Foo Bar <[email protected]>",
}
`;

exports[`deb file associations 4`] = `"Test Application (test quite “ #378)"`;

exports[`no quotes for safe exec name 1`] = `
"[Desktop Entry]
Name=foo
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/testConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as os from "os"
import * as path from "path"

export const ELECTRON_VERSION = "5.0.5"
export const ELECTRON_VERSION = "5.0.7"

export function getElectronCacheDir() {
if (process.platform === "win32") {
Expand Down
13 changes: 13 additions & 0 deletions test/src/linux/debTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ test.ifNotWindows("no quotes for safe exec name", app({
expect(content).toMatchSnapshot()
return false
}
}))

test.ifNotWindows.ifNotCiMac.ifAll("deb file associations", app({
targets: Platform.LINUX.createTarget("deb"),
config: {
fileAssociations: [
{
ext: "my-app",
name: "Test Foo",
mimeType: "application/x-example",
}
],
},
}))

0 comments on commit c11fa1f

Please sign in to comment.