desktop-lifecycle 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- desktop_lifecycle-0.1.0/CHANGELOG.md +35 -0
- desktop_lifecycle-0.1.0/CODE_OF_CONDUCT.md +134 -0
- desktop_lifecycle-0.1.0/CONTRIBUTING.md +67 -0
- desktop_lifecycle-0.1.0/LICENSE +21 -0
- desktop_lifecycle-0.1.0/MANIFEST.in +10 -0
- desktop_lifecycle-0.1.0/PKG-INFO +196 -0
- desktop_lifecycle-0.1.0/README.md +161 -0
- desktop_lifecycle-0.1.0/README.tr.md +160 -0
- desktop_lifecycle-0.1.0/SECURITY.md +52 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/__init__.py +56 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/__main__.py +80 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/_util.py +133 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/autostart.py +222 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/desktop_entry.py +132 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/lifecycle.py +150 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/logging_setup.py +61 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/paths.py +146 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/py.typed +0 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/session.py +59 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/single_instance.py +142 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle/tray.py +238 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/PKG-INFO +196 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/SOURCES.txt +37 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/dependency_links.txt +1 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/entry_points.txt +2 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/requires.txt +8 -0
- desktop_lifecycle-0.1.0/desktop_lifecycle.egg-info/top_level.txt +1 -0
- desktop_lifecycle-0.1.0/docs/tray-on-wayland.md +111 -0
- desktop_lifecycle-0.1.0/examples/tk_demo.py +82 -0
- desktop_lifecycle-0.1.0/pyproject.toml +63 -0
- desktop_lifecycle-0.1.0/setup.cfg +4 -0
- desktop_lifecycle-0.1.0/tests/test_autostart.py +129 -0
- desktop_lifecycle-0.1.0/tests/test_cli_and_logging.py +145 -0
- desktop_lifecycle-0.1.0/tests/test_desktop_entry.py +130 -0
- desktop_lifecycle-0.1.0/tests/test_lifecycle.py +105 -0
- desktop_lifecycle-0.1.0/tests/test_paths.py +120 -0
- desktop_lifecycle-0.1.0/tests/test_session.py +45 -0
- desktop_lifecycle-0.1.0/tests/test_single_instance.py +88 -0
- desktop_lifecycle-0.1.0/tests/test_tray.py +59 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-11
|
|
11
|
+
|
|
12
|
+
First release.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `App` — one object that resolves paths, detects the session and guards
|
|
17
|
+
against a second instance.
|
|
18
|
+
- `Paths` — XDG base directories on Linux/BSD, `APPDATA`/`LOCALAPPDATA` on
|
|
19
|
+
Windows, `Application Support`/`Caches` on macOS; created `0700`.
|
|
20
|
+
- `SingleInstance` — advisory `flock`/`msvcrt` lock with a `0600` lock file,
|
|
21
|
+
plus a signal file so a second launch can ask the running copy to show its
|
|
22
|
+
window.
|
|
23
|
+
- `Autostart` — XDG autostart entry, per-user Windows `Run` value, macOS
|
|
24
|
+
LaunchAgent; enable, disable, toggle and describe.
|
|
25
|
+
- `build_entry` / `install_menu_entry` / `install_icon` / `remove_menu_entry` —
|
|
26
|
+
`.desktop` files with spec-correct `Exec=` escaping and atomic writes.
|
|
27
|
+
- `session_type` — `x11`, `wayland`, `windows`, `macos` or `unknown`, based on
|
|
28
|
+
`XDG_SESSION_TYPE` rather than on `DISPLAY`.
|
|
29
|
+
- `tray.backend` — reports `ayatana`, `appindicator`, `pystray` or `none`, so an
|
|
30
|
+
application can decide whether a tray is possible at all.
|
|
31
|
+
- `setup_logging` — rotating log in the state directory.
|
|
32
|
+
- `python -m desktop_lifecycle` — read-only environment report for bug reports.
|
|
33
|
+
|
|
34
|
+
[Unreleased]: https://github.com/1emrecoskun/desktop-lifecycle/compare/v0.1.0...HEAD
|
|
35
|
+
[0.1.0]: https://github.com/1emrecoskun/desktop-lifecycle/releases/tag/v0.1.0
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement by opening a
|
|
63
|
+
private report through the repository's **Security → Report a vulnerability**
|
|
64
|
+
form, which is visible only to the maintainers.
|
|
65
|
+
|
|
66
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
67
|
+
|
|
68
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
69
|
+
reporter of any incident.
|
|
70
|
+
|
|
71
|
+
## Enforcement Guidelines
|
|
72
|
+
|
|
73
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
74
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
75
|
+
|
|
76
|
+
### 1. Correction
|
|
77
|
+
|
|
78
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
79
|
+
unprofessional or unwelcome in the community.
|
|
80
|
+
|
|
81
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
82
|
+
clarity around the nature of the violation and an explanation of why the
|
|
83
|
+
behavior was inappropriate. A public apology may be requested.
|
|
84
|
+
|
|
85
|
+
### 2. Warning
|
|
86
|
+
|
|
87
|
+
**Community Impact**: A violation through a single incident or series of
|
|
88
|
+
actions.
|
|
89
|
+
|
|
90
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
91
|
+
interaction with the people involved, including unsolicited interaction with
|
|
92
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
93
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
94
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
95
|
+
ban.
|
|
96
|
+
|
|
97
|
+
### 3. Temporary Ban
|
|
98
|
+
|
|
99
|
+
**Community Impact**: A serious violation of community standards, including
|
|
100
|
+
sustained inappropriate behavior.
|
|
101
|
+
|
|
102
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
103
|
+
communication with the community for a specified period of time. No public or
|
|
104
|
+
private interaction with the people involved, including unsolicited interaction
|
|
105
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
106
|
+
Violating these terms may lead to a permanent ban.
|
|
107
|
+
|
|
108
|
+
### 4. Permanent Ban
|
|
109
|
+
|
|
110
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
111
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
112
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
113
|
+
|
|
114
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
115
|
+
community.
|
|
116
|
+
|
|
117
|
+
## Attribution
|
|
118
|
+
|
|
119
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
120
|
+
version 2.1, available at
|
|
121
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
122
|
+
|
|
123
|
+
Community Impact Guidelines were inspired by
|
|
124
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
128
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
129
|
+
|
|
130
|
+
[homepage]: https://www.contributor-covenant.org
|
|
131
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
132
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
133
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
134
|
+
[translations]: https://www.contributor-covenant.org/translations
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for taking the time. This project is deliberately small; keeping it
|
|
4
|
+
small is part of the design.
|
|
5
|
+
|
|
6
|
+
## Before you start
|
|
7
|
+
|
|
8
|
+
Open an issue first for anything larger than a bug fix. The scope is "the
|
|
9
|
+
boring parts around a GUI application", not "a desktop framework".
|
|
10
|
+
|
|
11
|
+
## What fits
|
|
12
|
+
|
|
13
|
+
* fixing a platform-specific path, quoting or locking bug
|
|
14
|
+
* supporting a desktop environment or tray backend that genuinely misbehaves
|
|
15
|
+
* tests that reproduce a real bug report
|
|
16
|
+
* documentation fixes, especially for Wayland and Windows
|
|
17
|
+
|
|
18
|
+
## What does not fit
|
|
19
|
+
|
|
20
|
+
* drawing UI, a widget set, or a tray implementation of our own
|
|
21
|
+
* network features, telemetry, accounts
|
|
22
|
+
* anything that needs `sudo` or writes outside the user's home directory
|
|
23
|
+
* new runtime dependencies (the zero-dependency promise is the point)
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/1emrecoskun/desktop-lifecycle
|
|
29
|
+
cd desktop-lifecycle
|
|
30
|
+
python -m unittest discover -s tests -v
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
There is nothing to install: the package has no runtime dependencies, and the
|
|
34
|
+
tests need neither a display nor hardware.
|
|
35
|
+
|
|
36
|
+
A quick sanity check of the code itself:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python -m compileall -q desktop_lifecycle tests
|
|
40
|
+
python -m desktop_lifecycle
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Pull requests
|
|
44
|
+
|
|
45
|
+
* one topic per pull request
|
|
46
|
+
* a test for every behaviour change — tests that fail before your fix
|
|
47
|
+
* keep the public API additive where possible; this library is used by
|
|
48
|
+
applications that cannot be updated in lockstep
|
|
49
|
+
* do not add a `CHANGELOG` entry; the maintainer writes it at release time
|
|
50
|
+
|
|
51
|
+
## Commit messages
|
|
52
|
+
|
|
53
|
+
Short imperative subject, for example:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
Fix Exec quoting for paths containing a dollar sign
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Code style
|
|
60
|
+
|
|
61
|
+
Plain Python, no formatter required. Type hints where they help. Comments
|
|
62
|
+
should explain *why*, not restate the code. Keep functions small enough to
|
|
63
|
+
read on one screen.
|
|
64
|
+
|
|
65
|
+
## Conduct
|
|
66
|
+
|
|
67
|
+
By participating you agree to the [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 desktop-lifecycle contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: desktop-lifecycle
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The boring parts of a small Python desktop app: single-instance lock, XDG paths, autostart, menu entry, session and tray detection, rotating logs.
|
|
5
|
+
Author: desktop-lifecycle contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/1emrecoskun/desktop-lifecycle
|
|
8
|
+
Project-URL: Issues, https://github.com/1emrecoskun/desktop-lifecycle/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/1emrecoskun/desktop-lifecycle/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: desktop,linux,xdg,autostart,single-instance,system-tray,appindicator,wayland,pystray,desktop-entry
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: X11 Applications
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Desktop Environment
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: tray
|
|
29
|
+
Requires-Dist: pystray>=0.19; extra == "tray"
|
|
30
|
+
Requires-Dist: Pillow>=10; extra == "tray"
|
|
31
|
+
Provides-Extra: build
|
|
32
|
+
Requires-Dist: build>=1.0; extra == "build"
|
|
33
|
+
Requires-Dist: twine>=5; extra == "build"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# desktop-lifecycle
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+
|
|
40
|
+
**The boring parts of a small Python desktop app — before you write any UI.**
|
|
41
|
+
|
|
42
|
+
Single-instance lock, XDG directories, autostart, menu entry, session
|
|
43
|
+
detection, tray capability and rotating logs. No framework, no dependencies,
|
|
44
|
+
no root.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install git+https://github.com/1emrecoskun/desktop-lifecycle
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from desktop_lifecycle import App
|
|
52
|
+
|
|
53
|
+
app = App("my-tool").ensure_dirs()
|
|
54
|
+
app.setup_logging()
|
|
55
|
+
|
|
56
|
+
if not app.acquire(): # a second copy was launched
|
|
57
|
+
raise SystemExit(0) # it already asked the first one to show itself
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
That is the whole idea: the four things every small desktop app gets wrong,
|
|
61
|
+
in one small library you can read in ten minutes.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Why this exists
|
|
66
|
+
|
|
67
|
+
Every Python utility that lives in the tray ends up re-implementing the same
|
|
68
|
+
six things, usually differently and often incorrectly:
|
|
69
|
+
|
|
70
|
+
| What you need | What usually happens instead |
|
|
71
|
+
|---|---|
|
|
72
|
+
| One process per session | a PID file that lies after a crash, because PIDs are reused |
|
|
73
|
+
| Somewhere to write | settings in `~/.config`, logs in the checkout, a state file at `/.local/state` |
|
|
74
|
+
| Start at login | three platform-specific files written by hand |
|
|
75
|
+
| A menu entry | an unescaped `Exec=` line that silently refuses to launch |
|
|
76
|
+
| Know the session | `DISPLAY` is set, so it must be X11 — except under XWayland it is not |
|
|
77
|
+
| A tray icon | `pystray` works on X11, does not on Wayland, and needs PyGObject built |
|
|
78
|
+
|
|
79
|
+
These are not interesting problems, but each one produces a bug report that
|
|
80
|
+
takes an evening to understand. `desktop-lifecycle` is the version that was
|
|
81
|
+
already debugged.
|
|
82
|
+
|
|
83
|
+
## What you get
|
|
84
|
+
|
|
85
|
+
| Module | What it does |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `App` | ties everything below together in one object |
|
|
88
|
+
| `Paths` | `~/.config`, `~/.local/state`, `~/.local/share`, `~/.cache` (and the Windows/macOS equivalents), created with `0700` |
|
|
89
|
+
| `SingleInstance` | advisory `flock` / `msvcrt` lock, plus a signal file so a second launch can raise the existing window |
|
|
90
|
+
| `Autostart` | XDG autostart entry, per-user Windows `Run` key, macOS LaunchAgent — user-scoped, reversible |
|
|
91
|
+
| `install_menu_entry` | spec-correct `.desktop` file with properly escaped `Exec=` and atomic writes |
|
|
92
|
+
| `session_type` | `x11`, `wayland`, `windows`, `macos`, `unknown` — from `XDG_SESSION_TYPE`, not from `DISPLAY` |
|
|
93
|
+
| `tray.backend` | answers *which* tray backend will appear: `ayatana`, `appindicator`, `pystray` or `none` |
|
|
94
|
+
| `setup_logging` | rotating log in the state directory, so users can find it |
|
|
95
|
+
|
|
96
|
+
More detail, including package names per distribution:
|
|
97
|
+
[docs/tray-on-wayland.md](docs/tray-on-wayland.md).
|
|
98
|
+
|
|
99
|
+
## A complete tray application
|
|
100
|
+
|
|
101
|
+
See [`examples/tk_demo.py`](examples/tk_demo.py) — about sixty lines, and it
|
|
102
|
+
already handles the second launch, the tray, the hide-to-tray behaviour and
|
|
103
|
+
the log file. Run it twice to see the hand-over.
|
|
104
|
+
|
|
105
|
+
## What this is not
|
|
106
|
+
|
|
107
|
+
- **Not a GUI toolkit.** It does not draw anything. Tkinter, PyQt, GTK and
|
|
108
|
+
wxPython all work with it.
|
|
109
|
+
- **Not a tray replacement.** It detects the right backend and builds a small
|
|
110
|
+
menu, but it will not pretend a tray exists where the desktop has none.
|
|
111
|
+
- **Not a daemon framework.** It tells you where the lock and log live; how
|
|
112
|
+
your process loops is your business.
|
|
113
|
+
|
|
114
|
+
## Platform support
|
|
115
|
+
|
|
116
|
+
| | Linux X11 | Linux Wayland | Windows | macOS |
|
|
117
|
+
|---|---|---|---|---|
|
|
118
|
+
| Paths | ✅ | ✅ | ✅ | ✅ |
|
|
119
|
+
| Single instance | ✅ | ✅ | ✅ | ✅ |
|
|
120
|
+
| Autostart | ✅ XDG | ✅ XDG | ✅ `HKCU\...\Run` | ✅ LaunchAgent |
|
|
121
|
+
| Menu entry | ✅ | ✅ | — | — |
|
|
122
|
+
| Session detection | ✅ | ✅ | ✅ | ✅ |
|
|
123
|
+
| Tray | ✅ AppIndicator | ✅ AppIndicator | ✅ pystray | ✅ pystray |
|
|
124
|
+
|
|
125
|
+
Tray icons on Wayland only exist through the AppIndicator / StatusNotifierItem
|
|
126
|
+
protocol. If a desktop has neither, the answer is `none` and your app must
|
|
127
|
+
keep working with a visible window — that is exactly the case this library
|
|
128
|
+
forces you to handle.
|
|
129
|
+
|
|
130
|
+
## Security notes
|
|
131
|
+
|
|
132
|
+
- Everything is **user-scoped**. Nothing here asks for root, writes outside
|
|
133
|
+
your home directory, or edits system configuration.
|
|
134
|
+
- Lock files are created `0600`; configuration directories `0700`;
|
|
135
|
+
desktop entries `0644`.
|
|
136
|
+
- Every file is written **atomically** (temporary file + `rename`) so a
|
|
137
|
+
crash cannot leave half an autostart entry behind.
|
|
138
|
+
- `Exec=` values are escaped the way the specification requires — `"`, `` ` ``,
|
|
139
|
+
`$`, `\` and `%` cannot break out of the quoted argument or become a field
|
|
140
|
+
code.
|
|
141
|
+
- No `shell=True` anywhere, no `eval`, no dynamic imports from user input.
|
|
142
|
+
- Application names are validated, so a name cannot escape its own directory.
|
|
143
|
+
- No network access at runtime, no telemetry, no accounts.
|
|
144
|
+
|
|
145
|
+
Found a problem? See [SECURITY.md](SECURITY.md).
|
|
146
|
+
|
|
147
|
+
## Checking a machine
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python -m desktop_lifecycle # human-readable
|
|
151
|
+
python -m desktop_lifecycle --json # for bug reports
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
It prints the resolved directories, the session type and the tray backend
|
|
155
|
+
without writing anything. Users can paste that into an issue instead of
|
|
156
|
+
`ls -la ~`.
|
|
157
|
+
|
|
158
|
+
## Compared to the alternatives
|
|
159
|
+
|
|
160
|
+
| | desktop-lifecycle | pystray | manual code |
|
|
161
|
+
|---|---|---|---|
|
|
162
|
+
| XDG paths | ✅ | — | usually wrong |
|
|
163
|
+
| Single-instance lock | ✅ | — | PID file |
|
|
164
|
+
| Autostart | ✅ | — | per project |
|
|
165
|
+
| Menu entry | ✅ | — | per project |
|
|
166
|
+
| Wayland-aware tray detection | ✅ | partial | rare |
|
|
167
|
+
| GUI toolkit required | no | no | no |
|
|
168
|
+
| Dependencies | none | Pillow, PyGObject | — |
|
|
169
|
+
|
|
170
|
+
`pystray` is good at what it does; this library answers the questions around
|
|
171
|
+
it, including "should I even try".
|
|
172
|
+
|
|
173
|
+
## Requirements
|
|
174
|
+
|
|
175
|
+
Python 3.9+. No third-party packages.
|
|
176
|
+
|
|
177
|
+
Install from the repository until the PyPI release is published.
|
|
178
|
+
|
|
179
|
+
Optional tray fallback: `pip install desktop-lifecycle[tray]` (pystray + Pillow).
|
|
180
|
+
On Debian/Ubuntu/Mint the native way is `gir1.2-ayatanaappindicator3-0.1`.
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
git clone https://github.com/1emrecoskun/desktop-lifecycle
|
|
186
|
+
cd desktop-lifecycle
|
|
187
|
+
python -m unittest discover -s tests -v
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
79 tests, no hardware and no display required.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT — see [LICENSE](LICENSE).
|
|
195
|
+
|
|
196
|
+
Türkçe: [README.tr.md](README.tr.md)
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# desktop-lifecycle
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**The boring parts of a small Python desktop app — before you write any UI.**
|
|
6
|
+
|
|
7
|
+
Single-instance lock, XDG directories, autostart, menu entry, session
|
|
8
|
+
detection, tray capability and rotating logs. No framework, no dependencies,
|
|
9
|
+
no root.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install git+https://github.com/1emrecoskun/desktop-lifecycle
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from desktop_lifecycle import App
|
|
17
|
+
|
|
18
|
+
app = App("my-tool").ensure_dirs()
|
|
19
|
+
app.setup_logging()
|
|
20
|
+
|
|
21
|
+
if not app.acquire(): # a second copy was launched
|
|
22
|
+
raise SystemExit(0) # it already asked the first one to show itself
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That is the whole idea: the four things every small desktop app gets wrong,
|
|
26
|
+
in one small library you can read in ten minutes.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Why this exists
|
|
31
|
+
|
|
32
|
+
Every Python utility that lives in the tray ends up re-implementing the same
|
|
33
|
+
six things, usually differently and often incorrectly:
|
|
34
|
+
|
|
35
|
+
| What you need | What usually happens instead |
|
|
36
|
+
|---|---|
|
|
37
|
+
| One process per session | a PID file that lies after a crash, because PIDs are reused |
|
|
38
|
+
| Somewhere to write | settings in `~/.config`, logs in the checkout, a state file at `/.local/state` |
|
|
39
|
+
| Start at login | three platform-specific files written by hand |
|
|
40
|
+
| A menu entry | an unescaped `Exec=` line that silently refuses to launch |
|
|
41
|
+
| Know the session | `DISPLAY` is set, so it must be X11 — except under XWayland it is not |
|
|
42
|
+
| A tray icon | `pystray` works on X11, does not on Wayland, and needs PyGObject built |
|
|
43
|
+
|
|
44
|
+
These are not interesting problems, but each one produces a bug report that
|
|
45
|
+
takes an evening to understand. `desktop-lifecycle` is the version that was
|
|
46
|
+
already debugged.
|
|
47
|
+
|
|
48
|
+
## What you get
|
|
49
|
+
|
|
50
|
+
| Module | What it does |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `App` | ties everything below together in one object |
|
|
53
|
+
| `Paths` | `~/.config`, `~/.local/state`, `~/.local/share`, `~/.cache` (and the Windows/macOS equivalents), created with `0700` |
|
|
54
|
+
| `SingleInstance` | advisory `flock` / `msvcrt` lock, plus a signal file so a second launch can raise the existing window |
|
|
55
|
+
| `Autostart` | XDG autostart entry, per-user Windows `Run` key, macOS LaunchAgent — user-scoped, reversible |
|
|
56
|
+
| `install_menu_entry` | spec-correct `.desktop` file with properly escaped `Exec=` and atomic writes |
|
|
57
|
+
| `session_type` | `x11`, `wayland`, `windows`, `macos`, `unknown` — from `XDG_SESSION_TYPE`, not from `DISPLAY` |
|
|
58
|
+
| `tray.backend` | answers *which* tray backend will appear: `ayatana`, `appindicator`, `pystray` or `none` |
|
|
59
|
+
| `setup_logging` | rotating log in the state directory, so users can find it |
|
|
60
|
+
|
|
61
|
+
More detail, including package names per distribution:
|
|
62
|
+
[docs/tray-on-wayland.md](docs/tray-on-wayland.md).
|
|
63
|
+
|
|
64
|
+
## A complete tray application
|
|
65
|
+
|
|
66
|
+
See [`examples/tk_demo.py`](examples/tk_demo.py) — about sixty lines, and it
|
|
67
|
+
already handles the second launch, the tray, the hide-to-tray behaviour and
|
|
68
|
+
the log file. Run it twice to see the hand-over.
|
|
69
|
+
|
|
70
|
+
## What this is not
|
|
71
|
+
|
|
72
|
+
- **Not a GUI toolkit.** It does not draw anything. Tkinter, PyQt, GTK and
|
|
73
|
+
wxPython all work with it.
|
|
74
|
+
- **Not a tray replacement.** It detects the right backend and builds a small
|
|
75
|
+
menu, but it will not pretend a tray exists where the desktop has none.
|
|
76
|
+
- **Not a daemon framework.** It tells you where the lock and log live; how
|
|
77
|
+
your process loops is your business.
|
|
78
|
+
|
|
79
|
+
## Platform support
|
|
80
|
+
|
|
81
|
+
| | Linux X11 | Linux Wayland | Windows | macOS |
|
|
82
|
+
|---|---|---|---|---|
|
|
83
|
+
| Paths | ✅ | ✅ | ✅ | ✅ |
|
|
84
|
+
| Single instance | ✅ | ✅ | ✅ | ✅ |
|
|
85
|
+
| Autostart | ✅ XDG | ✅ XDG | ✅ `HKCU\...\Run` | ✅ LaunchAgent |
|
|
86
|
+
| Menu entry | ✅ | ✅ | — | — |
|
|
87
|
+
| Session detection | ✅ | ✅ | ✅ | ✅ |
|
|
88
|
+
| Tray | ✅ AppIndicator | ✅ AppIndicator | ✅ pystray | ✅ pystray |
|
|
89
|
+
|
|
90
|
+
Tray icons on Wayland only exist through the AppIndicator / StatusNotifierItem
|
|
91
|
+
protocol. If a desktop has neither, the answer is `none` and your app must
|
|
92
|
+
keep working with a visible window — that is exactly the case this library
|
|
93
|
+
forces you to handle.
|
|
94
|
+
|
|
95
|
+
## Security notes
|
|
96
|
+
|
|
97
|
+
- Everything is **user-scoped**. Nothing here asks for root, writes outside
|
|
98
|
+
your home directory, or edits system configuration.
|
|
99
|
+
- Lock files are created `0600`; configuration directories `0700`;
|
|
100
|
+
desktop entries `0644`.
|
|
101
|
+
- Every file is written **atomically** (temporary file + `rename`) so a
|
|
102
|
+
crash cannot leave half an autostart entry behind.
|
|
103
|
+
- `Exec=` values are escaped the way the specification requires — `"`, `` ` ``,
|
|
104
|
+
`$`, `\` and `%` cannot break out of the quoted argument or become a field
|
|
105
|
+
code.
|
|
106
|
+
- No `shell=True` anywhere, no `eval`, no dynamic imports from user input.
|
|
107
|
+
- Application names are validated, so a name cannot escape its own directory.
|
|
108
|
+
- No network access at runtime, no telemetry, no accounts.
|
|
109
|
+
|
|
110
|
+
Found a problem? See [SECURITY.md](SECURITY.md).
|
|
111
|
+
|
|
112
|
+
## Checking a machine
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python -m desktop_lifecycle # human-readable
|
|
116
|
+
python -m desktop_lifecycle --json # for bug reports
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
It prints the resolved directories, the session type and the tray backend
|
|
120
|
+
without writing anything. Users can paste that into an issue instead of
|
|
121
|
+
`ls -la ~`.
|
|
122
|
+
|
|
123
|
+
## Compared to the alternatives
|
|
124
|
+
|
|
125
|
+
| | desktop-lifecycle | pystray | manual code |
|
|
126
|
+
|---|---|---|---|
|
|
127
|
+
| XDG paths | ✅ | — | usually wrong |
|
|
128
|
+
| Single-instance lock | ✅ | — | PID file |
|
|
129
|
+
| Autostart | ✅ | — | per project |
|
|
130
|
+
| Menu entry | ✅ | — | per project |
|
|
131
|
+
| Wayland-aware tray detection | ✅ | partial | rare |
|
|
132
|
+
| GUI toolkit required | no | no | no |
|
|
133
|
+
| Dependencies | none | Pillow, PyGObject | — |
|
|
134
|
+
|
|
135
|
+
`pystray` is good at what it does; this library answers the questions around
|
|
136
|
+
it, including "should I even try".
|
|
137
|
+
|
|
138
|
+
## Requirements
|
|
139
|
+
|
|
140
|
+
Python 3.9+. No third-party packages.
|
|
141
|
+
|
|
142
|
+
Install from the repository until the PyPI release is published.
|
|
143
|
+
|
|
144
|
+
Optional tray fallback: `pip install desktop-lifecycle[tray]` (pystray + Pillow).
|
|
145
|
+
On Debian/Ubuntu/Mint the native way is `gir1.2-ayatanaappindicator3-0.1`.
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
git clone https://github.com/1emrecoskun/desktop-lifecycle
|
|
151
|
+
cd desktop-lifecycle
|
|
152
|
+
python -m unittest discover -s tests -v
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
79 tests, no hardware and no display required.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT — see [LICENSE](LICENSE).
|
|
160
|
+
|
|
161
|
+
Türkçe: [README.tr.md](README.tr.md)
|