Skip to content

Commit

Permalink
Add AsteroidOS plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoTheThird committed Jan 6, 2021
1 parent 890cec8 commit 95745e5
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ubports-installer",
"version": "0.8.3-beta",
"version": "0.8.4-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
74 changes: 74 additions & 0 deletions src/core/plugins/asteroid_os/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use strict";

/*
* Copyright (C) 2020-2021 UBports Foundation <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const axios = require("axios");

/** @module asteroid_os */

const baseURL = "https://release.asteroidos.org/";

const api = axios.create({ baseURL, timeout: 15000 });

/**
* get images from api
* @param {String} channel channel
* @param {String} device device codename
* @returns {Promise<Array<Object>>} images array
* @throws {Error} message "no network" if request failed
*/
const getImages = (channel, device) =>
api
.get(`${channel}/${device}/MD5SUMS`)
.then(({ data }) =>
data
.trim()
.split("\n")
.map(line => ({
url: `${baseURL}${channel}/${device}/${line.split(/[ ,]+/)[1]}`,
checksum: {
sum: line.split(/[ ,]+/)[0],
algorithm: "md5"
}
}))
)
.catch(error => {
if (error.response.status === 404) throw new Error("404");
else if (error.response) throw new Error("no network");
else throw error;
});

/**
* get channels from api
* @param {String} device device codename
* @returns {Promise<Array<String>>} channels
* @throws {Error} message "unsupported" if 404 not found
*/
const getChannels = device =>
Promise.all(
["1.0", "nightlies", "1.0-alpha"].map(channel =>
getImages(channel, device)
.then(() => channel)
.catch(error => {
if (error.message === "404") return null;
else throw error;
})
)
).then(channels => channels.filter(c => c));

module.exports = { getImages, getChannels };
7 changes: 7 additions & 0 deletions src/core/plugins/asteroid_os/api.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
process.argv = [null, null, "-vv"];
const { ipcMain } = require("electron");
jest.mock("electron");

const api = require("./api.js");

it("should construct", () => expect(require("./api.js")).toBeDefined());
63 changes: 63 additions & 0 deletions src/core/plugins/asteroid_os/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";

/*
* Copyright (C) 2020-2021 UBports Foundation <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const Plugin = require("../plugin.js");
const api = require("./api.js");

/**
* Asteroid OS plugin
* @extends Plugin
*/
class AsteroidOsPlugin extends Plugin {
/**
* action download
* @returns {Promise<Array<Object>>}
*/
action__download() {
return api
.getImages(this.props.settings.channel, this.props.config.codename)
.then(files => [
{
actions: [
{
"core:download": {
group: "AsteroidOS",
files
}
}
]
}
]);
}

/**
* channels remote_values
* @returns {Promise<Array<Object>>}
*/
remote_values__channels() {
return api.getChannels(this.props.config.codename).then(channels =>
channels.map(channel => ({
value: channel,
label: channel
}))
);
}
}

module.exports = AsteroidOsPlugin;
4 changes: 4 additions & 0 deletions src/core/plugins/asteroid_os/plugin.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const systemimage = require("./plugin.js");

it("should be a singleton", () =>
expect(systemimage).toEqual(require("./plugin.js")));
5 changes: 4 additions & 1 deletion src/core/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

/*
* Copyright (C) 2020 UBports Foundation <[email protected]>
* Copyright (C) 2020-2021 UBports Foundation <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,6 +18,7 @@
*/

const AdbPlugin = require("./adb/plugin.js");
const AsteroidOsPlugin = require("./asteroid_os/plugin.js");
const CorePlugin = require("./core/plugin.js");
const FastbootPlugin = require("./fastboot/plugin.js");
const HeimdallPlugin = require("./heimdall/plugin.js");
Expand All @@ -28,6 +29,7 @@ const SystemimagePlugin = require("./systemimage/plugin.js");
* @property {Props} props props reference
* @property {Object} plugins plugins namespace
* @property {AdbPlugin} plugins.adb adb plugin
* @property {AsteroidOsPlugin} plugins.asteroid_os AteroidOS plugin
* @property {CorePlugin} plugins.core core plugin
* @property {FastbootPlugin} plugins.fastboot fastboot plugin
* @property {HeimdallPlugin} plugins.heimdall heimdall plugin
Expand All @@ -40,6 +42,7 @@ class PluginIndex {
const pluginArgs = [props, cachePath, mainEvent, log];
this.plugins = {
adb: new AdbPlugin(...pluginArgs),
asteroid_os: new AsteroidOsPlugin(...pluginArgs),
core: new CorePlugin(...pluginArgs),
fastboot: new FastbootPlugin(...pluginArgs),
heimdall: new HeimdallPlugin(...pluginArgs),
Expand Down

0 comments on commit 95745e5

Please sign in to comment.