Skip to content

Commit

Permalink
Show hidden systemimage channels (#2503)
Browse files Browse the repository at this point in the history
* Show hidden systemimage channels
hidden channels are presented in a separate section at the end of the dropdown.
Replaces #2432.

* implement hidden channels setting
  • Loading branch information
NeoTheThird authored Mar 21, 2022
1 parent 57473b0 commit 89f4352
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 29 deletions.
9 changes: 8 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const YAML = require("yaml");
const mainEvent = require("../lib/mainEvent.js");
const { path: cachePath } = require("../lib/cache.js");
const log = require("../lib/log.js");
const settings = require("../lib/settings.js");
const errors = require("../lib/errors.js");
const window = require("../lib/window.js");
const api = require("./helpers/api.js");
Expand All @@ -48,7 +49,13 @@ class Core {
constructor() {
this.props = {};
this.reset();
this.plugins = new PluginIndex(this.props, cachePath, mainEvent, log);
this.plugins = new PluginIndex(
this.props,
cachePath,
mainEvent,
log,
settings
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/core/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ const SystemimagePlugin = require("./systemimage/plugin.js");
* @property {SystemimagePlugin} plugins.systemimage systemimage plugin
*/
class PluginIndex {
constructor(props, cachePath, mainEvent, log) {
constructor(props, cachePath, mainEvent, log, settings) {
this.props = props;
this.log = log;
this.settings = settings;
this.event = mainEvent;
const pluginArgs = [props, cachePath, this.event, log];
const pluginArgs = [props, cachePath, this.event, log, settings];
this.plugins = {
adb: new AdbPlugin(...pluginArgs),
asteroid_os: new AsteroidOsPlugin(...pluginArgs),
Expand Down
4 changes: 3 additions & 1 deletion src/core/plugins/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const log = {
error: jest.fn()
};

const pluginArgs = [{}, "a", {}, log];
const settings = {};

const pluginArgs = [{}, "a", {}, log, settings];

const pluginIndex = new (require("./index.js"))(...pluginArgs);
const originalPluginList = pluginIndex.plugins;
Expand Down
4 changes: 3 additions & 1 deletion src/core/plugins/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class Plugin {
* @param {String} cachePath cache path
* @param {EventEmitter} event event
* @param {Object} log logger
* @param {Object} settings settings manager
*/
constructor(props, cachePath, event, log) {
constructor(props, cachePath, event, log, settings) {
this.props = props;
this.cachePath = cachePath;
this.event = event;
this.log = log;
this.settings = settings;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/core/plugins/systemimage/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,17 @@ const getChannels = device =>
!(
(
!properties ||
properties.hidden ||
properties.redirect ||
(properties.alias && properties.hidden) ||
!properties.devices
) // remove invalid channels
) && properties.devices[device] // remove channels that don't serve this device
)
.map(([name]) => name)
.map(([name, properties]) => ({
value: name,
label: name.replace("ubports-touch/", ""),
hidden: properties.hidden || false
}))
);

module.exports = { getImages, getChannels };
24 changes: 20 additions & 4 deletions src/core/plugins/systemimage/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,31 @@ unmount system",
it("should resolve channels", () => {
axios.get.mockResolvedValue({
data: {
"16.04/stable": { devices: { bacon: "a" } },
"ubports-touch/16.04/stable": { devices: { bacon: "a" } },
"16.04/stable": {
devices: { bacon: "a" },
hidden: true,
alias: "ubports-touch/16.04/stable"
},
"17.04/stable": { devices: { bacon: "a" }, hidden: true },
"18.04/stable": { devices: { bacon: "a" }, redirect: "asdf" },
"19.04/stable": { devices: { hamburger: "a" } }
}
});
return api
.getChannels("bacon")
.then(r => expect(r).toEqual(["16.04/stable"]));
return api.getChannels("bacon").then(r =>
expect(r).toEqual([
{
hidden: false,
label: "16.04/stable",
value: "ubports-touch/16.04/stable"
},
{
hidden: true,
label: "17.04/stable",
value: "17.04/stable"
}
])
);
});
});
});
Expand Down
23 changes: 15 additions & 8 deletions src/core/plugins/systemimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ class SystemimagePlugin extends Plugin {
* @returns {Promise<Array<Object>>}
*/
remote_values__channels() {
return api.getChannels(this.props.config.codename).then(channels =>
channels
.map(channel => ({
value: channel,
label: channel.replace("ubports-touch/", "")
}))
.reverse()
);
return api
.getChannels(this.props.config.codename)
.then(channels => ({
visible: channels.filter(({ hidden }) => !hidden).reverse(),
hidden: this.settings.get("systemimage.showHiddenChannels")
? channels.filter(({ hidden }) => hidden)
: []
}))
.then(({ visible, hidden }) => [
...visible.map(({ value, label }) => ({ value, label })),
...(hidden.length
? [{ label: "--- hidden channels ---", disabled: true }]
: []),
...hidden.map(({ value, label }) => ({ value, label }))
]);
}
}

Expand Down
73 changes: 64 additions & 9 deletions src/core/plugins/systemimage/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ api.getImages.mockResolvedValue({
files: [{ url: "a/s/d/f" }],
commands: "here be dragons"
});
api.getChannels.mockResolvedValue([
"ubports-touch/16.04/devel",
"ubports-touch/16.04/stable"
]);
const systemimage = new (require("./plugin.js"))({
os: { name: "Ubuntu Touch" },
config: { codename: "bacon" },
settings: { channel: "ubports-touch/16.04/stable" }
});

systemimage.settings = {
get: jest.fn()
};

beforeEach(() => jest.clearAllMocks());

describe("systemimage plugin", () => {
describe("actions", () => {
describe("download", () => {
Expand Down Expand Up @@ -51,13 +53,66 @@ describe("systemimage plugin", () => {
});
describe("remote_values", () => {
describe("channels", () => {
it("should resolve channels", () =>
systemimage.remote_values__channels().then(r =>
it("should resolve channels", () => {
systemimage.settings.get.mockReturnValueOnce(false);
api.getChannels.mockResolvedValueOnce([
{
hidden: false,
label: "16.04/stable",
value: "ubports-touch/16.04/stable"
},
{
hidden: true,
label: "17.04/stable",
value: "17.04/stable"
}
]);
return systemimage.remote_values__channels().then(r => {
expect(r).toEqual([
{ label: "16.04/stable", value: "ubports-touch/16.04/stable" }
]);
expect(systemimage.settings.get).toHaveBeenCalledTimes(1);
});
});
it("should resolve channels including hidden channels if set", () => {
systemimage.settings.get.mockReturnValueOnce(true);
api.getChannels.mockResolvedValueOnce([
{
hidden: false,
label: "16.04/stable",
value: "ubports-touch/16.04/stable"
},
{
hidden: true,
label: "17.04/stable",
value: "17.04/stable"
}
]);
return systemimage.remote_values__channels().then(r => {
expect(r).toEqual([
{ label: "16.04/stable", value: "ubports-touch/16.04/stable" },
{ label: "16.04/devel", value: "ubports-touch/16.04/devel" }
])
));
{ label: "--- hidden channels ---", disabled: true },
{ label: "17.04/stable", value: "17.04/stable" }
]);
expect(systemimage.settings.get).toHaveBeenCalledTimes(1);
});
});
it("should not include hidden channels separator if none specified", () => {
api.getChannels.mockResolvedValueOnce([
{
hidden: false,
label: "16.04/stable",
value: "ubports-touch/16.04/stable"
}
]);
systemimage
.remote_values__channels()
.then(r =>
expect(r).toEqual([
{ label: "16.04/stable", value: "ubports-touch/16.04/stable" }
])
);
});
});
});
});
10 changes: 10 additions & 0 deletions src/lib/menuManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ class MenuManager {
window.send("settings:animations", settings.get("animations"));
}
},
{
label: "Show hidden System-Image Channels",
checked: settings.get("systemimage.showHiddenChannels"),
type: "checkbox",
click: () =>
settings.set(
"systemimage.showHiddenChannels",
!settings.get("systemimage.showHiddenChannels")
)
},
{
label: "Never ask for udev rules",
checked: settings.get("never.udev"),
Expand Down
6 changes: 6 additions & 0 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const settings = new Store({
type: "boolean",
default: false
}
},
systemimage: {
showHiddenChannels: {
type: "boolean",
default: false
}
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/ui/modals/specific-modals/PromptModals.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
{#if field.type === "select"}
<select class="form-select" bind:value={formData[id][field.var]}>
{#each field.values as value}
<option value={value.value}>{value.label}</option>
<option disabled={value.disabled} value={value.value}
>{value.label}</option
>
{/each}
</select>
{:else if field.type === "checkbox"}
Expand Down

0 comments on commit 89f4352

Please sign in to comment.