Skip to content

Commit

Permalink
fix: snap support, desktop integration attempt #509
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 19, 2016
1 parent 6a177a6 commit 223a6aa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
4 changes: 4 additions & 0 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,8 @@ export async function getResolvedPublishConfig(packager: BuildInfo, publishConfi
else {
return null
}
}

export function toDebArch(arch: Arch) {
return arch === Arch.ia32 ? "i386" : "amd64"
}
5 changes: 3 additions & 2 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ export class LinuxTargetHelper {
return options.description || this.packager.appInfo.description
}

async computeDesktopEntry(platformSpecificBuildOptions: LinuxBuildOptions, exec?: string, extra?: { [key: string]: string; }): Promise<string> {
async computeDesktopEntry(platformSpecificBuildOptions: LinuxBuildOptions, exec?: string, destination?: string | null, extra?: { [key: string]: string; }): Promise<string> {
const appInfo = this.packager.appInfo

const productFilename = appInfo.productFilename
const tempFile = await this.packager.getTempFile(`${productFilename}.desktop`)

const desktopMeta: any = Object.assign({
Name: appInfo.productName,
Expand All @@ -80,6 +79,7 @@ export class LinuxTargetHelper {
Terminal: "false",
Type: "Application",
Icon: appInfo.name,
StartupWMClass: `"${productFilename}"`,
}, extra, platformSpecificBuildOptions.desktop)

const category = platformSpecificBuildOptions.category
Expand All @@ -94,6 +94,7 @@ export class LinuxTargetHelper {
}
data += "\n"

const tempFile = destination || await this.packager.getTempFile(`${productFilename}.desktop`)
await outputFile(tempFile, data)
return tempFile
}
Expand Down
6 changes: 3 additions & 3 deletions src/targets/appImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class AppImageTarget extends Target {

// we add X-AppImage-BuildId to ensure that new desktop file will be installed
this.desktopEntry = BluebirdPromise.promisify(uuid1)({mac: false})
.then(uuid => helper.computeDesktopEntry(this.options, "AppRun", {
.then(uuid => helper.computeDesktopEntry(this.options, "AppRun", null, {
"X-AppImage-Version": `${packager.appInfo.buildVersion}`,
"X-AppImage-BuildId": uuid,
}))
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class AppImageTarget extends Target {
args.push("-zisofs", `level=${packager.devMetadata.build.compression === "store" ? "0" : "9"}:block_size=128k:by_magic=off`)
args.push("set_filter_r", "--zisofs", "/")

await exec(process.env.USE_SYSTEM_FPM === "true" || process.arch !== "x64" ? "xorriso" : path.join(appImagePath, "xorriso"), args)
await exec(process.arch === "x64" ? path.join(appImagePath, "xorriso") : "xorriso", args)

await new BluebirdPromise((resolve, reject) => {
const rd = createReadStream(path.join(appImagePath, arch === Arch.ia32 ? "32" : "64", "runtime"))
Expand All @@ -87,6 +87,6 @@ export default class AppImageTarget extends Target {

await chmod(resultFile, "0755")

packager.dispatchArtifactCreated(resultFile, packager.generateName("AppImage", arch, true))
packager.dispatchArtifactCreated(resultFile)
}
}
40 changes: 20 additions & 20 deletions src/targets/snap.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Target } from "../platformPackager"
import { Target, toDebArch } from "../platformPackager"
import { Arch } from "../metadata"
import { LinuxTargetHelper } from "./LinuxTargetHelper"
import { LinuxPackager } from "../linuxPackager"
import { log } from "../util/log"
import { SnapOptions } from "../options/linuxOptions"
import { emptyDir, writeFile } from "fs-extra-p"
import { emptyDir, writeFile, rename, copy } from "fs-extra-p"
import * as path from "path"
import { safeDump } from "js-yaml"
import { spawn, unlinkIfExists } from "../util/util"
import { spawn } from "../util/util"
import { homedir } from "os"

export default class SnapTarget extends Target {
private readonly options: SnapOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, (<any>this.packager.devMetadata.build)[this.name])
private readonly desktopEntry: Promise<string>

constructor(private packager: LinuxPackager, private helper: LinuxTargetHelper, private outDir: string) {
super("snap")

// we add X-AppImage-BuildId to ensure that new desktop file will be installed
this.desktopEntry = helper.computeDesktopEntry(this.options, "AppRun")
}

async build(appOutDir: string, arch: Arch): Promise<any> {
Expand All @@ -28,8 +24,8 @@ export default class SnapTarget extends Target {
const appInfo = packager.appInfo
const options = this.options

const resultFile = path.join(this.outDir, packager.generateName("snap", arch, true))
await unlinkIfExists(resultFile)
const snapDir = `${appOutDir}-snap`
await emptyDir(snapDir)

const snap: any = {}
snap.name = packager.executableName
Expand All @@ -39,15 +35,19 @@ export default class SnapTarget extends Target {
snap.confinement = options.confinement || "strict"
snap.grade = options.grade || "stable"

await this.helper.icons
if (this.helper.maxIconPath != null) {
snap.icon = "setup/gui/icon.png"
await copy(this.helper.maxIconPath, path.join(snapDir, "setup", "gui", "icon.png"))
}

if (options.assumes != null) {
if (!Array.isArray(options.assumes)) {
throw new Error("snap.assumes must be an array of strings")
}
snap.assumes = options.assumes
}

const snapDir = `${appOutDir}-snap`

snap.apps = {
[snap.name]: {
command: `desktop-launch $SNAP/${packager.executableName}`,
Expand All @@ -57,29 +57,26 @@ export default class SnapTarget extends Target {
}
}

await this.helper.computeDesktopEntry(this.options, "$snap.$app", path.join(snapDir, "setup", "gui", `${snap.name}.desktop`), {
"Icon": "${SNAP}/meta/gui/icon.png"
})

const isUseDocker = process.platform !== "linux"
snap.parts = {
app: {
plugin: "dump",
"stage-packages": ["libappindicator1", "libdbusmenu-glib4", "libnotify4", "libunity9", "libgconf-2-4", "libnss3", "libxss1", "fontconfig-config", "libnotify-bin"],
source: isUseDocker ? `/out/${path.basename(snapDir)}` : appOutDir,
filesets: {
app: [`${appOutDir}/*`]
app: [`${appOutDir}/*`],
},
after: ["desktop-glib-only"]
}
}

const snapcraft = path.join(snapDir, "snapcraft.yaml")
await emptyDir(snapDir)
await writeFile(snapcraft, safeDump(snap))

// await writeFile(path.join(snapDir, "wrapper"), `
// #!/bin/bash
// unset XDG_CONFIG_DIRS
// exec $SNAP/${packager.executableName}
// `)

// const args = ["snapcraft", path.relative(snapDir)]
// snap /out/${path.basename(snapDir)} --output /out/${path.basename(resultFile)}
if (isUseDocker) {
Expand All @@ -100,6 +97,9 @@ export default class SnapTarget extends Target {
})
}

packager.dispatchArtifactCreated(resultFile, packager.generateName("snap", arch, true))
const snapName = `${snap.name}_${snap.version}_${toDebArch(arch)}.snap`
const resultFile = path.join(this.outDir, snapName)
await rename(path.join(snapDir, snapName), resultFile)
packager.dispatchArtifactCreated(resultFile)
}
}
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,9 @@ [email protected]:
semver "^5.3.0"
sumchecker "^1.2.0"

[email protected].2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/electron-macos-sign/-/electron-macos-sign-1.3.2.tgz#e7b6d0721fb3f4365f69c04d59f74d30354a5b47"
electron-macos-sign@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/electron-macos-sign/-/electron-macos-sign-1.3.4.tgz#641e011f974b26879f05ac505dde94b86481376a"
dependencies:
bluebird "^3.4.6"
compare-version "^0.1.2"
Expand Down

0 comments on commit 223a6aa

Please sign in to comment.