diff --git a/CHANGELOG.md b/CHANGELOG.md index 47abe30d..d46571ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * Add `Alchemy#afterStart()` method * Add `Alchemy#isProcessRunning(pid)` method * Complete Task system implementation +* Added task menu item to Janeway + added actions to it & the session menu ## 1.3.16 (2023-10-05) diff --git a/lib/class/session.js b/lib/class/session.js index 066dbb8b..872a4c8b 100644 --- a/lib/class/session.js +++ b/lib/class/session.js @@ -167,7 +167,7 @@ Session.setMethod(function hasAlreadyQueued() { * * @author Jelle De Loecker * @since 0.2.0 - * @version 0.4.0 + * @version 1.3.17 * * @param {Conduit} conduit The conduit to postpone * @@ -187,7 +187,12 @@ Session.setMethod(function createMenuItem(conduit) { browser += ': ' + conduit.ip; - this.menu_item = alchemy.Janeway.session_menu.addItem(browser); + this.menu_item = alchemy.Janeway.session_menu.addItem(browser, () => { + console.log('Clicked on session', this, this.id); + }); + + // Seems to fix render issues: + alchemy.Janeway.session_menu.reorderItems(); }); /** diff --git a/lib/class/task_service.js b/lib/class/task_service.js index f56d9b43..cf782446 100644 --- a/lib/class/task_service.js +++ b/lib/class/task_service.js @@ -31,6 +31,10 @@ const Service = Function.inherits('Alchemy.Base', 'Alchemy.Task', function TaskS this.initSchedules(); singleton = this; + + if (alchemy.settings.janeway_task_menu) { + this.createJanewayTaskMenu(); + } }); /** @@ -219,6 +223,34 @@ Service.setMethod(async function initSchedules() { this.has_loaded = true; }); +/** + * Create the Janeway task menu + * + * @author Jelle De Loecker + * @since 1.3.17 + * @version 1.3.17 + */ +Service.setMethod(function createJanewayTaskMenu() { + + if (!alchemy.Janeway || alchemy.Janeway?.task_menu) { + return; + } + + let task_menu = alchemy.Janeway.addIndicator('⌚︎'); + + if (!task_menu.addItem) { + return task_menu.remove(); + } + + task_menu.addItem('Currently scheduled tasks:', () => { + console.log('Currently scheduled tasks:', this.schedules); + }); + + alchemy.Janeway.task_menu = task_menu; + this.janeway_task_menu = task_menu; + this.janeway_task_menu_entries = []; +}); + /** * Update all the schedule `setTimeout` calls that need it * @@ -457,6 +489,7 @@ class TaskSchedule { is_running = false; task_instance = null; history_document = null; + janeway_menu_item = null; #change_counter = 0; @@ -619,6 +652,14 @@ class TaskSchedule { return; } + if (alchemy.task_service.janeway_task_menu) { + let title = this.task_document?.title || this.task_schedules.task_constructor.type_name; + title += ' @ ' + scheduled_date.format('Y-m-d H:i:s'); + this.janeway_menu_item = alchemy.task_service.janeway_task_menu.addItem(title, () => this.clickedJanewayMenuItem()); + // Seems to fix render issues: + alchemy.task_service.janeway_task_menu.reorderItems(); + } + // Calculate the timeout that should be set let timeout = scheduled_date.getTime() - Date.now(); @@ -636,6 +677,17 @@ class TaskSchedule { return this.#setDateAndTimeout(scheduled_date, timeout); } + /** + * Do something when the Janeway menu item is clicked. + * + * @author Jelle De Loecker + * @since 1.3.17 + * @version 1.3.17 + */ + clickedJanewayMenuItem() { + console.log('Clicked on scheduled task:', this); + } + /** * Actually set the date & timeout (and history document) * @@ -716,6 +768,21 @@ class TaskSchedule { } this.is_running = true; + let janeway_item; + let janeway_title; + + try { + if (alchemy.task_service.janeway_task_menu) { + janeway_title = this.task_document?.title || this.task_schedules.task_constructor.type_name; + let title = 'Currently running: ' + janeway_title; + + janeway_item = alchemy.task_service.janeway_task_menu.addItem(title, () => this.clickedJanewayMenuItem()); + // Seems to fix render issues: + alchemy.task_service.janeway_task_menu.reorderItems(); + } + } catch (err) { + alchemy.registerError(err); + } try { if (await this.ownsScheduledTask()) { @@ -733,6 +800,12 @@ class TaskSchedule { this.is_running = false; this.calculateNextScheduledDate(); + + if (janeway_item) { + let title = 'Finished: ' + janeway_title; + janeway_item.box.setContent(title); + setTimeout(() => janeway_item.remove(), 5000); + } } /** @@ -747,5 +820,10 @@ class TaskSchedule { this.timer_id = null; this.next_scheduled_date = null; this.#change_counter++; + + if (this.janeway_menu_item) { + this.janeway_menu_item.remove(); + this.janeway_menu_item = null; + } } } \ No newline at end of file diff --git a/lib/init/alchemy.js b/lib/init/alchemy.js index aae494fb..7b744413 100644 --- a/lib/init/alchemy.js +++ b/lib/init/alchemy.js @@ -496,6 +496,10 @@ Alchemy.setMethod(function startJaneway(options) { return session_menu.remove(); } + session_menu.addItem('Current active browser sessions:', () => { + console.log('All sessions:', alchemy.sessions); + }); + this.Janeway.session_menu = session_menu; }