-
Commands stored on the browser
+
+
Actions stored locally for {{ host }}
+
Actions stored locally
+
+
+
No actions available on this device
+
+
+
@@ -10,7 +53,166 @@ import mixins from '../utils';
export default {
name: 'LocalCommands',
mixins: [mixins],
+ props: {
+ host: String,
+ },
+
+ data() {
+ return {
+ hosts: {},
+ actions_: {},
+ selectedAction: null,
+ response: null,
+ error: null,
+ };
+ },
+
+ computed: {
+ actionsByHost() {
+ return Object.entries(this.actions_).reduce((obj, [name, action]) => {
+ const hosts = action.hosts || [];
+ for (const host of hosts) {
+ if (!(host in obj)) {
+ obj[host] = {};
+ }
+
+ obj[host][name] = action;
+ }
+
+ return obj;
+ }, {});
+ },
+
+ actions() {
+ return this.host ? this.actionsByHost[this.host] : this.actions_;
+ },
+ },
+
+ methods: {
+ async loadActions() {
+ this.actions_ = await this.getActions();
+ },
+
+ async loadHosts() {
+ this.hosts = await this.getHosts();
+ },
+
+ async removeAction() {
+ if (!this.selectedAction || !(this.selectedAction in this.actions_) || !confirm('Are you sure that you want to remove this action from this device?')) {
+ return;
+ }
+
+ const action = this.actions_[this.selectedAction];
+ const hostIndex = action.hosts.indexOf(this.host);
+ if (hostIndex < 0) {
+ return;
+ }
+
+ action.hosts.splice(hostIndex, 1);
+ if (action.hosts.length === 0) {
+ delete this.actions_[this.selectedAction];
+ } else {
+ this.actions_[this.selectedAction] = action;
+ }
+
+ await this.saveActions(this.actions_);
+ await this.loadActions();
+ },
+
+ async runAction() {
+ if (!(this.selectedAction && this.host && this.selectedAction in this.actions)) {
+ return;
+ }
+
+ const action = this.actions[this.selectedAction];
+ this.error = null;
+
+ try {
+ this.response = await this.run(action, this.hosts[this.host]);
+ } catch (e) {
+ this.error = e.message;
+ }
+ },
+
+ toggleSelectedAction(name) {
+ this.response = null;
+ this.error = null;
+ this.selectedAction = this.selectedAction === name ? null : name;
+ },
+ },
+
+ created() {
+ this.loadHosts();
+ this.loadActions();
+ },
};
+
+
diff --git a/src/options/Menu.vue b/src/options/Menu.vue
index 4186303..d7df9d8 100644
--- a/src/options/Menu.vue
+++ b/src/options/Menu.vue
@@ -1,6 +1,12 @@
+
+
+
+
+
+
diff --git a/src/options/Run.vue b/src/options/Run.vue
index 30e72e2..30ef392 100644
--- a/src/options/Run.vue
+++ b/src/options/Run.vue
@@ -66,6 +66,14 @@
+