> For the complete documentation index, see [llms.txt](https://docs.sacruda.nl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sacruda.nl/developers/your-apps-code/basic-third-party-process.md).

# Basic third-party process

ThirdPartyProcess -> Process

So you want to create a basic third-party process, without creating a window? Great! We're building some stuff for that. It's still a little unrefined around the edges, but we're getting there, slowly but surely.

The class in question is `ThirdPartyProcess`: a third-party equivalent of Sacruda's internal `Process` base class. This class doesn't give you a window or anything; it's up to you to create your own content.

{% hint style="warning" icon="window" %}
Even if your application doesn't have a window, you're still required to fill out the window dimensions and configuration options in `_app.tpa` for Sacruda to see your application as valid.
{% endhint %}

### In-phase process methods

There are several built-in methods in the process class that are executed in different phases of your process. Here's an exhaustive list of them.

{% hint style="warning" %}
The in-phase methods are **all** asynchronous: The Sacruda process handler and app renderer awaits these, and expects them to be asynchronous.
{% endhint %}

* `async start`: this method is called when the process is spawned, before the `render` method. If this method returns `false`, Sacruda will stop the spawn.
* `async stop`: this method is called when the process is killed.

### Built-in process methods

These methods are available for you to call in your app process. They range from closing your app to handling multiple instances. Here they are:

```typescript
getSingleton(): ThirdPartyProcess[];
```

This function returns other instances of your app. This is useful if you want to interact with the methods of one of those other instances.

***

```typescript
closeIfSecondInstance(): Promise<AppProcess | undefined>;
```

{% hint style="info" %}
This method is asynchronous: it has to be awaited.
{% endhint %}

If you only want your process to only have one instance at a time, call this method conditionally at the very top of your `start` method, like so:

```javascript
async start() {
  if (await this.closeIfSecondInstance()) return false;
  // . . .
}
```

{% hint style="warning" icon="gears" %}
Be sure to only call `closeIfSecondInstance` at the beginning of the start method. Sacruda will terminate your application if this method is called anywhere else, because otherwise it runs the risk of hanging the process stack.
{% endhint %}

### Loading CSS files

Loading CSS content works a little differently in ThirdPartyProcesses; since there's no window to render, there's also no HTML content, and as such no handler for `<link>`. So instead, you have to call `IThirdPartyProcess.loadCSS`, passing in the relative Sacruda file path of the CSS file you want to load:

{% code lineNumbers="true" %}

```javascript
const cssFile = "./popup.css";
await this.loadCSS(cssFile);
```

{% endcode %}

{% hint style="danger" %}
**NOTE**: the loadCSS method **can throw an error** if the file can't be read. Be sure to employ proper [Error handling](https://docs.sacruda.nl/developers/your-apps-code/error-handling.md).
{% endhint %}

This method loads the CSS content and appends it to the `<head>` of Sacruda's webpage. It also makes sure that the CSS is unloaded properly when the main process is disposed.
