Skip to content

Commit

Permalink
Support configurable branding of strings
Browse files Browse the repository at this point in the history
Allow the overall branding (app name, urls, etc.) to be controlled by
editing values in the branding.json file.
  • Loading branch information
llewelld committed Apr 22, 2022
1 parent 9a39df2 commit c149698
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 91 deletions.
13 changes: 7 additions & 6 deletions afterPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

const fs = require("fs-extra");
const path = require("path");
const branding = require("./branding.json");

/**
* Wrap the packaged application to avoid having to use double dashes -- before passing command-line arguments
Expand All @@ -30,21 +31,21 @@ module.exports = async function (context) {

if (context.targets.find(target => target.name === "deb")) {
wrapperScript = `#!/bin/bash
/opt/ubports-installer/ubports-installer.bin --no-sandbox "$@"
/opt/${branding.executable}/${branding.executable}.bin --no-sandbox "$@"
`;
} else if (context.targets.find(target => target.name === "appImage")) {
wrapperScript = `#!/bin/bash
"\${BASH_SOURCE%/*}"/ubports-installer.bin --no-sandbox "$@"
"\${BASH_SOURCE%/*}"/${branding.executable}.bin --no-sandbox "$@"
`;
} else {
console.log("no wrapper needed");
return;
}

fs.moveSync(
path.join(distDir, "ubports-installer"),
path.join(distDir, "ubports-installer.bin")
path.join(distDir, `${branding.executable}`),
path.join(distDir, `${branding.executable}.bin`)
);
fs.writeFileSync(path.join(distDir, "ubports-installer"), wrapperScript);
fs.chmodSync(path.join(distDir, "ubports-installer"), 0o765);
fs.writeFileSync(path.join(distDir, branding.executable), wrapperScript);
fs.chmodSync(path.join(distDir, branding.executable), 0o765);
};
31 changes: 31 additions & 0 deletions branding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"appname": "UBports Installer",
"os": "Ubuntu Touch",
"executable": "ubports-installer",
"app-id": "com.ubports.installer",
"header-text": "UBports Installer ({version})",
"donate-url": "https://ubports.com/donate",
"allow-reporting": true,
"supported-devices": "http://devices.ubuntu-touch.io/test/test.html",
"all-devices-supported": false,
"config-repo-prefix": "https://github.com/ubports/installer-configs/blob/master/v2/devices/",
"device-info-prefix": "https://devices.ubuntu-touch.io/device/",
"feedback": "https://github.com/ubports/ubports-touch",
"participate": "https://ubports.com/join-us",
"config-repo": "https://ubports.github.io/installer-configs/v2/",
"logfile": "ubports-installer.log",
"organisation-name": "the UBports Foundation",
"organisation-url": "https://ubports.com",
"info-url": "https://ubuntu-touch.io",
"installer-source": "https://github.com/ubports/ubports-installer/tree/",
"licence-url": "https://github.com/ubports/ubports-installer/blob/",
"bug-tracker": "https://github.com/ubports/ubports-installer/issues",
"troubleshooting": "https://docs.ubports.com/en/latest/userguide/install.html#troubleshooting",
"forum-name": "UBports Forums",
"forum-url": "https://forums.ubports.com",
"support-name": "AskUbuntu",
"support-url": "https://askubuntu.com/questions/tagged/ubuntu-touch",
"contact-name": "Telegram",
"contact-url": "https://t.me/WelcomePlus",
"update-url": "https://api.github.com/repos/ubports/ubports-installer/releases/latest"
}
11 changes: 7 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

const builder = require("electron-builder");
const cli = require("commander");
const branding = require("./branding.json");


const PLATFORMS = ["darwin", "win32", "linux"];
const PACKAGES = ["deb", "snap", "AppImage", "dmg", "portable", "dir"];
Expand Down Expand Up @@ -60,16 +62,17 @@ const opts = cli.opts();

var targetOs;
var buildConfig = {
appId: "com.ubports.installer",
productName: "ubports-installer",
copyright: `Copyright © 2017-${new Date().getFullYear()} UBports Foundation`,
appId: branding["app-id"],
productName: branding.executable,
copyright: "Copyright © 2017-2020 UBports Foundation",
artifactName: "${name}_${version}_${os}_${arch}.${ext}",
publish: [],
files: [
"src/**/*",
"public/**/*",
"node_modules/**/*",
"build/icons/icon.*",
"branding.json",
// exclude binaries for other operating systems
...PLATFORMS.filter(p => p !== opts.os).map(
p => `!node_modules/android-tools-bin/dist/${p}`
Expand Down Expand Up @@ -110,7 +113,7 @@ switch (opts.os) {
linux: {
target,
icon: "build/icons",
synopsis: "Install Ubuntu Touch on UBports devices",
synopsis: `Install ${branding.os} on your device device`,
category: "Utility"
},
deb: {
Expand Down
2 changes: 0 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />

<title>UBports Installer</title>

<link rel="stylesheet" href="build/theme.css" />
<link rel="stylesheet" href="global.css" />

Expand Down
7 changes: 4 additions & 3 deletions src/core/helpers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
*/

const axios = require("axios");
const branding = require("../../../branding.json");

/** @module api */

const api = axios.create({
baseURL: "https://ubports.github.io/installer-configs/v2/",
timeout: 15000
baseURL: branding["config-repo"],
timeout: 30000
});

/**
* get device index
* @returns {Promise<Array<Object>>}
*/
const getIndex = () => api.get("/").then(({ data }) => data);
const getIndex = () => api.get("/index.json").then(({ data }) => data);

/**
* get device selects object array
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
const cli = require("commander");
const log = require("./log.js");
const packageInfo = require("../../package.json");
const branding = require("../../branding.json");

const description = `UBports Installer (${packageInfo.version}) ${
const description = `${branding["header-text"]} (${packageInfo.version}) ${
packageInfo.package || "source"
} for ${process.platform}
${packageInfo.license} ${packageInfo.author}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const winston = require("winston");
const path = require("path");
const { path: cachePath } = require("./cache.js");
const branding = require("../../branding.json");

const levels = {
error: 0,
Expand Down Expand Up @@ -48,7 +49,7 @@ class Logger {
});

this.logfile = new winston.transports.File({
filename: path.join(cachePath, "ubports-installer.log"),
filename: path.join(cachePath, branding.logfile),
options: { flags: "w" },
level: "command"
});
Expand Down
5 changes: 3 additions & 2 deletions src/lib/mainEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { ipcMain, shell } = require("electron");
const EventEmitter = require("events");
const { prompt } = require("./prompt.js");
const packageInfo = require("../../package.json");
const branding = require("../../branding.json");

const mainEvent = new EventEmitter();

Expand Down Expand Up @@ -203,9 +204,9 @@ mainEvent.on("user:write:done", () => {
window.send("user:write:done");
window.send("user:write:speed");
log.info(
"All done! Your device will now reboot and complete the installation. Enjoy exploring Ubuntu Touch!"
`All done! Your device will now reboot; follow the steps on your device to complete the installation. Enjoy using ${branding.os}!`
);
if (!settings.get("never.opencuts")) {
if (branding["allow-reporting"] && !settings.get("never.opencuts")) {
setTimeout(() => {
window.send("user:report", true);
}, 1500);
Expand Down
46 changes: 31 additions & 15 deletions src/lib/menuManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const udev = require("./udev.js");
const settings = require("./settings.js");
const cache = require("./cache.js");
const reporter = require("./reporter.js");
const branding = require("../../branding.json");

class MenuManager {
/**
Expand All @@ -36,30 +37,34 @@ class MenuManager {
label: "About",
submenu: [
{
label: "About the UBports Foundation...",
click: () => shell.openExternal("https://ubports.com")
label: `About ${branding["organisation-name"]}...`,
visible: !!branding["organisation-url"],
click: () => shell.openExternal(branding["organisation-url"])
},
{
label: "About Ubuntu Touch...",
click: () => shell.openExternal("https://ubuntu-touch.io")
label: `About ${branding.os}...`,
visible: !!branding["info-url"],
click: () => shell.openExternal(branding["info-url"])
},
{
label: "Donate",
click: () => shell.openExternal("https://ubports.com/donate")
visible: !!branding["donate-url"],
click: () => shell.openExternal(branding["donate-url"])
},
{
label: "Source",
visible: !!branding["installer-source"],
click: () =>
shell.openExternal(
"https://github.com/ubports/ubports-installer/tree/" +
branding["installer-source"] +
packageInfo.version
)
},
{
label: "License",
click: () =>
shell.openExternal(
"https://github.com/ubports/ubports-installer/blob/" +
branding["licence-url"] +
packageInfo.version +
"/LICENSE"
)
Expand Down Expand Up @@ -98,6 +103,7 @@ class MenuManager {
},
{
label: "Report a bug",
visible: branding["allow-reporting"],
click: () => window.send("user:report")
},
{
Expand Down Expand Up @@ -167,13 +173,15 @@ class MenuManager {
},
{
label: "Never ask for OPEN-CUTS automatic reporting",
visible: branding["allow-reporting"],
checked: settings.get("never.opencuts"),
type: "checkbox",
click: () =>
settings.set("never.opencuts", !settings.get("never.opencuts"))
},
{
label: "OPEN-CUTS API Token",
visible: branding["allow-reporting"],
click: () => reporter.tokenDialog(mainWindow)
}
]
Expand All @@ -183,36 +191,44 @@ class MenuManager {
submenu: [
{
label: "Bug tracker",
visible: !!branding["bug-tracker"],
click: () =>
shell.openExternal(
"https://github.com/ubports/ubports-installer/issues"
branding["bug-tracker"]
)
},
{
label: "Report a bug",
visible: branding["allow-reporting"],
click: () => window.send("user:report")
},
{
label: "Troubleshooting",
visible: !!branding["troubleshooting"],
click: () =>
shell.openExternal(
"https://docs.ubports.com/en/latest/userguide/install.html#troubleshooting"
branding["troubleshooting"]
)
},
{
label: "UBports Forums",
click: () => shell.openExternal("https://forums.ubports.com")
label: branding["forum-name"],
visible: !!branding["forum-url"],
click: () => shell.openExternal(branding["forum-url"])
},
{
label: "AskUbuntu",
label: branding["support-name"],
visible: !!branding["support-url"],
click: () =>
shell.openExternal(
"https://askubuntu.com/questions/tagged/ubuntu-touch"
branding["support-url"]
)
},
{
label: "Telegram",
click: () => shell.openExternal("https://t.me/WelcomePlus")
label: branding["contact-name"],
visible: !!branding["contact-url"],
click: () => shell.openExternal(
branding["contact-url"]
)
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const cli = require("./cli.js");
const core = require("../core/core.js");
const { prompt } = require("./prompt.js");
const { paste } = require("./paste.js");
const branding = require("../../branding.json");

/**
* OPEN-CUTS operating system mapping
Expand Down Expand Up @@ -104,7 +105,7 @@ class Reporter {
async getDebugInfo(data, runUrl, logUrl) {
return encodeURIComponent(
[
`**UBports Installer \`${packageInfo.version}\` (${data.package})**`,
`**${branding.appname} \`${packageInfo.version}\` (${data.package})**`,
`Environment: \`${data.environment}\``,
`Device: ${this.getDeviceLinkMarkdown(data.device)}`,
`Target OS: ${core?.props?.os?.name}`,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/udev.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const sudo = require("sudo-prompt");
const path = require("path");
const log = require("./log.js");
const { ipcMain } = require("electron");
const branding = require("../../branding.json");

const vendorIds = [
"03f0",
Expand Down Expand Up @@ -128,7 +129,7 @@ class Udev {
sudo.exec(
udevCommand,
{
name: "UBports Installer",
name: branding.appname,
icns: path.join(__dirname, "../../build/icons/icon.icns")
},
error => {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

const axios = require("axios");
const packageInfo = require("../../package.json");
const branding = require("../../branding.json");

/**
* UBports Installer version management
Expand All @@ -42,7 +43,7 @@ class Updater {
} else {
return axios
.get(
"https://api.github.com/repos/ubports/ubports-installer/releases/latest",
branding["update-url"],
{
json: true,
headers: { "User-Agent": "axios" }
Expand All @@ -54,7 +55,7 @@ class Updater {
})
.catch(e => {
throw new Error(
`Failed to get latest version of the UBports Installer: ${e}`
`Failed to get latest version of the ${branding.appname}: ${e}`
);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/updater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const axios = require("axios");
jest.mock("axios");
axios.create.mockReturnValue(axios);
const packageInfo = require("../../package.json");
const branding = require("../../branding.json");
jest.mock("../../package.json");
packageInfo.version = "0.8.9-beta";

Expand All @@ -28,7 +29,7 @@ describe("getLatestVersion()", () => {
expect.assertions(1);
return updater.getLatestVersion().catch(e => {
expect(e.message).toMatch(
"Failed to get latest version of the UBports Installer"
`Failed to get latest version of the ${branding.appname}`
);
});
});
Expand Down
Loading

0 comments on commit c149698

Please sign in to comment.