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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use flatpak::prelude::*;
use flatpak::Installation;
use gtk::prelude::*;
use gtk::{gio, glib};
use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;
#[derive(Deserialize, Serialize, Type, Eq, PartialEq, Default, Debug, Clone, Hash, glib::Boxed)]
#[boxed_type(name = "InstallationInfo", nullable)]
pub struct InstallationInfo {
pub name: String,
pub is_user: bool,
pub path: String,
}
impl From<&Installation> for InstallationInfo {
fn from(installation: &Installation) -> Self {
let name = installation.id().unwrap().to_string();
let is_user = installation.is_user();
let path = installation
.path()
.unwrap()
.path()
.unwrap()
.to_str()
.unwrap()
.to_string();
Self {
name,
is_user,
path,
}
}
}
impl From<&InstallationInfo> for Installation {
fn from(info: &InstallationInfo) -> Self {
if info.name == "user" && info.is_user {
let mut user_path = glib::home_dir();
user_path.push(".local");
user_path.push("share");
user_path.push("flatpak");
let file = gio::File::for_path(user_path);
Installation::for_path(&file, true, gio::Cancellable::NONE)
.expect("Unable to create Flatpak system installation for path")
} else if info.name == "default" && !info.is_user {
Installation::new_system(gio::Cancellable::NONE)
.expect("Unable to create Flatpak system installation")
} else if !info.is_user {
Installation::new_system_with_id(Some(&info.name), gio::Cancellable::NONE)
.expect("Unable to create Flatpak system installation with id")
} else {
let path = gio::File::for_parse_name(&info.path);
Installation::for_path(&path, info.is_user, gio::Cancellable::NONE)
.expect("Unable to create Flatpak user installation for path")
}
}
}