Solel//dev docs

Overview

, @solel-io/sdk, is what your app's front end uses to work inside . It connects to the desktop, says who's using the app and where it was opened, and lets the app set its window's title, send notifications and open links and other apps. It has no dependencies and works with any framework.

Adding it to your project

The SDK lives in packages/sdk in the repository, under the Apache License 2.0, so you can use it in an app under any licence. It isn't published to npm. Solel's own apps use it from source, by pointing @solel-io/sdk at it in vite.config.ts, as Contacts does:

const here = (path: string) => fileURLToPath(new URL(path, import.meta.url));

export default defineConfig({
  resolve: {
    alias: {
      '@solel-io/sdk': here('../../packages/sdk/src/index.ts'),
    },
  },
});

and in tsconfig.json, so TypeScript finds it:

"paths": { "@solel-io/sdk": ["../../packages/sdk/src/index.ts"] }

Your first app does the same from a project of your own.

Starting

Call ready() once when the app starts:

import { solel } from '@solel-io/sdk';

const app = await solel.ready();
console.log(`Hello, ${app.user.name}`);

It resolves with the app, the person using it, their theme and layout, the grants approved for this install, and the path the app was opened at. It also sets data-theme and color-scheme on <html> to match the person's theme, so Daybreak and the browser follow it.

Keeping up

solel.on('theme', (theme) => { /* light or dark */ });
solel.on('layout', (layout) => { /* desktop or phone */ });
solel.on('open', (path) => router.go(path));

open fires when someone opens one of the app's notifications, or another app opens it at a path, while it's already running.

Doing things

solel.setTitle('Shopping list');
await solel.notify({ title: 'Saved', body: 'Your note is safe.', link: '/notes/7' });
solel.openLink('https://example.com/help');
solel.openApp('io.solel.contacts', '/contact/c1');
solel.close();

notify needs the notify grant. Recording from the microphone needs microphone, and the calls about Sols need sols.manage. Everything else needs no grant. The Reference has every call.

Outside the desktop

ready() rejects with a SolelError when the page isn't inside , or the desktop doesn't answer in 5 seconds. Solel's own apps catch it and carry on without the desktop while they're being developed on their own, with no window title or notifications:

export async function connect(): Promise<AppContext | null> {
  try {
    return await solel.ready({ timeout: 4000 });
  } catch {
    return null;
  }
}