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

Fix restart issues #1001

Merged
merged 15 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 130 additions & 91 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

"use strict"
"use strict";

/*

Expand All @@ -10,63 +10,92 @@ Author: Marius Gripsgard <[email protected]>

*/

const builder = require("electron-builder")
const builder = require("electron-builder");
const cli = require("commander");
const unzip = require("unzipper");
const path = require("path");
const fs = require("fs-extra");
const download = require('download');
const download = require("download");
const events = require("events");
class event extends events {}
const Platform = builder.Platform
const platformToolsPath = "./platform-tools"
const Platform = builder.Platform;
const platformToolsPath = "./platform-tools";
const platformToolsUrls = {
"linux": "https://dl.google.com/android/repository/platform-tools-latest-linux.zip",
"mac": "https://dl.google.com/android/repository/platform-tools-latest-darwin.zip",
"win": "https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
}
linux:
"https://dl.google.com/android/repository/platform-tools-latest-linux.zip",
mac:
"https://dl.google.com/android/repository/platform-tools-latest-darwin.zip",
win:
"https://dl.google.com/android/repository/platform-tools-latest-windows.zip"
};

function getAndroidPlatformTools() {
return [{
url: platformToolsUrls[cli.os],
path: platformToolsPath,
target: cli.os
}];
return [
{
url: platformToolsUrls[cli.os],
path: platformToolsPath,
target: cli.os
}
];
}

function extractPlatformTools(platformToolsArray, callback) {
var i = platformToolsArray[0];
fs.createReadStream(path.join(i.path, path.basename(i.url))).pipe(unzip.Extract({
path: path.join(i.path, i.target + "_tmp")
})).on("close", () => {
fs.move(path.join(i.path, i.target + "_tmp", "platform-tools"), path.join(i.path, i.target), {
overwrite: true
}, (e) => {
fs.removeSync(path.join(i.path, i.target + "_tmp"));
if (cli.os !== "win") {
fs.chmodSync(path.join(i.path, i.target, "fastboot"), 0o755);
fs.chmodSync(path.join(i.path, i.target, "adb"), 0o755);
fs.chmodSync(path.join(i.path, i.target, "mke2fs"), 0o755);
}
if (platformToolsArray.length <= 1) {
callback()
} else {
platformToolsArray.shift();
extractPlatformTools(platformToolsArray, callback);
}
fs.createReadStream(path.join(i.path, path.basename(i.url)))
.pipe(
unzip.Extract({
path: path.join(i.path, i.target + "_tmp")
})
)
.on("close", () => {
fs.move(
path.join(i.path, i.target + "_tmp", "platform-tools"),
path.join(i.path, i.target),
{
overwrite: true
},
e => {
fs.removeSync(path.join(i.path, i.target + "_tmp"));
if (cli.os !== "win") {
fs.chmodSync(path.join(i.path, i.target, "fastboot"), 0o755);
fs.chmodSync(path.join(i.path, i.target, "adb"), 0o755);
fs.chmodSync(path.join(i.path, i.target, "mke2fs"), 0o755);
}
if (platformToolsArray.length <= 1) {
callback();
} else {
platformToolsArray.shift();
extractPlatformTools(platformToolsArray, callback);
}
}
);
});
});
}

cli
.version(require('./package.json').version)
.usage('./build.js -o <os> -p <package> [options]')
.option('-o, --os <os>', 'Target operating system')
.option('-p, --package [package]', 'Target package')
.option('-e, --extra-metadata [JSON]', 'Inject JSON into package.json', JSON.parse, "")
.option('-d, --download-only', 'Only download platform tools', undefined, false)
.option('-n, --no-platform-tools', 'Build without platform tools', undefined, false)
.parse(process.argv)
.version(require("./package.json").version)
.usage("./build.js -o <os> -p <package> [options]")
.option("-o, --os <os>", "Target operating system")
.option("-p, --package [package]", "Target package")
.option(
"-e, --extra-metadata [JSON]",
"Inject JSON into package.json",
JSON.parse,
""
)
.option(
"-d, --download-only",
"Only download platform tools",
undefined,
false
)
.option(
"-n, --no-platform-tools",
"Build without platform tools",
undefined,
false
)
.parse(process.argv);

var targetOs;
var buildConfig = require("./buildconfig-generic.json");
Expand All @@ -80,38 +109,44 @@ switch (cli.os) {
case "linux":
targetOs = Platform.LINUX;
buildConfig = Object.assign(buildConfig, {
"linux": {
"target": cli.package,
"icon": "build/icons",
"synopsis": "Install Ubuntu Touch on UBports devices",
"category": "Utility"
},
"deb": {
"depends": ["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3", "android-tools-adb", "android-tools-fastboot"]
}
linux: {
target: cli.package,
icon: "build/icons",
synopsis: "Install Ubuntu Touch on UBports devices",
category: "Utility"
},
deb: {
depends: [
"gconf2",
"gconf-service",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"android-tools-adb",
"android-tools-fastboot"
]
}
);
});
break;
case "win":
targetOs = Platform.WINDOWS;
buildConfig = Object.assign(buildConfig, {
"win": {
"target": ["portable"],
"icon": "build/icons/icon.ico"
}
win: {
target: ["portable"],
icon: "build/icons/icon.ico"
}
);
});
break;
case "mac":
targetOs = Platform.MAC;
buildConfig = Object.assign(buildConfig, {
"mac": {
"target": "dmg",
"icon": "build/icons/icon.icns",
"category": "public.app-category.utilities"
}
mac: {
target: "dmg",
icon: "build/icons/icon.icns",
category: "public.app-category.utilities"
}
);
});
break;
default:
console.log("Please specify a target operating system!");
Expand Down Expand Up @@ -154,42 +189,46 @@ switch (cli.package) {
var build = () => {
// Build
if (!cli.downloadOnly) {
builder.build({
builder
.build({
targets: builder.createTargets([targetOs]),
config: Object.assign(buildConfig,
{ "extraMetadata":
(cli.package ?
Object.assign(cli.extraMetadata, { "package": cli.package }) :
cli.extraMetadata
)
}
)
}).then(() => {
console.log("Done");
}).catch((e) => {
if(e.message.indexOf("GitHub Personal Access Token is not set") !== -1) {
config: Object.assign(buildConfig, {
extraMetadata: cli.package
? Object.assign(cli.extraMetadata, { package: cli.package })
: cli.extraMetadata
})
})
.then(() => {
console.log("Done");
process.exit(0);
} else {
console.log(e);
process.exit(1);
}
});
})
.catch(e => {
if (
e.message.indexOf("GitHub Personal Access Token is not set") !== -1
) {
console.log("Done");
process.exit(0);
} else {
console.log(e);
process.exit(1);
}
});
}
}
};

// Download platform tools
if (cli.platformTools) {
download(getAndroidPlatformTools()[0].url,getAndroidPlatformTools()[0].path).then(() => {
console.log('files downloaded!');
extractPlatformTools(getAndroidPlatformTools(), () => {
console.log("Platform tools downloaded successfully!");
if (!cli.downloadOnly) build();
download(getAndroidPlatformTools()[0].url, getAndroidPlatformTools()[0].path)
.then(() => {
console.log("files downloaded!");
extractPlatformTools(getAndroidPlatformTools(), () => {
console.log("Platform tools downloaded successfully!");
if (!cli.downloadOnly) build();
});
})
.catch(() => {
console.error("Failed to download files!");
process.exit(1);
});
}).catch(() => {
console.error("Failed to download files!");
process.exit(1);
});
} else {
build();
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ubports-installer",
"version": "0.4.6-beta",
"version": "0.4.7-beta",
"description": "The easy way to install Ubuntu Touch on UBports devices. A friendly cross-platform Installer for Ubuntu Touch. Just connect a supported device to your PC, follow the on-screen instructions and watch this awesome tool do all the rest.",
"keywords": [
"Ubuntu",
Expand Down Expand Up @@ -30,8 +30,8 @@
"dist:linux:appimage": "node ./build.js -o 'linux' -p 'AppImage'",
"dist:linux:deb": "node ./build.js -o 'linux' -p 'deb'",
"dist:linux:snap": "snapcraft cleanbuild",
"lint": "./node_modules/.bin/eslint src/*.js",
"lint-fix": "./node_modules/.bin/eslint src/*.js --fix"
"lint": "./node_modules/.bin/eslint *.js src/*.js src/html/scripts/*.js",
"lint-fix": "./node_modules/.bin/eslint *.js src/*.js src/html/scripts/*.js --fix"
},
"devDependencies": {
"electron": "^1.8.8",
Expand Down
Loading