Skip to content

Commit

Permalink
Reformat and fix a few problems
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed Mar 30, 2024
1 parent c788a7b commit a123e6c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
9 changes: 5 additions & 4 deletions native/src/components/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ fn get_download_url() -> &'static str {
pub struct Runtime {
pub version: Option<String>,

directory: PathBuf,
executable: PathBuf,
config: PathBuf,
pub directory: PathBuf,
pub executable: PathBuf,
pub config: PathBuf,
}

impl Runtime {
Expand Down Expand Up @@ -291,10 +291,11 @@ impl Runtime {

#[cfg(feature = "linked-runtime")]
pub fn link(&self) -> Result<()> {
use crate::storage::Storage;
use std::fs::{copy, create_dir_all};
use std::os::unix::fs::symlink;

use crate::storage::Storage;

let dirs = ProjectDirs::new()?;
let mut storage = Storage::load(&dirs)?;

Expand Down
30 changes: 25 additions & 5 deletions native/src/connector/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,36 @@ use log::{info, warn};

use crate::components::runtime::Runtime;
use crate::connector::request::{
CreateProfile, GetConfig, GetProfileList, GetSiteList, GetSystemVersions, InstallRuntime,
InstallSite, LaunchSite, PatchAllProfiles, RegisterProtocolHandler, RemoveProfile, SetConfig,
UninstallRuntime, UninstallSite, UnregisterProtocolHandler, UpdateAllSites, UpdateProfile,
CreateProfile,
GetConfig,
GetProfileList,
GetSiteList,
GetSystemVersions,
InstallRuntime,
InstallSite,
LaunchSite,
PatchAllProfiles,
RegisterProtocolHandler,
RemoveProfile,
SetConfig,
UninstallRuntime,
UninstallSite,
UnregisterProtocolHandler,
UpdateAllSites,
UpdateProfile,
UpdateSite,
};
use crate::connector::response::ConnectorResponse;
use crate::connector::Connection;
use crate::console::app::{
ProfileCreateCommand, ProfileRemoveCommand, ProfileUpdateCommand, RuntimeInstallCommand,
RuntimeUninstallCommand, SiteInstallCommand, SiteLaunchCommand, SiteUninstallCommand,
ProfileCreateCommand,
ProfileRemoveCommand,
ProfileUpdateCommand,
RuntimeInstallCommand,
RuntimeUninstallCommand,
SiteInstallCommand,
SiteLaunchCommand,
SiteUninstallCommand,
SiteUpdateCommand,
};
use crate::console::Run;
Expand Down
2 changes: 1 addition & 1 deletion native/src/connector/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub struct SetConfig(pub Config);
#[cfg(feature = "linked-runtime")]
#[derive(Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct InstallRuntime {
/// Experimental: use a linked runtime instead of downloading from mozilla.
/// Experimental: Use a linked runtime instead of downloading from Mozilla.
pub link: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion native/src/console/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub enum RuntimeCommand {

#[derive(Parser, Debug, Eq, PartialEq, Clone)]
pub struct RuntimeInstallCommand {
/// Experimental: use a linked runtime instead of downloading from mozilla.
/// Experimental: Use a linked runtime instead of downloading from Mozilla
#[cfg(feature = "linked-runtime")]
#[clap(long)]
pub link: bool,
Expand Down
19 changes: 10 additions & 9 deletions native/src/console/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use url::Url;
use crate::components::runtime::Runtime;
use crate::components::site::{Site, SiteConfig};
use crate::console::app::{
SiteInstallCommand, SiteLaunchCommand, SiteUninstallCommand, SiteUpdateCommand,
SiteInstallCommand,
SiteLaunchCommand,
SiteUninstallCommand,
SiteUpdateCommand,
};
use crate::console::{store_value, store_value_vec, Run};
use crate::directories::ProjectDirs;
Expand All @@ -31,11 +34,9 @@ impl Run for SiteLaunchCommand {

#[cfg(platform_macos)]
{
use crate::integrations;

if !self.direct_launch {
integrations::launch(site, &self.url, args)?;
Ok(())
return Ok(());
}
}

Expand All @@ -48,22 +49,22 @@ impl Run for SiteLaunchCommand {

#[cfg(feature = "linked-runtime")]
{
use blake3::{hash, Hash};
use std::fs::File;
use std::io::Read;
use std::path::Path;

fn hasher(path: &str) -> Hash {
let mut file = File::open(Path::new(&path).join("firefox")).unwrap();
use blake3::{hash, Hash};

fn hasher<P: AsRef<Path>>(path: P) -> Hash {
let mut file = File::open(path.as_ref().join("firefox")).unwrap();
let mut buf = Vec::new();
let _ = file.read_to_end(&mut buf);

hash(&buf)
}

if storage.config.use_linked_runtime
&& hasher(crate::components::runtime::FFOX)
!= hasher("/home/daniele/.local/share/firefoxpwa/runtime/")
&& hasher(crate::components::runtime::FFOX) != hasher(&runtime.directory)
{
runtime.link()?;
}
Expand Down

0 comments on commit a123e6c

Please sign in to comment.