mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-06 03:42:56 +00:00
[ai] Forbid Q_OS_LINUX checks in the agent guidelines
This commit is contained in:
@@ -241,6 +241,29 @@ auto text = u"Settings"_q;
|
||||
auto text = QStringLiteral("Settings");
|
||||
```
|
||||
|
||||
**Never use `Q_OS_LINUX` for platform checks in new code:**
|
||||
|
||||
Telegram Desktop distinguishes at most three platforms: Windows / macOS / all-other. The "all-other" branch covers Linux, the BSD variants and more — and this is almost always the branch you want. `Q_OS_LINUX` narrows it to Linux alone, silently excluding the non-Linux Unix platforms, which is almost never intended. For the all-other branch use `!defined Q_OS_WIN && !defined Q_OS_MAC` at compile time, or its runtime equivalent `Platform::IsLinux()` — which, despite the name, means exactly `!defined Q_OS_WIN && !defined Q_OS_MAC` ("everything except Windows and macOS"), not Linux specifically:
|
||||
|
||||
```cpp
|
||||
// BAD - excludes FreeBSD and other non-Linux Unix:
|
||||
#ifdef Q_OS_LINUX
|
||||
UnixSpecificCode();
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
// GOOD - the all-other branch, compile time:
|
||||
#if !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||
UnixSpecificCode();
|
||||
#endif // !Q_OS_WIN && !Q_OS_MAC
|
||||
|
||||
// GOOD - the all-other branch, runtime (same meaning, NOT Linux-only):
|
||||
if (Platform::IsLinux()) {
|
||||
UnixSpecificCode();
|
||||
}
|
||||
```
|
||||
|
||||
`Q_OS_LINUX` is only for the rare case where you genuinely want exactly Linux and not the other Unix-like systems — usually you don't. The few existing uses (`Telegram/SourceFiles/core/sandbox.cpp`, `Telegram/SourceFiles/platform/linux/specific_linux.cpp`) are such genuinely Linux-only code paths and stay as-is.
|
||||
|
||||
## API Usage
|
||||
|
||||
### API Schema Files
|
||||
|
||||
@@ -553,3 +553,24 @@ Non-static member functions use camelCase (`startBatch`, `finalize`). Static mem
|
||||
// GOOD - PascalCase for static method:
|
||||
[[nodiscard]] static bool ShouldTrack(not_null<HistoryItem*> item);
|
||||
```
|
||||
|
||||
## No Q_OS_LINUX platform checks in new code
|
||||
|
||||
Telegram Desktop distinguishes at most three platforms: Windows / macOS / all-other, where "all-other" covers Linux, the BSD variants and more — and this is almost always the branch that is wanted. A `Q_OS_LINUX` check narrows it to Linux alone, silently excluding the non-Linux Unix platforms, which is almost never intended. For the all-other branch use `!defined Q_OS_WIN && !defined Q_OS_MAC` at compile time, or its runtime equivalent `Platform::IsLinux()` — which, despite the name, means exactly `!defined Q_OS_WIN && !defined Q_OS_MAC` ("everything except Windows and macOS"), not Linux specifically. `Q_OS_LINUX` is only for the rare case where exactly Linux is meant and not the other Unix-like systems — usually it is not. The few existing uses (`Telegram/SourceFiles/core/sandbox.cpp`, `Telegram/SourceFiles/platform/linux/specific_linux.cpp`) are such genuinely Linux-only code paths and stay as-is.
|
||||
|
||||
```cpp
|
||||
// BAD - excludes FreeBSD and other non-Linux Unix:
|
||||
#ifdef Q_OS_LINUX
|
||||
UnixSpecificCode();
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
// GOOD - the all-other branch, compile time:
|
||||
#if !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||
UnixSpecificCode();
|
||||
#endif // !Q_OS_WIN && !Q_OS_MAC
|
||||
|
||||
// GOOD - the all-other branch, runtime (same meaning, NOT Linux-only):
|
||||
if (Platform::IsLinux()) {
|
||||
UnixSpecificCode();
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user