Skip to content

Commit

Permalink
Merge pull request #54 from Stremio/fix/flatpak-lockfile
Browse files Browse the repository at this point in the history
fix: lockfile not working with flatpak
  • Loading branch information
tymmesyde authored Oct 6, 2023
2 parents 407546f + 819df57 commit 3c2dfc2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
23 changes: 10 additions & 13 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use url::Url;

use crate::{
args::Args,
config::{DATA_DIR, STREMIO_URL, UPDATE_ENDPOINT},
constants::{STREMIO_URL, UPDATE_ENDPOINT},
server::Server,
updater::Updater,
util::load_icon,
Expand Down Expand Up @@ -52,9 +52,6 @@ pub struct Config {
#[cfg_attr(any(not(feature = "bundled"), target_os = "windows"), allow(dead_code))]
home_dir: PathBuf,

/// The data directory where the service will store data
data_dir: PathBuf,

/// The lockfile that guards against running multiple instances of the service.
lockfile: PathBuf,

Expand All @@ -72,12 +69,16 @@ impl Config {
///
/// If `self_update` is `true` and it is a supported platform for the updater (see [`IS_UPDATER_SUPPORTED`])
/// it will check for the existence of the `updater` binary at the given location.
pub fn new(args: Args, home_dir: PathBuf, service_bins_dir: PathBuf) -> Result<Self, Error> {
pub fn new(
args: Args,
home_dir: PathBuf,
cache_dir: PathBuf,
service_bins_dir: PathBuf,
) -> Result<Self, Error> {
let server =
server::Config::at_dir(service_bins_dir).context("Server.js configuration failed")?;

let data_dir = home_dir.join(DATA_DIR);
let lockfile = data_dir.join("lock");
let lockfile = cache_dir.join("lock");

let updater_endpoint = if let Some(endpoint) = args.updater_endpoint {
endpoint
Expand All @@ -92,7 +93,6 @@ impl Config {
Ok(Self {
updater_endpoint,
home_dir,
data_dir,
lockfile,
server,
skip_update: args.skip_updater,
Expand All @@ -115,9 +115,6 @@ impl Application {
}

pub async fn run(&self) -> Result<(), anyhow::Error> {
std::fs::create_dir_all(&self.config.data_dir)
.context("Failed to create the service data directory")?;

let mut lockfile = LockFile::open(&self.config.lockfile)?;

if !lockfile.try_lock()? {
Expand Down Expand Up @@ -229,7 +226,7 @@ fn make_it_autostart(home_dir: impl AsRef<Path>) {
#[cfg(target_os = "linux")]
{
use crate::{
config::{AUTOSTART_CONFIG_PATH, DESKTOP_FILE_NAME, DESKTOP_FILE_PATH},
constants::{AUTOSTART_CONFIG_PATH, DESKTOP_FILE_NAME, DESKTOP_FILE_PATH},
util::create_dir_if_does_not_exists,
};

Expand All @@ -251,7 +248,7 @@ fn make_it_autostart(home_dir: impl AsRef<Path>) {
#[cfg(target_os = "macos")]
{
use crate::{
config::{APP_IDENTIFIER, APP_NAME, LAUNCH_AGENTS_PATH},
constants::{APP_IDENTIFIER, APP_NAME, LAUNCH_AGENTS_PATH},
util::create_dir_if_does_not_exists,
};

Expand Down
1 change: 0 additions & 1 deletion src/config.rs → src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (C) 2017-2023 Smart code 203358507

pub const DATA_DIR: &str = ".stremio-service";
pub const STREMIO_URL: &str = "https://web.stremio.com";
pub const APP_IDENTIFIER: &str = "com.stremio.service";
pub const APP_NAME: &str = "StremioService";
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pub mod app;
pub mod args;
pub mod config;
pub mod constants;
pub mod server;
pub mod updater;
pub mod util;
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

let home_dir = dirs::home_dir().context("Failed to get home dir")?;
let cache_dir = dirs::cache_dir().context("Failed to get cache dir")?;

#[cfg(feature = "bundled")]
// use the installed dir if we've built the app with `bundled` feature.
Expand All @@ -37,7 +38,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.join("bin")
.join(std::env::consts::OS);

let config = Config::new(cli, home_dir, service_bins_dir)?;
let config = Config::new(cli, home_dir, cache_dir, service_bins_dir)?;
log::info!("Using service configuration: {:#?}", config);

let application = Application::new(config);
Expand Down

0 comments on commit 3c2dfc2

Please sign in to comment.