Skip to content

Commit

Permalink
Only patch runtime and profile when they need update (closes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed Dec 26, 2021
1 parent 6383466 commit 156b6b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
30 changes: 28 additions & 2 deletions native/src/console/site.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs::metadata;
use std::io;
use std::io::Write;

Expand Down Expand Up @@ -44,8 +45,33 @@ impl Run for SiteLaunchCommand {
bail!("Runtime not installed");
}

runtime.patch(&dirs, site)?;
profile.patch(&dirs)?;
let should_patch = if storage.config.always_patch {
// Force patching if this is enabled
true
} else {
// Uses "chrome.jsm" file because it contains version info
let source = dirs.sysdata.join("userchrome/profile/chrome/pwa/chrome.jsm");
let target = dirs.userdata.join("profiles").join(profile.ulid.to_string()).join("chrome/pwa/chrome.jsm");

// Only patch if modification dates of source and target are different
// In case any error happens, just force patching
if let (Ok(source_metadata), Ok(target_metadata)) = (metadata(source), metadata(target)) {
if let (Ok(source_modified), Ok(target_modified)) = (source_metadata.modified(), target_metadata.modified()) {
source_modified > target_modified
} else {
true
}
} else {
true
}
};

// Patching on macOS is always needed to correctly show PWA name
// Otherwise, patch runtime and profile only if needed
if cfg!(target_os = "macos") || should_patch {
runtime.patch(&dirs, site)?;
profile.patch(&dirs)?;
}

info!("Launching the site");
cfg_if! {
Expand Down
8 changes: 8 additions & 0 deletions native/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ use crate::components::profile::Profile;
use crate::components::site::Site;
use crate::directories::ProjectDirs;

#[non_exhaustive]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, SmartDefault)]
#[serde(default)]
pub struct Config {
pub always_patch: bool,
}

#[non_exhaustive]
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, SmartDefault)]
#[serde(default)]
Expand All @@ -19,6 +26,7 @@ pub struct Storage {
pub sites: BTreeMap<Ulid, Site>,
pub arguments: Vec<String>,
pub variables: BTreeMap<String, String>,
pub config: Config,
}

impl Storage {
Expand Down

0 comments on commit 156b6b5

Please sign in to comment.