Core Tutorial
This tutorial shows you how to interact with the core.
Usage
The core variable injected into API signatures contains a reference to the Core instance.
It is used to interact with service providers, read configuration(s) and other core functionality.
Common
These methods are shared between the server and client:
// Gets a configuration value
const value = core.config("resolve.by.key", "optional default value");
// Retrieves an instance of a service
const service = core.make("namespace/service");
// Registers a new ServiceProvicer class
core.register(SomeServiceProvider, {/* registration options */});
// Registers a new singleton factory for service
core.singleton("namespace/service", () => new SomeService());
// Registers a new instance factory for service
core.instance("namespace/service", () => new SomeService());
// Checks if given service exists
const exists = core.has("namespace/service");
// Subscribe to an event
core.on("event-name", () => {});
Client
The client has some extra methods for dealing with user data, requests, resources and applications:
// Creates a URL based on the public path
const url = core.url("/foo/bar");
// Creates a new fetch() request
const promise = core.request("http://url", {/* options */}, "type");
// Launches an application
core.run("Preview", { file: { path: "home://image.png" } });
// Launches a new application based on a file
core.open({ path: "home://image.png", mime: "image/png" });
// Gets user data
const user = core.getUser();
// Send an event to the server
core.send("event-name", 1, 2, 3);
Global "meeseOS" namespace
The window global meeseOS also lets you reach some of the core functionality.
// Same as above (but some services are restricted)
meeseOS.make();
// These are the same as above
meeseOS.open();
meeseOS.request();
meeseOS.run();
meeseOS.url();
Client Events
init => ()- Main initmeeseOS/core:boot => ()- Core boot (before providers have initialized)meeseOS/core:booted => ()- Core booted (after providers have initialized)meeseOS/core:start => ()- Core start (before providers have started)meeseOS/core:started => ()- Core started (after providers have started)meeseOS/core:logged-in => ()- User successfully logged inmeeseOS/core:connect => ()- Connection establishedmeeseOS/core:disconnect => ()- Connection lostmeeseOS/core:destroy => ()- Core destroymeeseOS/application:launch => (name, args, options)- Application pre-launchmeeseOS/application:launched => (name, app)- Application launchedmeeseOS/application:*:launched => (app)- Application launched (*is metadata name)meeseOS/application:create => (app)- Application createmeeseOS/application:destroy => (app)- Application destroymeeseOS/window:create => (win)- Window createmeeseOS/window:render => (win)- Window rendermeeseOS/window:change => (win, key, value)- Window changedmeeseOS/window:transitionend => (ev, win)- Window transition endedmeeseOS/desktop:transform => (rect)- Desktop transformedmeeseOS/fs:mount => ()- Filesystem mountedmeeseOS/fs:unmount => ()- Filesystem unmountedmeeseOS/settings:save => ()- Settings savedmeeseOS/settings:load => ()- Settings loadedmeeseOS/vfs:* => (...args)- VFS Method call started (*is method name)meeseOS/vfs:*:done => (...args)- VFS Method call finished (*is method name)meeseOS/tray:create => (entry)- Tray entry createdmeeseOS/tray:remove => (entry)- Tray entry removedmeeseOS/tray:update => (entries)- Tray entry updatedmeeseOS/notification:create => (notif)- Notification createdmeeseOS/notification:destroy => (notif)- Notification destroyed
Client Services
These are the default provided services and their signatures:
meeseOS/application => (data)- Creates a new Application instancemeeseOS/window => (options)- Creates a new Window instancemeeseOS/event-handler => (name)- Creates a new EventEmitter instancemeeseOS/websocket => (...args)- Creates a new WebSocket instancemeeseOS/notification => (options?)- Creates a new Notification entrymeeseOS/tray => (options?)- Creates a new Tray entrymeeseOS/clipboard => ()- APIs for performing ClipboardmeeseOS/settings => ()- APIs for SettingsmeeseOS/vfs => ()- APIs for VFSmeeseOS/auth => ()- APIs for AuthenticationmeeseOS/contextmenu => (options?)- APIs for Context MenusmeeseOS/dialog => (name, ...args)- APIs for DialogsmeeseOS/dialogs => ()- APIs for Custom DialogsmeeseOS/dnd => ()- APIs for performing Drag-and-Drop operationsmeeseOS/theme => ()- APIs for ThemesmeeseOS/packages => ()- APIs for Package ManagementmeeseOS/session => ()- APIs for SessionmeeseOS/desktop => ()- APIs for desktopmeeseOS/panels => ()- APIs for panels
Example:
core.make("meeseOS/settings").save();
Server
The server also has some extra methods:
// Broadcast an event to all connected users (WebSocket)
core.broadcast("event-name", [1, 2, 3])
// Broadcast an event to a set of users
core.broadcast("event-name", [1, 2, 3], ws => {
//The original "req" containing session etc
//ws.upgradeReq
//The original session data
//ws._meeseOS_client
return true;
});
// Broadcast to all alias but with expanded arguments:
core.broadcastAll("event-name", 1, 2 , 3);
// Broadcast to a specific user, with expanded arguments:
core.broadcastUser("username", "event-name", 1, 2 , 3);
// Express server
const app = core.app;
// WebSocket server
const ws = core.ws;
// Session server
const session = core.session;
[info] You can listen for broadcast events in the client with
// Client-side example:
core.on("event-name", (a, b, c) => console.log(a, b, c)) // => 1 2 3
Server Services
These are the default provided services and their signatures:
meeseOS/express => ()- APIs for ExpressmeeseOS/packages => ()- APIs for PackagesmeeseOS/vfs => ()- APIs for VFSmeeseOS/fs => ()- APIs for Filesystem interaction
Events
init => ()- Main initmeeseOS/core:start => ()- Core startmeeseOS/core:started => ()- Core startedmeeseOS/core:ping => (req)- User pinged the servermeeseOS/core:vfs:watch:change => ({ mountpoint, target, type })- VFS watch triggermeeseOS/core:logged-in => (session)- User logged inmeeseOS/core:logging-out => (session)- User is logging out
MeeseOS Web Desktop - © Aaron Meese <[email protected]>