ashpd 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -0
- data/Cargo.lock +1 -0
- data/ext/ashpd/Cargo.toml +9 -2
- data/ext/ashpd/src/devices.rs +152 -0
- data/ext/ashpd/src/files.rs +211 -0
- data/ext/ashpd/src/lib.rs +124 -6
- data/ext/ashpd/src/screencast.rs +387 -0
- data/ext/ashpd/src/sessions.rs +545 -0
- data/ext/ashpd/src/shell.rs +278 -0
- data/ext/ashpd/src/system.rs +220 -0
- data/lib/ashpd/version.rb +1 -1
- metadata +8 -1
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
//! The portals that ask the user for something, or tell the shell something.
|
|
2
|
+
//!
|
|
3
|
+
//! Every call here may put a dialog in front of the user and does not return
|
|
4
|
+
//! until it is answered, so none of them belongs on a main loop - put them on
|
|
5
|
+
//! a Ruby thread. The exception is {Background.set_status}, which only updates
|
|
6
|
+
//! what the shell says about this application.
|
|
7
|
+
//!
|
|
8
|
+
//! - org.freedesktop.portal.Email
|
|
9
|
+
//! - org.freedesktop.portal.Background
|
|
10
|
+
//! - org.freedesktop.portal.Notification
|
|
11
|
+
//! - org.freedesktop.portal.Wallpaper
|
|
12
|
+
//! - org.freedesktop.portal.Inhibit
|
|
13
|
+
//! - org.freedesktop.portal.Secret
|
|
14
|
+
|
|
15
|
+
use magnus::{function, prelude::*, Error, RArray, RHash, RModule, Ruby, TryConvert};
|
|
16
|
+
|
|
17
|
+
use ashpd_core::desktop::background::{Background, BackgroundProxy, SetStatusOptions};
|
|
18
|
+
use ashpd_core::desktop::email::EmailRequest;
|
|
19
|
+
use ashpd_core::desktop::inhibit::{InhibitFlags, InhibitOptions, InhibitProxy};
|
|
20
|
+
use ashpd_core::desktop::notification::{Notification, NotificationProxy, Priority};
|
|
21
|
+
use ashpd_core::desktop::wallpaper::{SetOn, WallpaperRequest};
|
|
22
|
+
use ashpd_core::enumflags2::BitFlags;
|
|
23
|
+
use ashpd_core::Uri;
|
|
24
|
+
|
|
25
|
+
use crate::{block, option_bool, option_name, option_strings, rt_err};
|
|
26
|
+
|
|
27
|
+
// --- org.freedesktop.portal.Email ------------------------------------------
|
|
28
|
+
|
|
29
|
+
/// Open the user's mail program on a new message.
|
|
30
|
+
///
|
|
31
|
+
/// Nothing is sent: the portal hands the draft to whatever composes mail here
|
|
32
|
+
/// and the user decides. So the addresses are a suggestion, not an action, and
|
|
33
|
+
/// this is the honest way for an application to offer "email us".
|
|
34
|
+
fn email_compose(ruby: &Ruby, options: RHash) -> Result<(), Error> {
|
|
35
|
+
let addresses = option_strings(ruby, options, "addresses")?;
|
|
36
|
+
let cc = option_strings(ruby, options, "cc")?;
|
|
37
|
+
let bcc = option_strings(ruby, options, "bcc")?;
|
|
38
|
+
let subject = option_name(ruby, options, "subject")?;
|
|
39
|
+
let body = option_name(ruby, options, "body")?;
|
|
40
|
+
|
|
41
|
+
block(async {
|
|
42
|
+
let mut request = EmailRequest::default();
|
|
43
|
+
|
|
44
|
+
if !addresses.is_empty() {
|
|
45
|
+
request = request.addresses(&addresses);
|
|
46
|
+
}
|
|
47
|
+
if !cc.is_empty() {
|
|
48
|
+
request = request.cc(&cc);
|
|
49
|
+
}
|
|
50
|
+
if !bcc.is_empty() {
|
|
51
|
+
request = request.bcc(&bcc);
|
|
52
|
+
}
|
|
53
|
+
request = request.subject(subject.as_deref()).body(body.as_deref());
|
|
54
|
+
|
|
55
|
+
request.send().await?.response()
|
|
56
|
+
})?
|
|
57
|
+
.map_err(rt_err)?;
|
|
58
|
+
|
|
59
|
+
Ok(())
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// --- org.freedesktop.portal.Background -------------------------------------
|
|
63
|
+
|
|
64
|
+
/// Ask to keep running once the window is gone, and optionally to be started
|
|
65
|
+
/// at login.
|
|
66
|
+
///
|
|
67
|
+
/// Returns `{"run_in_background" =>, "auto_start" =>}` - what the user
|
|
68
|
+
/// granted, which is not necessarily what was asked for.
|
|
69
|
+
fn background_request(ruby: &Ruby, options: RHash) -> Result<RHash, Error> {
|
|
70
|
+
let reason = option_name(ruby, options, "reason")?;
|
|
71
|
+
let auto_start = option_bool(ruby, options, "auto_start");
|
|
72
|
+
let dbus_activatable = option_bool(ruby, options, "dbus_activatable");
|
|
73
|
+
|
|
74
|
+
let granted: Background = block(async {
|
|
75
|
+
let mut request = ashpd_core::desktop::background::Background::request();
|
|
76
|
+
|
|
77
|
+
if let Some(reason) = reason.as_deref() {
|
|
78
|
+
request = request.reason(reason);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
request
|
|
82
|
+
.auto_start(auto_start)
|
|
83
|
+
.dbus_activatable(dbus_activatable)
|
|
84
|
+
.send()
|
|
85
|
+
.await?
|
|
86
|
+
.response()
|
|
87
|
+
})?
|
|
88
|
+
.map_err(rt_err)?;
|
|
89
|
+
|
|
90
|
+
let hash = ruby.hash_new();
|
|
91
|
+
hash.aset("run_in_background", granted.run_in_background())?;
|
|
92
|
+
hash.aset("auto_start", granted.auto_start())?;
|
|
93
|
+
|
|
94
|
+
Ok(hash)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Tell the shell what this application is doing while it runs in the
|
|
98
|
+
/// background, which is what the user sees when they ask what is still
|
|
99
|
+
/// running. This shows no dialog.
|
|
100
|
+
fn background_set_status(message: String) -> Result<(), Error> {
|
|
101
|
+
block(async {
|
|
102
|
+
BackgroundProxy::new()
|
|
103
|
+
.await?
|
|
104
|
+
.set_status(SetStatusOptions::default().set_message(&message))
|
|
105
|
+
.await
|
|
106
|
+
})?
|
|
107
|
+
.map_err(rt_err)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// --- org.freedesktop.portal.Notification -----------------------------------
|
|
111
|
+
|
|
112
|
+
fn priority_from(name: &str) -> Result<Priority, Error> {
|
|
113
|
+
match name {
|
|
114
|
+
"low" => Ok(Priority::Low),
|
|
115
|
+
"normal" => Ok(Priority::Normal),
|
|
116
|
+
"high" => Ok(Priority::High),
|
|
117
|
+
"urgent" => Ok(Priority::Urgent),
|
|
118
|
+
other => Err(rt_err(format!(
|
|
119
|
+
"unknown priority {other:?}, wanted :low, :normal, :high or :urgent"
|
|
120
|
+
))),
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// Post a notification under an id of this application's choosing.
|
|
125
|
+
///
|
|
126
|
+
/// The id is how it is replaced or withdrawn later: posting the same id again
|
|
127
|
+
/// replaces what is on screen rather than stacking another one up.
|
|
128
|
+
fn notification_add(ruby: &Ruby, id: String, title: String, options: RHash) -> Result<(), Error> {
|
|
129
|
+
let body = option_name(ruby, options, "body")?;
|
|
130
|
+
let priority = option_name(ruby, options, "priority")?;
|
|
131
|
+
|
|
132
|
+
block(async {
|
|
133
|
+
let mut notification = Notification::new(&title).body(body.as_deref());
|
|
134
|
+
|
|
135
|
+
if let Some(name) = priority.as_deref() {
|
|
136
|
+
notification = notification.priority(priority_from(name).ok());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
NotificationProxy::new()
|
|
140
|
+
.await?
|
|
141
|
+
.add_notification(&id, notification)
|
|
142
|
+
.await
|
|
143
|
+
})?
|
|
144
|
+
.map_err(rt_err)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// Withdraw a notification posted earlier. Unknown ids are not an error: the
|
|
148
|
+
/// state asked for - not on screen - is the state that results.
|
|
149
|
+
fn notification_remove(id: String) -> Result<(), Error> {
|
|
150
|
+
block(async {
|
|
151
|
+
NotificationProxy::new()
|
|
152
|
+
.await?
|
|
153
|
+
.remove_notification(&id)
|
|
154
|
+
.await
|
|
155
|
+
})?
|
|
156
|
+
.map_err(rt_err)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// --- org.freedesktop.portal.Wallpaper --------------------------------------
|
|
160
|
+
|
|
161
|
+
fn set_on_from(name: &str) -> Result<SetOn, Error> {
|
|
162
|
+
match name {
|
|
163
|
+
"lockscreen" => Ok(SetOn::Lockscreen),
|
|
164
|
+
"background" => Ok(SetOn::Background),
|
|
165
|
+
"both" => Ok(SetOn::Both),
|
|
166
|
+
other => Err(rt_err(format!(
|
|
167
|
+
"unknown wallpaper target {other:?}, wanted :lockscreen, :background or :both"
|
|
168
|
+
))),
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/// Set the desktop wallpaper from a URI.
|
|
173
|
+
///
|
|
174
|
+
/// `show_preview` asks the portal to show the user what it will look like
|
|
175
|
+
/// before doing it, which is the difference between offering and imposing.
|
|
176
|
+
fn wallpaper_set(ruby: &Ruby, uri: String, options: RHash) -> Result<(), Error> {
|
|
177
|
+
let parsed = Uri::parse(&uri).map_err(rt_err)?;
|
|
178
|
+
let set_on = option_name(ruby, options, "set_on")?;
|
|
179
|
+
let show_preview = option_bool(ruby, options, "show_preview");
|
|
180
|
+
|
|
181
|
+
block(async {
|
|
182
|
+
let mut request = WallpaperRequest::default().show_preview(show_preview);
|
|
183
|
+
|
|
184
|
+
if let Some(name) = set_on.as_deref() {
|
|
185
|
+
request = request.set_on(set_on_from(name).ok());
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
request.build_uri(&parsed).await?.response()
|
|
189
|
+
})?
|
|
190
|
+
.map_err(rt_err)?;
|
|
191
|
+
|
|
192
|
+
Ok(())
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// --- org.freedesktop.portal.Inhibit ----------------------------------------
|
|
196
|
+
|
|
197
|
+
fn inhibit_flag_from(name: &str) -> Result<InhibitFlags, Error> {
|
|
198
|
+
match name {
|
|
199
|
+
"logout" => Ok(InhibitFlags::Logout),
|
|
200
|
+
"user_switch" => Ok(InhibitFlags::UserSwitch),
|
|
201
|
+
"suspend" => Ok(InhibitFlags::Suspend),
|
|
202
|
+
"idle" => Ok(InhibitFlags::Idle),
|
|
203
|
+
other => Err(rt_err(format!(
|
|
204
|
+
"unknown inhibit flag {other:?}, wanted :logout, :user_switch, :suspend or :idle"
|
|
205
|
+
))),
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// Ask the host not to do something while this application is busy: suspend,
|
|
210
|
+
/// idle, log out, switch user.
|
|
211
|
+
///
|
|
212
|
+
/// The inhibition lasts until the portal request is closed, which happens when
|
|
213
|
+
/// this process exits. There is deliberately no way to lift it earlier here;
|
|
214
|
+
/// that wants the request object, which the next version can carry.
|
|
215
|
+
fn inhibit(ruby: &Ruby, what: RArray, reason: String) -> Result<(), Error> {
|
|
216
|
+
let mut flags = BitFlags::<InhibitFlags>::empty();
|
|
217
|
+
|
|
218
|
+
for flag in what.into_iter() {
|
|
219
|
+
flags |= inhibit_flag_from(&flag.to_r_string()?.to_string()?)?;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let _ = ruby;
|
|
223
|
+
|
|
224
|
+
block(async {
|
|
225
|
+
InhibitProxy::new()
|
|
226
|
+
.await?
|
|
227
|
+
.inhibit(
|
|
228
|
+
None,
|
|
229
|
+
flags,
|
|
230
|
+
InhibitOptions::default().set_reason(reason.as_str()),
|
|
231
|
+
)
|
|
232
|
+
.await?
|
|
233
|
+
.response()
|
|
234
|
+
})?
|
|
235
|
+
.map_err(rt_err)?;
|
|
236
|
+
|
|
237
|
+
Ok(())
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// --- org.freedesktop.portal.Secret -----------------------------------------
|
|
241
|
+
|
|
242
|
+
/// The master secret for this application, as a String of bytes.
|
|
243
|
+
///
|
|
244
|
+
/// This is not a keyring: it is one secret the host keeps for this application
|
|
245
|
+
/// alone, meant to be used as the key with which it encrypts its own storage.
|
|
246
|
+
/// A sandboxed application gets one it cannot read for any other, which is the
|
|
247
|
+
/// point.
|
|
248
|
+
fn secret_retrieve(ruby: &Ruby) -> Result<magnus::RString, Error> {
|
|
249
|
+
let bytes = block(ashpd_core::desktop::secret::retrieve())?.map_err(rt_err)?;
|
|
250
|
+
|
|
251
|
+
Ok(ruby.str_from_slice(&bytes))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
pub fn init(namespace: RModule) -> Result<(), Error> {
|
|
255
|
+
let email = namespace.define_module("Email")?;
|
|
256
|
+
email.define_singleton_method("compose", function!(email_compose, 1))?;
|
|
257
|
+
|
|
258
|
+
let background = namespace.define_module("Background")?;
|
|
259
|
+
background.define_singleton_method("request", function!(background_request, 1))?;
|
|
260
|
+
background.define_singleton_method("set_status", function!(background_set_status, 1))?;
|
|
261
|
+
|
|
262
|
+
let notification = namespace.define_module("Notification")?;
|
|
263
|
+
notification.define_singleton_method("add", function!(notification_add, 3))?;
|
|
264
|
+
notification.define_singleton_method("remove", function!(notification_remove, 1))?;
|
|
265
|
+
|
|
266
|
+
let wallpaper = namespace.define_module("Wallpaper")?;
|
|
267
|
+
wallpaper.define_singleton_method("set", function!(wallpaper_set, 2))?;
|
|
268
|
+
|
|
269
|
+
let inhibit_module = namespace.define_module("Inhibit")?;
|
|
270
|
+
inhibit_module.define_singleton_method("inhibit", function!(inhibit, 2))?;
|
|
271
|
+
|
|
272
|
+
let secret = namespace.define_module("Secret")?;
|
|
273
|
+
secret.define_singleton_method("retrieve", function!(secret_retrieve, 0))?;
|
|
274
|
+
|
|
275
|
+
let _ = RArray::try_convert;
|
|
276
|
+
|
|
277
|
+
Ok(())
|
|
278
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
//! The portals that answer questions about the machine, rather than asking the
|
|
2
|
+
//! user for something.
|
|
3
|
+
//!
|
|
4
|
+
//! None of these shows a dialog, so unlike the rest of this binding they are
|
|
5
|
+
//! safe to call from a main loop: they are property reads and plain method
|
|
6
|
+
//! calls. That makes them the right things to branch a user interface on -
|
|
7
|
+
//! whether there is a network, whether the machine is on battery - before
|
|
8
|
+
//! asking for anything that interrupts.
|
|
9
|
+
//!
|
|
10
|
+
//! - org.freedesktop.portal.NetworkMonitor
|
|
11
|
+
//! - org.freedesktop.portal.PowerProfileMonitor
|
|
12
|
+
//! - org.freedesktop.portal.ProxyResolver
|
|
13
|
+
//! - org.freedesktop.portal.Realtime
|
|
14
|
+
//! - org.freedesktop.portal.GameMode
|
|
15
|
+
|
|
16
|
+
use magnus::{function, prelude::*, Error, RArray, RHash, RModule, Ruby};
|
|
17
|
+
|
|
18
|
+
use ashpd_core::desktop::game_mode::{GameMode, Status};
|
|
19
|
+
use ashpd_core::desktop::network_monitor::{Connectivity, NetworkMonitor};
|
|
20
|
+
use ashpd_core::desktop::power_profile_monitor::PowerProfileMonitor;
|
|
21
|
+
use ashpd_core::desktop::proxy_resolver::ProxyResolver;
|
|
22
|
+
use ashpd_core::desktop::realtime::Realtime;
|
|
23
|
+
use ashpd_core::Uri;
|
|
24
|
+
|
|
25
|
+
use crate::{block, rt_err};
|
|
26
|
+
|
|
27
|
+
// --- org.freedesktop.portal.NetworkMonitor ---------------------------------
|
|
28
|
+
|
|
29
|
+
/// How much of a network there is, as the interface's own four states rather
|
|
30
|
+
/// than a boolean: a captive portal is connected and useless, which is a
|
|
31
|
+
/// distinction an application wants to draw.
|
|
32
|
+
fn connectivity_name(connectivity: Connectivity) -> &'static str {
|
|
33
|
+
match connectivity {
|
|
34
|
+
Connectivity::Local => "local",
|
|
35
|
+
Connectivity::Limited => "limited",
|
|
36
|
+
Connectivity::CaptivePortal => "captive_portal",
|
|
37
|
+
Connectivity::FullNetwork => "full_network",
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Whether there is any network at all.
|
|
42
|
+
fn network_available() -> Result<bool, Error> {
|
|
43
|
+
block(async { NetworkMonitor::new().await?.is_available().await })?.map_err(rt_err)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Whether the network bills by the byte, which is what to check before
|
|
47
|
+
/// downloading something large on someone else's behalf.
|
|
48
|
+
fn network_metered() -> Result<bool, Error> {
|
|
49
|
+
block(async { NetworkMonitor::new().await?.is_metered().await })?.map_err(rt_err)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn network_connectivity(ruby: &Ruby) -> Result<magnus::Symbol, Error> {
|
|
53
|
+
let connectivity =
|
|
54
|
+
block(async { NetworkMonitor::new().await?.connectivity().await })?.map_err(rt_err)?;
|
|
55
|
+
|
|
56
|
+
Ok(ruby.to_symbol(connectivity_name(connectivity)))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// The three answers at once, in one round trip rather than three.
|
|
60
|
+
fn network_status(ruby: &Ruby) -> Result<RHash, Error> {
|
|
61
|
+
let status = block(async { NetworkMonitor::new().await?.status().await })?.map_err(rt_err)?;
|
|
62
|
+
|
|
63
|
+
let hash = ruby.hash_new();
|
|
64
|
+
hash.aset("available", status.is_available())?;
|
|
65
|
+
hash.aset("metered", status.is_metered())?;
|
|
66
|
+
hash.aset(
|
|
67
|
+
"connectivity",
|
|
68
|
+
ruby.to_symbol(connectivity_name(status.connectivity())),
|
|
69
|
+
)?;
|
|
70
|
+
|
|
71
|
+
Ok(hash)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Whether a host and port could be reached.
|
|
75
|
+
///
|
|
76
|
+
/// This asks the portal, not the network: it answers from what the host
|
|
77
|
+
/// already knows about routing, and opens no connection of its own.
|
|
78
|
+
fn network_can_reach(hostname: String, port: u32) -> Result<bool, Error> {
|
|
79
|
+
block(async {
|
|
80
|
+
NetworkMonitor::new()
|
|
81
|
+
.await?
|
|
82
|
+
.can_reach(&hostname, port)
|
|
83
|
+
.await
|
|
84
|
+
})?
|
|
85
|
+
.map_err(rt_err)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- org.freedesktop.portal.PowerProfileMonitor ----------------------------
|
|
89
|
+
|
|
90
|
+
/// Whether power saving is on, which is the host asking applications to do
|
|
91
|
+
/// less: fewer animations, less background work.
|
|
92
|
+
fn power_saver_enabled() -> Result<bool, Error> {
|
|
93
|
+
block(async { PowerProfileMonitor::new().await?.is_enabled().await })?.map_err(rt_err)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// --- org.freedesktop.portal.ProxyResolver ----------------------------------
|
|
97
|
+
|
|
98
|
+
/// The proxies to use for a URI, in the order to try them.
|
|
99
|
+
///
|
|
100
|
+
/// "direct://" means no proxy, and is what comes back when none is configured
|
|
101
|
+
/// - so the list is never empty and the first entry is the one to use.
|
|
102
|
+
fn proxy_lookup(ruby: &Ruby, uri: String) -> Result<RArray, Error> {
|
|
103
|
+
let parsed = Uri::parse(&uri).map_err(rt_err)?;
|
|
104
|
+
let proxies = block(async { ProxyResolver::new().await?.lookup(&parsed).await })?
|
|
105
|
+
.map_err(rt_err)?;
|
|
106
|
+
|
|
107
|
+
let array = ruby.ary_new_capa(proxies.len());
|
|
108
|
+
for proxy in proxies {
|
|
109
|
+
let _ = array.push(proxy.as_str());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Ok(array)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// --- org.freedesktop.portal.Realtime ---------------------------------------
|
|
116
|
+
|
|
117
|
+
/// What the host will allow a thread to ask for, as
|
|
118
|
+
/// `{"max_realtime_priority" =>, "min_nice_level" =>, "rt_time_usec_max" =>}`.
|
|
119
|
+
///
|
|
120
|
+
/// Only the limits are read here. Making a thread realtime is deliberately not
|
|
121
|
+
/// bound: it takes a thread id, and a Ruby thread is not the kernel thread it
|
|
122
|
+
/// runs on for long enough to make that meaningful.
|
|
123
|
+
fn realtime_limits(ruby: &Ruby) -> Result<RHash, Error> {
|
|
124
|
+
let hash = ruby.hash_new();
|
|
125
|
+
|
|
126
|
+
// Each property is read on its own and a failure leaves nil behind, rather
|
|
127
|
+
// than one unimplemented property taking the other two with it. A portal
|
|
128
|
+
// is free to carry some of an interface and not the rest.
|
|
129
|
+
let max_priority = block(async { Realtime::new().await?.max_realtime_priority().await })?;
|
|
130
|
+
let min_nice = block(async { Realtime::new().await?.min_nice_level().await })?;
|
|
131
|
+
let rt_time = block(async { Realtime::new().await?.rt_time_usec_max().await })?;
|
|
132
|
+
|
|
133
|
+
hash.aset("max_realtime_priority", max_priority.ok())?;
|
|
134
|
+
hash.aset("min_nice_level", min_nice.ok())?;
|
|
135
|
+
hash.aset("rt_time_usec_max", rt_time.ok())?;
|
|
136
|
+
|
|
137
|
+
Ok(hash)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- org.freedesktop.portal.GameMode ---------------------------------------
|
|
141
|
+
|
|
142
|
+
/// Whether game mode is on for the host as a whole.
|
|
143
|
+
fn game_mode_active() -> Result<bool, Error> {
|
|
144
|
+
block(async { GameMode::new().await?.is_active().await })?.map_err(rt_err)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// Whether one process is registered with game mode, as `:inactive`,
|
|
148
|
+
/// `:active` or `:registered`.
|
|
149
|
+
fn game_mode_status(ruby: &Ruby, pid: u32) -> Result<magnus::Symbol, Error> {
|
|
150
|
+
// The by-pid form, which names the asking process as well as the asked
|
|
151
|
+
// about one. The single-argument QueryStatus wants to work out the caller's
|
|
152
|
+
// pid namespace for itself and fails outside a sandbox with "Could not get
|
|
153
|
+
// pidns".
|
|
154
|
+
let status = block(async {
|
|
155
|
+
GameMode::new()
|
|
156
|
+
.await?
|
|
157
|
+
.query_status_by_pid(pid, std::process::id())
|
|
158
|
+
.await
|
|
159
|
+
})?
|
|
160
|
+
.map_err(rt_err)?;
|
|
161
|
+
|
|
162
|
+
Ok(ruby.to_symbol(match status {
|
|
163
|
+
Status::Inactive => "inactive",
|
|
164
|
+
Status::Active => "active",
|
|
165
|
+
Status::Registered => "registered",
|
|
166
|
+
// The host refused: game mode exists but will not have this process.
|
|
167
|
+
Status::Rejected => "rejected",
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Ask the host to treat a process as a game: it may raise its priority and
|
|
172
|
+
/// stop power saving from throttling it.
|
|
173
|
+
///
|
|
174
|
+
/// The requester is this process, which is what the portal wants in order to
|
|
175
|
+
/// unregister on our behalf if we go away.
|
|
176
|
+
fn game_mode_register(pid: u32) -> Result<(), Error> {
|
|
177
|
+
block(async {
|
|
178
|
+
GameMode::new()
|
|
179
|
+
.await?
|
|
180
|
+
.register_by_pid(pid, std::process::id())
|
|
181
|
+
.await
|
|
182
|
+
})?
|
|
183
|
+
.map_err(rt_err)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fn game_mode_unregister(pid: u32) -> Result<(), Error> {
|
|
187
|
+
block(async {
|
|
188
|
+
GameMode::new()
|
|
189
|
+
.await?
|
|
190
|
+
.unregister_by_pid(pid, std::process::id())
|
|
191
|
+
.await
|
|
192
|
+
})?
|
|
193
|
+
.map_err(rt_err)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pub fn init(namespace: RModule) -> Result<(), Error> {
|
|
197
|
+
let network = namespace.define_module("NetworkMonitor")?;
|
|
198
|
+
network.define_singleton_method("available?", function!(network_available, 0))?;
|
|
199
|
+
network.define_singleton_method("metered?", function!(network_metered, 0))?;
|
|
200
|
+
network.define_singleton_method("connectivity", function!(network_connectivity, 0))?;
|
|
201
|
+
network.define_singleton_method("status", function!(network_status, 0))?;
|
|
202
|
+
network.define_singleton_method("can_reach?", function!(network_can_reach, 2))?;
|
|
203
|
+
|
|
204
|
+
let power = namespace.define_module("PowerProfileMonitor")?;
|
|
205
|
+
power.define_singleton_method("power_saver_enabled?", function!(power_saver_enabled, 0))?;
|
|
206
|
+
|
|
207
|
+
let proxy = namespace.define_module("ProxyResolver")?;
|
|
208
|
+
proxy.define_singleton_method("lookup", function!(proxy_lookup, 1))?;
|
|
209
|
+
|
|
210
|
+
let realtime = namespace.define_module("Realtime")?;
|
|
211
|
+
realtime.define_singleton_method("limits", function!(realtime_limits, 0))?;
|
|
212
|
+
|
|
213
|
+
let game_mode = namespace.define_module("GameMode")?;
|
|
214
|
+
game_mode.define_singleton_method("active?", function!(game_mode_active, 0))?;
|
|
215
|
+
game_mode.define_singleton_method("status", function!(game_mode_status, 1))?;
|
|
216
|
+
game_mode.define_singleton_method("register", function!(game_mode_register, 1))?;
|
|
217
|
+
game_mode.define_singleton_method("unregister", function!(game_mode_unregister, 1))?;
|
|
218
|
+
|
|
219
|
+
Ok(())
|
|
220
|
+
}
|
data/lib/ashpd/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ashpd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nathan Kidd
|
|
@@ -75,13 +75,20 @@ extensions:
|
|
|
75
75
|
- ext/ashpd/extconf.rb
|
|
76
76
|
extra_rdoc_files: []
|
|
77
77
|
files:
|
|
78
|
+
- CHANGELOG.md
|
|
78
79
|
- Cargo.lock
|
|
79
80
|
- Cargo.toml
|
|
80
81
|
- LICENSE
|
|
81
82
|
- NOTICE
|
|
82
83
|
- ext/ashpd/Cargo.toml
|
|
83
84
|
- ext/ashpd/extconf.rb
|
|
85
|
+
- ext/ashpd/src/devices.rs
|
|
86
|
+
- ext/ashpd/src/files.rs
|
|
84
87
|
- ext/ashpd/src/lib.rs
|
|
88
|
+
- ext/ashpd/src/screencast.rs
|
|
89
|
+
- ext/ashpd/src/sessions.rs
|
|
90
|
+
- ext/ashpd/src/shell.rs
|
|
91
|
+
- ext/ashpd/src/system.rs
|
|
85
92
|
- lib/ashpd.rb
|
|
86
93
|
- lib/ashpd/version.rb
|
|
87
94
|
- lib/ashpd/version.rb.erb
|