File: oslayer_controller.md

package info (click to toggle)
plover 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,356 kB
  • sloc: python: 21,589; sh: 682; ansic: 25; makefile: 11
file content (42 lines) | stat: -rw-r--r-- 1,299 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# `plover.oslayer.controller` -- Process management

This module provides a global process lock to ensure that there is only
one instance of Plover running, and forwards any commands received externally
(i.e. from sources other than Plover) to that existing instance.

```{py:module} plover.oslayer.controller
```

````{class} Controller
Creates a handle in the operating system that guarantees there is only one
Plover instance running. On Windows, this takes the form of a named pipe,
e.g. `\\.\pipe\plover`; on Unix platforms it is a Unix domain socket,
e.g. `/tmp/plover_socket`. This handle is destroyed when Plover exits.

If the handle already exists, this tries to send the `focus` command to
the existing instance to surface the main window.

An instance of this class can be used as a context manager:

```
with Controller() as ctrl:
  # Now this is the only Plover instance running
  pass
```

```{attribute} is_owner
:type: bool

`True` if the current process is the only one running.
```

```{method} force_cleanup()
Delete the handle, if possible. This should only be used if the
previous Plover instance did not exit cleanly and the handle still
exists on the system.
```

```{method} send_command(command: str)
Sends `command` to the running Plover instance to be executed.
```
````