CustomPuterService.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const path = require('path');
  2. class CustomPuterService extends use.Service {
  3. async _init () {
  4. const svc_commands = this.services.get('commands');
  5. this._register_commands(svc_commands);
  6. const svc_puterHomepage = this.services.get('puter-homepage');
  7. svc_puterHomepage.register_script('/custom-gui/main.js');
  8. }
  9. ['__on_install.routes'] (_, { app }) {
  10. const require = this.require;
  11. const express = require('express');
  12. const path_ = require('path');
  13. app.use('/custom-gui',
  14. express.static(path.join(__dirname, 'gui')));
  15. }
  16. async ['__on_boot.consolidation'] () {
  17. const then = Date.now();
  18. this.tod_widget = () => {
  19. const s = 5 - Math.floor(
  20. (Date.now() - then) / 1000);
  21. const lines = [
  22. "\x1B[36;1mKDMOD ENABLED\x1B[0m" +
  23. ` (👁️ ${s}s)`
  24. ];
  25. // It would be super cool to be able to use this here
  26. // surrounding_box('33;1', lines);
  27. return lines;
  28. }
  29. const svc_devConsole = this.services.get('dev-console', { optional: true });
  30. if ( ! svc_devConsole ) return;
  31. svc_devConsole.add_widget(this.tod_widget);
  32. setTimeout(() => {
  33. svc_devConsole.remove_widget(this.tod_widget);
  34. }, 5000)
  35. }
  36. _register_commands (commands) {
  37. commands.registerCommands('o', [
  38. {
  39. id: 'k',
  40. description: '',
  41. handler: async (_, log) => {
  42. const svc_devConsole = this.services.get('dev-console', { optional: true });
  43. if ( ! svc_devConsole ) return;
  44. svc_devConsole.remove_widget(this.tod_widget);
  45. const lines = this.tod_widget();
  46. for ( const line of lines ) log.log(line);
  47. this.tod_widget = null;
  48. }
  49. }
  50. ]);
  51. }
  52. }
  53. module.exports = { CustomPuterService };