CustomPuterService.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2024-present Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. const path = require('path');
  20. class CustomPuterService extends use.Service {
  21. async _init () {
  22. const svc_commands = this.services.get('commands');
  23. this._register_commands(svc_commands);
  24. const svc_puterHomepage = this.services.get('puter-homepage');
  25. svc_puterHomepage.register_script('/custom-gui/main.js');
  26. }
  27. ['__on_install.routes'] (_, { app }) {
  28. const require = this.require;
  29. const express = require('express');
  30. const path_ = require('path');
  31. app.use('/custom-gui',
  32. express.static(path.join(__dirname, 'gui')));
  33. }
  34. async ['__on_boot.consolidation'] () {
  35. const then = Date.now();
  36. this.tod_widget = () => {
  37. const s = 5 - Math.floor(
  38. (Date.now() - then) / 1000);
  39. const lines = [
  40. "\x1B[36;1mKDMOD ENABLED\x1B[0m" +
  41. ` (👁️ ${s}s)`
  42. ];
  43. // It would be super cool to be able to use this here
  44. // surrounding_box('33;1', lines);
  45. return lines;
  46. }
  47. const svc_devConsole = this.services.get('dev-console', { optional: true });
  48. if ( ! svc_devConsole ) return;
  49. svc_devConsole.add_widget(this.tod_widget);
  50. setTimeout(() => {
  51. svc_devConsole.remove_widget(this.tod_widget);
  52. }, 5000)
  53. }
  54. _register_commands (commands) {
  55. commands.registerCommands('o', [
  56. {
  57. id: 'k',
  58. description: '',
  59. handler: async (_, log) => {
  60. const svc_devConsole = this.services.get('dev-console', { optional: true });
  61. if ( ! svc_devConsole ) return;
  62. svc_devConsole.remove_widget(this.tod_widget);
  63. const lines = this.tod_widget();
  64. for ( const line of lines ) log.log(line);
  65. this.tod_widget = null;
  66. }
  67. }
  68. ]);
  69. }
  70. }
  71. module.exports = { CustomPuterService };