Skip to content

Commit e2cb619

Browse files
committed
dev: add startup apps, start emulator by default
1 parent e1ec848 commit e2cb619

File tree

8 files changed

+70
-4
lines changed

8 files changed

+70
-4
lines changed

doc/devmeta/track-comments.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ Comments beginning with `// track:`. See
5757
It may be applicable to write an iterator in the
5858
future, or something will come up that require
5959
these to be handled with a modular approach instead.
60+
- `track: checkpoint`
61+
A location where some statement about the state of the
62+
software must hold true.

src/backend/src/services/BaseService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
const { AdvancedBase } = require("../../../putility");
19+
const { concepts } = require("@heyputer/putility");
2020

2121
const NOOP = async () => {};
2222

23-
class BaseService extends AdvancedBase {
23+
class BaseService extends concepts.Service {
2424
constructor (service_resources, ...a) {
2525
const { services, config, my_config, name, args } = service_resources;
2626
super(service_resources, ...a);

src/gui/src/UI/UIDesktop.js

+6
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ async function UIDesktop(options){
10221022
// adjust window container to take into account the toolbar height
10231023
$('.window-container').css('top', window.toolbar_height);
10241024

1025+
// track: checkpoint
1026+
//-----------------------------
1027+
// GUI is ready to launch apps!
1028+
//-----------------------------
1029+
1030+
globalThis.services.emit('gui:ready');
10251031

10261032
//--------------------------------------------------------------------------------------
10271033
// Determine if an app was launched from URL

src/gui/src/definitions.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
import { AdvancedBase } from "@heyputer/putility";
20+
import { concepts, AdvancedBase } from "@heyputer/putility";
2121

22-
export class Service {
22+
export class Service extends concepts.Service {
23+
// TODO: Service todo items
24+
static TODO = [
25+
'consolidate with BaseService from backend'
26+
];
2327
construct (o) {
2428
this.$puter = {};
2529
for ( const k in o ) this.$puter[k] = o[k];
@@ -28,6 +32,7 @@ export class Service {
2832
}
2933
init (...a) {
3034
if ( ! this._init ) return;
35+
this.services = a[0].services;
3136
return this._init(...a)
3237
}
3338
};

src/gui/src/initgui.js

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const launch_services = async function (options) {
5555
const services_m_ = {};
5656
globalThis.services = {
5757
get: (name) => services_m_[name],
58+
emit: (id, args) => {
59+
for (const [_, instance] of services_l_) {
60+
instance.__on(id, args ?? []);
61+
}
62+
}
5863
};
5964
const register = (name, instance) => {
6065
services_l_.push([name, instance]);

src/gui/src/services/ProcessService.js

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import { InitProcess, Service } from "../definitions.js";
2222
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
2323

2424
export class ProcessService extends Service {
25+
static INITRC = [
26+
'test-emu'
27+
];
28+
2529
async _init () {
2630
this.processes = [];
2731
this.processes_map = new Map();
@@ -33,6 +37,19 @@ export class ProcessService extends Service {
3337
this.register_(root);
3438
}
3539

40+
['__on_gui:ready'] () {
41+
const svc_exec = this.services.get('exec');
42+
for ( let spec of ProcessService.INITRC ) {
43+
if ( typeof spec === 'string' ) {
44+
spec = { name: spec };
45+
}
46+
47+
svc_exec.launchApp({
48+
app_name: spec.name,
49+
});
50+
}
51+
}
52+
3653
get_init () {
3754
return this.processes_map.get(NULL_UUID);
3855
}

src/putility/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919
const { AdvancedBase } = require('./src/AdvancedBase');
20+
const { Service } = require('./src/concepts/Service');
2021

2122
module.exports = {
2223
AdvancedBase,
2324
libs: {
2425
promise: require('./src/libs/promise'),
2526
},
27+
concepts: {
28+
Service,
29+
},
2630
};

src/putility/src/concepts/Service.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { AdvancedBase } = require("../AdvancedBase");
2+
3+
const NOOP = async () => {};
4+
5+
/**
6+
* Service will be incrementally updated to consolidate
7+
* BaseService in Puter's backend with Service in Puter's frontend,
8+
* becoming the common base for both and a useful utility in general.
9+
*/
10+
class Service extends AdvancedBase {
11+
async __on (id, args) {
12+
const handler = this.__get_event_handler(id);
13+
14+
return await handler(id, ...args);
15+
}
16+
17+
__get_event_handler (id) {
18+
return this[`__on_${id}`]?.bind?.(this)
19+
|| this.constructor[`__on_${id}`]?.bind?.(this.constructor)
20+
|| NOOP;
21+
}
22+
}
23+
24+
module.exports = {
25+
Service,
26+
};

0 commit comments

Comments
 (0)