From c149698dbc7ac488b23a95f8c899157d7ae6e15e Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Mon, 6 Dec 2021 00:39:58 +0200 Subject: [PATCH] Support configurable branding of strings Allow the overall branding (app name, urls, etc.) to be controlled by editing values in the branding.json file. --- afterPack.js | 13 ++--- branding.json | 31 ++++++++++++ build.js | 11 +++-- public/index.html | 2 - src/core/helpers/api.js | 7 +-- src/lib/cli.js | 3 +- src/lib/log.js | 3 +- src/lib/mainEvent.js | 5 +- src/lib/menuManager.js | 46 +++++++++++------ src/lib/reporter.js | 3 +- src/lib/udev.js | 3 +- src/lib/updater.js | 5 +- src/lib/updater.spec.js | 3 +- src/main.js | 7 +-- .../specific-modals/SelectDeviceModal.svelte | 27 ++++++---- src/ui/partials/Footer.svelte | 3 +- src/ui/partials/Header.svelte | 15 ++++-- src/ui/views/Done.svelte | 49 +++++++++++-------- src/ui/views/NotSupported.svelte | 9 +++- src/ui/views/SelectOs.svelte | 21 +++++--- src/ui/views/WaitForDevice.svelte | 7 +-- 21 files changed, 182 insertions(+), 91 deletions(-) create mode 100644 branding.json diff --git a/afterPack.js b/afterPack.js index f26ed724..20696283 100644 --- a/afterPack.js +++ b/afterPack.js @@ -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 @@ -30,11 +31,11 @@ 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"); @@ -42,9 +43,9 @@ module.exports = async function (context) { } 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); }; diff --git a/branding.json b/branding.json new file mode 100644 index 00000000..e13c5aea --- /dev/null +++ b/branding.json @@ -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" +} diff --git a/build.js b/build.js index 0e121394..3682d2f4 100755 --- a/build.js +++ b/build.js @@ -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"]; @@ -60,9 +62,9 @@ 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: [ @@ -70,6 +72,7 @@ var buildConfig = { "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}` @@ -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: { diff --git a/public/index.html b/public/index.html index 8d20dbf6..4e1bc9ef 100644 --- a/public/index.html +++ b/public/index.html @@ -4,8 +4,6 @@ - UBports Installer - diff --git a/src/core/helpers/api.js b/src/core/helpers/api.js index 67eb64f6..b062489a 100644 --- a/src/core/helpers/api.js +++ b/src/core/helpers/api.js @@ -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>} */ -const getIndex = () => api.get("/").then(({ data }) => data); +const getIndex = () => api.get("/index.json").then(({ data }) => data); /** * get device selects object array diff --git a/src/lib/cli.js b/src/lib/cli.js index 059bbe22..798d3e8f 100755 --- a/src/lib/cli.js +++ b/src/lib/cli.js @@ -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} diff --git a/src/lib/log.js b/src/lib/log.js index 3604abb7..5a8b90e5 100644 --- a/src/lib/log.js +++ b/src/lib/log.js @@ -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, @@ -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" }); diff --git a/src/lib/mainEvent.js b/src/lib/mainEvent.js index f0a792dd..672e2e5e 100644 --- a/src/lib/mainEvent.js +++ b/src/lib/mainEvent.js @@ -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(); @@ -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); diff --git a/src/lib/menuManager.js b/src/lib/menuManager.js index 361da9b6..d3ee4f2a 100755 --- a/src/lib/menuManager.js +++ b/src/lib/menuManager.js @@ -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 { /** @@ -36,22 +37,26 @@ 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 ) }, @@ -59,7 +64,7 @@ class MenuManager { label: "License", click: () => shell.openExternal( - "https://github.com/ubports/ubports-installer/blob/" + + branding["licence-url"] + packageInfo.version + "/LICENSE" ) @@ -98,6 +103,7 @@ class MenuManager { }, { label: "Report a bug", + visible: branding["allow-reporting"], click: () => window.send("user:report") }, { @@ -167,6 +173,7 @@ class MenuManager { }, { label: "Never ask for OPEN-CUTS automatic reporting", + visible: branding["allow-reporting"], checked: settings.get("never.opencuts"), type: "checkbox", click: () => @@ -174,6 +181,7 @@ class MenuManager { }, { label: "OPEN-CUTS API Token", + visible: branding["allow-reporting"], click: () => reporter.tokenDialog(mainWindow) } ] @@ -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"] + ) } ] } diff --git a/src/lib/reporter.js b/src/lib/reporter.js index 5e88f06d..89fd0ef4 100644 --- a/src/lib/reporter.js +++ b/src/lib/reporter.js @@ -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 @@ -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}`, diff --git a/src/lib/udev.js b/src/lib/udev.js index cba26e94..95e95830 100644 --- a/src/lib/udev.js +++ b/src/lib/udev.js @@ -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", @@ -128,7 +129,7 @@ class Udev { sudo.exec( udevCommand, { - name: "UBports Installer", + name: branding.appname, icns: path.join(__dirname, "../../build/icons/icon.icns") }, error => { diff --git a/src/lib/updater.js b/src/lib/updater.js index efc655be..1080ba12 100644 --- a/src/lib/updater.js +++ b/src/lib/updater.js @@ -19,6 +19,7 @@ const axios = require("axios"); const packageInfo = require("../../package.json"); +const branding = require("../../branding.json"); /** * UBports Installer version management @@ -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" } @@ -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}` ); }); } diff --git a/src/lib/updater.spec.js b/src/lib/updater.spec.js index b5acbc42..a513ecd4 100644 --- a/src/lib/updater.spec.js +++ b/src/lib/updater.spec.js @@ -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"; @@ -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}` ); }); }); diff --git a/src/main.js b/src/main.js index cf24d330..5c967f4a 100755 --- a/src/main.js +++ b/src/main.js @@ -28,6 +28,7 @@ const mainEvent = require("./lib/mainEvent.js"); const reporter = require("./lib/reporter.js"); const menuManager = require("./lib/menuManager.js"); const core = require("./core/core.js"); +const branding = require("../branding.json"); // Enable live reload for Electron if (process.env.ROLLUP_WATCH) { @@ -47,14 +48,14 @@ ipcMain.on("reportResult", async (event, result, error) => { // Restart the installer // FIXME move after a better way to access mainWindow has been found mainEvent.on("restart", () => { - log.info("UBports Installer restarting..."); + log.info(`${branding.appname} restarting...`); core.kill(); mainWindow.reload(); }); async function createWindow() { log.info( - "Welcome to the UBports Installer version " + packageInfo.version + "!" + `Welcome to the ${branding.appname} version ${packageInfo.version}!` ); log.verbose("Versions: " + JSON.stringify(process.versions)); @@ -64,7 +65,7 @@ async function createWindow() { height: 750, minHeight: 600, icon: path.join(__dirname, "../build/icons/icon.png"), - title: "UBports Installer (" + packageInfo.version + ")", + title: branding.appname, kiosk: false, fullscreen: false, webPreferences: { diff --git a/src/ui/modals/specific-modals/SelectDeviceModal.svelte b/src/ui/modals/specific-modals/SelectDeviceModal.svelte index c4e0edef..f22cb596 100644 --- a/src/ui/modals/specific-modals/SelectDeviceModal.svelte +++ b/src/ui/modals/specific-modals/SelectDeviceModal.svelte @@ -3,9 +3,14 @@ const { ipcRenderer } = require("electron"); import { createEventDispatcher } from "svelte"; import { deviceSelectOptions } from "../../../stores.mjs"; + import branding from "../../../../branding.json"; let selectedDevice; + let supported = branding["supported-devices"] + .replace(/(^\w+:|^)\/\//, '') + .replace(/\/.*$/, ''); + function selectDevice(device) { ipcRenderer.send("device:selected", device); close(); @@ -30,16 +35,18 @@ -

- Not all Ubuntu Touch devices - are supported by the UBports Installer yet. You can find installation instructions - for devices not listed here on - devices.ubuntu-touch.io. If - you want to help, you can - contribute a config file for any device and operating system! -

+ {#if !branding["all-devices-supported"]} +

+ Not all {branding.os} devices + are supported by the {branding.appname} yet. You can find installation instructions + for devices not listed here on + {supported}. If + you want to help, you can + contribute a config file for any device and operating system! +

+ {/if}

Please do not try to install other devices images on your device. It will not work! { footerData.set({ - topText: "UBports Installer is starting up", + topText: branding.appname + " is starting up", underText: "Starting adb service" }); }); diff --git a/src/ui/partials/Header.svelte b/src/ui/partials/Header.svelte index 44dc0df8..3a642cfd 100644 --- a/src/ui/partials/Header.svelte +++ b/src/ui/partials/Header.svelte @@ -1,5 +1,6 @@

@@ -16,28 +17,36 @@ The installation process from the computer is done. The device will now perform the remaining steps which should take less than five minutes. After the installation, the device will reboot and you can begin to - explore Ubuntu Touch. + explore {branding.os}.

+ {#if branding.feedback} +

+ Found something you don't like? Tell us, or help us change it! +

+ {/if}

- Found something you don't like? Tell us, or help us change it! -

-

- Development of Ubuntu Touch is driven by the UBports Community. Donate now to allow us to - continue our mission! - Get involved - Donate + Development of Ubuntu Touch and this installer is driven by the + UBports Community. + {#if branding["donate-url"]} + Donate now to allow us to + continue our mission! + {/if} + {#if branding.participate} + Get involved + {/if} + {#if branding["donate-url"]} + Donate + {/if}

Got more devices you want to flash? diff --git a/src/ui/views/NotSupported.svelte b/src/ui/views/NotSupported.svelte index 89c775ce..e483588c 100644 --- a/src/ui/views/NotSupported.svelte +++ b/src/ui/views/NotSupported.svelte @@ -1,5 +1,10 @@

@@ -22,7 +27,7 @@

See - devices.ubuntu-touch.io + {supported} for more info


@@ -30,7 +35,7 @@

You can try selecting your device manually, but please only do so if you're sure that your exact model is actually supported! You might also - want to file a bug. + want to file a bug.