Skip to content

Commit

Permalink
feat(core): adding system events to api
Browse files Browse the repository at this point in the history
You can now listen for events like lock-screen etc.
  • Loading branch information
markmcdowell committed Dec 15, 2020
1 parent 3b0555e commit 3548ec3
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 67 deletions.
56 changes: 50 additions & 6 deletions docs/sdk/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The underlying raw api object, this property is exposed but shouldn't be needed.

A property that returns true if the application is running in the desktop host.

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const hosted = desktop.isHostedInDesktop;
Expand All @@ -24,7 +24,7 @@ const hosted = desktop.isHostedInDesktop;

Gets the application name.

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const appName = await desktop.getAppName();
Expand All @@ -36,7 +36,7 @@ const appName = await desktop.getAppName();

Gets the application version.

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const appVersion = await desktop.getAppVersion();
Expand All @@ -48,19 +48,51 @@ const appVersion = await desktop.getAppVersion();

Versions of chrome, node, v8 etc...

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const versions = await desktop.getVersions();
```

## off <Badge text="M" type="warning" vertical="middle" />

### `off(event: SystemEvents, listener: () => void): void`

Removes a listener from [System Events](./#system-events).

```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const listener = () => {
// trigger an action
};

desktop.off("lock-screen", listener);
```

## on <Badge text="M" type="warning" vertical="middle" />

### `on(event: SystemEvents, listener: () => void): void`

Adds a listener to [System Events](./#system-events).

```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

const listener = () => {
// trigger an action
};

desktop.on("lock-screen", listener);
```

## quit <Badge text="M" type="warning" vertical="middle" />

### `quit(): Promise<void>`

Quits the application giving all applications time to close.

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

await desktop.quit();
Expand All @@ -72,8 +104,20 @@ await desktop.quit();

Shows the desktop about panel.

```js
```ts
import { desktop } from "@reactivemarkets/desktop-sdk";

await desktop.showAboutPanel();
```

## System Events

| Event | Description |
| ------------- | -------------------------------------------------------- |
| lock-screen | Emitted when the system is about to lock the screen. |
| on-ac | Emitted when the system changes to AC power. |
| on-battery | Emitted when system changes to battery power. |
| resume | Emitted when system is resuming. |
| shutdown | Emitted when the system is about to reboot or shut down. |
| suspend | Emitted when the system is suspending. |
| unlock-screen | Emitted as soon as the systems screen is unlocked. |
8 changes: 4 additions & 4 deletions docs/sdk/globalshortcut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Whether this application has registered the `accelerator`.

```js
```ts
import { globalShortcut } from "@reactivemarkets/desktop-sdk";

const isRegistered = await globalShortcut.isRegistered("CommandOrControl+X");
Expand All @@ -20,7 +20,7 @@ Registers a global shortcut of `accelerator`.

If the accelerator is already registered by another application outside of the desktop, the listener will sliently fail. This is the behavior of operating systems.

```js
```ts
import { globalShortcut } from "@reactivemarkets/desktop-sdk";

await globalShortcut.register("CommandOrControl+X", () => {
Expand All @@ -34,7 +34,7 @@ await globalShortcut.register("CommandOrControl+X", () => {

Unregisters the global shortcut of `accelerator`.

```js
```ts
import { globalShortcut } from "@reactivemarkets/desktop-sdk";

const listener = () => console.info("CommandOrControl+X invoked");
Expand All @@ -49,7 +49,7 @@ await globalShortcut.unregister("CommandOrControl+X", listener);

Unregisters all global shortcuts for this application.

```js
```ts
import { globalShortcut } from "@reactivemarkets/desktop-sdk";

await globalShortcut.unregisterAll();
Expand Down
2 changes: 1 addition & 1 deletion docs/sdk/launcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Launch the given `configuration`.

```js
```ts
import { launcher } from "@reactivemarkets/desktop-sdk";

const configuration = await launcher.launch({
Expand Down
10 changes: 5 additions & 5 deletions docs/sdk/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Log at debug level.

```js
```ts
import { logger } from "@reactivemarkets/desktop-sdk";

logger.debug("Logs to a structured logger", {
Expand All @@ -20,7 +20,7 @@ logger.debug("Logs to a structured logger", {

Log at error level.

```js
```ts
import { logger } from "@reactivemarkets/desktop-sdk";

logger.error("Logs to a structured logger", {
Expand All @@ -34,7 +34,7 @@ logger.error("Logs to a structured logger", {

Log at info level.

```js
```ts
import { logger } from "@reactivemarkets/desktop-sdk";

logger.info("Logs to a structured logger", {
Expand All @@ -48,7 +48,7 @@ logger.info("Logs to a structured logger", {

Log at verbose level.

```js
```ts
import { logger } from "@reactivemarkets/desktop-sdk";

logger.verbose("Logs to a structured logger", {
Expand All @@ -62,7 +62,7 @@ logger.verbose("Logs to a structured logger", {

Log at warn level.

```js
```ts
import { logger } from "@reactivemarkets/desktop-sdk";

logger.warn("Logs to a structured logger", {
Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

List all registered applications in the given namespace.

```js
```ts
import { registry } from "@reactivemarkets/desktop-sdk";

const applications = await registry.listApplications();
Expand All @@ -18,7 +18,7 @@ const applications = await registry.listApplications();

Register a new `configuration` object.

```js
```ts
import { registry } from "@reactivemarkets/desktop-sdk";

await registry.register({
Expand All @@ -39,7 +39,7 @@ await registry.register({

Unregister a previously registered configuation object. This will not stop anything currently running.

```js
```ts
import { registry } from "@reactivemarkets/desktop-sdk";

const applications = await registry.listApplications();
Expand Down
6 changes: 3 additions & 3 deletions docs/sdk/router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Publish a message on a channel.

```js
```ts
import { router } from "@reactivemarkets/desktop-sdk";

router.publish("my_channel", {
Expand All @@ -20,7 +20,7 @@ router.publish("my_channel", {

Subscribe to a channel.

```js
```ts
import { router } from "@reactivemarkets/desktop-sdk";

router.subscribe("my_channel", (payload) => {
Expand All @@ -34,7 +34,7 @@ router.subscribe("my_channel", (payload) => {

Unsubscribe from a channel.

```js
```ts
import { router } from "@reactivemarkets/desktop-sdk";

const listener = (data: string) => {
Expand Down
Loading

0 comments on commit 3548ec3

Please sign in to comment.