mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
dev: add startup apps, start emulator by default
This commit is contained in:
parent
258b3cafd1
commit
0acd904176
@ -57,3 +57,6 @@ Comments beginning with `// track:`. See
|
||||
It may be applicable to write an iterator in the
|
||||
future, or something will come up that require
|
||||
these to be handled with a modular approach instead.
|
||||
- `track: checkpoint`
|
||||
A location where some statement about the state of the
|
||||
software must hold true.
|
||||
|
@ -16,11 +16,11 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require("../../../putility");
|
||||
const { concepts } = require("@heyputer/putility");
|
||||
|
||||
const NOOP = async () => {};
|
||||
|
||||
class BaseService extends AdvancedBase {
|
||||
class BaseService extends concepts.Service {
|
||||
constructor (service_resources, ...a) {
|
||||
const { services, config, my_config, name, args } = service_resources;
|
||||
super(service_resources, ...a);
|
||||
|
@ -1022,6 +1022,12 @@ async function UIDesktop(options){
|
||||
// adjust window container to take into account the toolbar height
|
||||
$('.window-container').css('top', window.toolbar_height);
|
||||
|
||||
// track: checkpoint
|
||||
//-----------------------------
|
||||
// GUI is ready to launch apps!
|
||||
//-----------------------------
|
||||
|
||||
globalThis.services.emit('gui:ready');
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Determine if an app was launched from URL
|
||||
|
@ -17,9 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AdvancedBase } from "@heyputer/putility";
|
||||
import { concepts, AdvancedBase } from "@heyputer/putility";
|
||||
|
||||
export class Service {
|
||||
export class Service extends concepts.Service {
|
||||
// TODO: Service todo items
|
||||
static TODO = [
|
||||
'consolidate with BaseService from backend'
|
||||
];
|
||||
construct (o) {
|
||||
this.$puter = {};
|
||||
for ( const k in o ) this.$puter[k] = o[k];
|
||||
@ -28,6 +32,7 @@ export class Service {
|
||||
}
|
||||
init (...a) {
|
||||
if ( ! this._init ) return;
|
||||
this.services = a[0].services;
|
||||
return this._init(...a)
|
||||
}
|
||||
};
|
||||
|
@ -55,6 +55,11 @@ const launch_services = async function (options) {
|
||||
const services_m_ = {};
|
||||
globalThis.services = {
|
||||
get: (name) => services_m_[name],
|
||||
emit: (id, args) => {
|
||||
for (const [_, instance] of services_l_) {
|
||||
instance.__on(id, args ?? []);
|
||||
}
|
||||
}
|
||||
};
|
||||
const register = (name, instance) => {
|
||||
services_l_.push([name, instance]);
|
||||
|
@ -22,6 +22,10 @@ import { InitProcess, Service } from "../definitions.js";
|
||||
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
export class ProcessService extends Service {
|
||||
static INITRC = [
|
||||
'test-emu'
|
||||
];
|
||||
|
||||
async _init () {
|
||||
this.processes = [];
|
||||
this.processes_map = new Map();
|
||||
@ -33,6 +37,19 @@ export class ProcessService extends Service {
|
||||
this.register_(root);
|
||||
}
|
||||
|
||||
['__on_gui:ready'] () {
|
||||
const svc_exec = this.services.get('exec');
|
||||
for ( let spec of ProcessService.INITRC ) {
|
||||
if ( typeof spec === 'string' ) {
|
||||
spec = { name: spec };
|
||||
}
|
||||
|
||||
svc_exec.launchApp({
|
||||
app_name: spec.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
get_init () {
|
||||
return this.processes_map.get(NULL_UUID);
|
||||
}
|
||||
|
@ -17,10 +17,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const { AdvancedBase } = require('./src/AdvancedBase');
|
||||
const { Service } = require('./src/concepts/Service');
|
||||
|
||||
module.exports = {
|
||||
AdvancedBase,
|
||||
libs: {
|
||||
promise: require('./src/libs/promise'),
|
||||
},
|
||||
concepts: {
|
||||
Service,
|
||||
},
|
||||
};
|
||||
|
26
src/putility/src/concepts/Service.js
Normal file
26
src/putility/src/concepts/Service.js
Normal file
@ -0,0 +1,26 @@
|
||||
const { AdvancedBase } = require("../AdvancedBase");
|
||||
|
||||
const NOOP = async () => {};
|
||||
|
||||
/**
|
||||
* Service will be incrementally updated to consolidate
|
||||
* BaseService in Puter's backend with Service in Puter's frontend,
|
||||
* becoming the common base for both and a useful utility in general.
|
||||
*/
|
||||
class Service extends AdvancedBase {
|
||||
async __on (id, args) {
|
||||
const handler = this.__get_event_handler(id);
|
||||
|
||||
return await handler(id, ...args);
|
||||
}
|
||||
|
||||
__get_event_handler (id) {
|
||||
return this[`__on_${id}`]?.bind?.(this)
|
||||
|| this.constructor[`__on_${id}`]?.bind?.(this.constructor)
|
||||
|| NOOP;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Service,
|
||||
};
|
Loading…
Reference in New Issue
Block a user