Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ futures-util = "0.3.31"
zip-extract = "0.2.2"
dirs = "6.0.0"
sysinfo = "0.34.2"
inotify = "0.11.0"
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 9
1 change: 0 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub const BUS_NAME: &str = "one.playtron.LocalPlugin";
pub const CLIENT_PATH: &str = "/one/playtron/LocalPlugin/PluginClient0";
pub const PLUGIN_ID: &str = "local";
pub const NAME: &str = "Local games";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const MINIMUM_API_VERSION: &str = "0.1.1";
Expand Down
14 changes: 12 additions & 2 deletions src/local/connector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::constants::LIBRARY_PROVIDER_ID;
/// This module is where you implement the functionality to interact with the store service
/// legendary / gog-warp / etc code should go here. The module can be renamed to represent your
/// connector more accurately eg `legendary.rs`
Expand All @@ -20,16 +21,25 @@ pub struct AccountInfo {
}

impl LocalConnector {
// pub fn get_config_path(&self) -> PathBuf {
// dirs::data_dir().unwrap().join(PathBuf::from(format!(
// "playtron/plugins/{}",
// LIBRARY_PROVIDER_ID
// )))
// }

pub fn get_library_paths(&self) -> Vec<PathBuf> {
let mut library_paths = Vec::new();
let home_library_path = dirs::data_dir().unwrap().join("playtron/apps/local");
let home_library_path = dirs::data_dir()
.unwrap()
.join(format!("playtron/apps/{}", LIBRARY_PROVIDER_ID));
if home_library_path.exists() {
library_paths.push(home_library_path);
}
for mount_point in get_mount_points() {
let library_path = PathBuf::from_str(&mount_point)
.unwrap()
.join("playtron/apps/local");
.join(format!("playtron/apps/{}", LIBRARY_PROVIDER_ID));
if library_path.exists() {
library_paths.push(library_path);
}
Expand Down
35 changes: 35 additions & 0 deletions src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use crate::types::app::{
use crate::types::cloud_sync::CloudPath;
use crate::types::results::ResultWithError;
use futures::future;
use inotify::{Inotify, WatchMask};
use rsa::pkcs1::EncodeRsaPublicKey;
use rsa::pkcs8::LineEnding;
use rsa::{RsaPrivateKey, RsaPublicKey};
use std::collections::BTreeMap;
use std::fs;
use std::vec;
use zbus::fdo;

Expand All @@ -29,6 +31,39 @@ impl LocalService {
Self { rsa, connector }
}

pub fn initialize(&self) {
let mut inotify = Inotify::init().expect("Failed to initialize inotify");

let library_paths = self.connector.get_library_paths();
library_paths.iter().for_each(|path| {
fs::read_dir(path).unwrap().for_each(|dir_result| {
let dir_entry = dir_result.unwrap();
let game_path = dir_entry.path();
let game_info = game_path.join("gameinfo.yaml");
inotify
.watches()
.add(
game_info,
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE,
)
.expect("Failed to add inotify watch");
});
});
let mut buffer = [0u8; 4096];
tokio::spawn(async move {
loop {
let events = inotify
.read_events_blocking(&mut buffer)
.expect("Failed to read inotify events");

for event in events {
// TODO emit signal to trigger update of app metadata
log::info!("gameinfo modified: {:?}", event);
}
}
});
}

pub fn get_public_key(&self) -> String {
let public_key = RsaPublicKey::from(&self.rsa);
public_key.to_pkcs1_pem(LineEnding::LF).unwrap()
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
log::info!("Starting Playtron Plugin version: {version} ");

let local_service = LocalService::new();
local_service.initialize();
build_connection(local_service).await?;
register_plugin().await;

Expand Down
4 changes: 2 additions & 2 deletions src/plugin/plugin_interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::constants::{MINIMUM_API_VERSION, NAME, PLUGIN_ID, VERSION};
use crate::constants::{LIBRARY_PROVIDER_ID, MINIMUM_API_VERSION, NAME, VERSION};
use zbus::fdo;
use zbus_macros::interface;

Expand All @@ -16,7 +16,7 @@ impl Plugin {
/// Id
#[zbus(property)]
async fn id(&self) -> fdo::Result<&str> {
Ok(PLUGIN_ID)
Ok(LIBRARY_PROVIDER_ID)
}

/// Human readable name of the plugin (e.g. “Steam”)
Expand Down