Skip to content
Closed
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
5 changes: 5 additions & 0 deletions crates/app/src/engine/pc_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub struct PortFiltersPatch {
pub guided: Option<bool>,
pub verified: Option<bool>,
pub installed: Option<bool>,
pub platform: Option<gamenode_core::ports::store::PortPlatformFilter>,
}

/// Reads `null` as `Some(None)` and a value as `Some(Some(value))`; a missing field stays `None`.
Expand Down Expand Up @@ -1237,6 +1238,7 @@ impl PortsService {
preferences: &preferences,
facts: &facts,
active_jobs: &active,
installs_supported: self.config.platform.supports_installs(),
}))
}

Expand Down Expand Up @@ -1424,6 +1426,9 @@ fn apply_preferences(preferences: &mut PortPreferences, patch: &PortPreferencesP
if let Some(installed) = filters.installed {
preferences.installed = installed;
}
if let Some(platform) = filters.platform {
preferences.platform_filter = platform;
}
}
if let Some(last_parent) = &patch.last_parent_folder {
preferences.last_parent = last_parent.clone();
Expand Down
34 changes: 29 additions & 5 deletions crates/app/src/engine/pc_ports/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct ViewInput<'a> {
pub facts: &'a HashMap<String, EntryFacts>,
/// Job ids the install runner currently owns.
pub active_jobs: &'a HashSet<String>,
/// False on a platform that serves the catalog without an install runner.
pub installs_supported: bool,
}

/// Builds the complete PC ports projection.
Expand All @@ -77,6 +79,7 @@ pub fn build(input: ViewInput<'_>) -> PortsView {
entry,
installed_keys.get(&entry.catalog_id).cloned(),
&facts,
input.installs_supported,
)
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -134,6 +137,7 @@ pub fn entry_view(
entry: &CatalogEntry,
installed_registration_key: Option<String>,
facts: &EntryFacts,
installs_supported: bool,
) -> PortEntryView {
let pinned = entry
.pinned_release
Expand All @@ -149,11 +153,14 @@ pub fn entry_view(
});
let withdrawn = !entry.withdrawn.is_empty() || facts.withdrawn;
let no_asset_reason = facts.no_asset_reason;
let installable = entry.supports_windows()
let installable = installs_supported
&& entry.supports_windows()
&& !withdrawn
&& (verified || pinned.is_some())
&& no_asset_reason.is_none();
let install_block_reason = if withdrawn {
let install_block_reason = if !installs_supported {
Some(PortInstallBlockReason::ComingSoon)
} else if withdrawn {
Some(PortInstallBlockReason::Withdrawn)
} else if !verified && pinned.is_none() {
Some(PortInstallBlockReason::NoVerifiedRelease)
Expand Down Expand Up @@ -541,6 +548,7 @@ fn preferences_view(preferences: &PortPreferences) -> PortPreferencesView {
guided: preferences.guided,
verified: preferences.verified,
installed: preferences.installed,
platform: preferences.platform_filter,
},
last_parent_folder: preferences.last_parent.clone(),
}
Expand Down Expand Up @@ -886,6 +894,7 @@ mod tests {
preferences,
facts,
active_jobs: active,
installs_supported: true,
}
}

Expand Down Expand Up @@ -937,13 +946,13 @@ mod tests {
no_asset_reason: Some(PortNoAssetReason::InstallerOnly),
withdrawn: false,
};
let view = entry_view(&withdrawn, None, &EntryFacts::default());
let view = entry_view(&withdrawn, None, &EntryFacts::default(), true);
assert_eq!(
view.install_block_reason,
Some(PortInstallBlockReason::Withdrawn)
);
assert!(!view.installable);
let view = entry_view(&entry(), None, &facts);
let view = entry_view(&entry(), None, &facts, true);
assert_eq!(
view.install_block_reason,
Some(PortInstallBlockReason::InstallerOnly)
Expand Down Expand Up @@ -1160,14 +1169,29 @@ mod tests {
.map(|release| (release.version.as_str(), release.withdrawn)),
Some(("v0.9.38", true))
);
let view = entry_view(&entry, None, &facts);
let view = entry_view(&entry, None, &facts, true);
assert!(!view.installable);
assert_eq!(
view.install_block_reason,
Some(PortInstallBlockReason::Withdrawn)
);
}

#[test]
fn a_catalog_only_platform_blocks_every_install_with_coming_soon() {
// A Windows-capable, verified entry is still blocked where the install runner is absent.
let view = entry_view(&entry(), None, &EntryFacts::default(), false);
assert!(!view.installable);
assert_eq!(
view.install_block_reason,
Some(PortInstallBlockReason::ComingSoon)
);
// The same entry is installable on a platform with an install runner.
let view = entry_view(&entry(), None, &EntryFacts::default(), true);
assert!(view.installable);
assert_eq!(view.install_block_reason, None);
}

#[test]
fn iso_dates_follow_the_gregorian_calendar() {
assert_eq!(iso_date(0), None);
Expand Down
45 changes: 45 additions & 0 deletions crates/app/src/engine/tests/pc_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,46 @@ async fn the_catalog_status_carries_seconds_and_the_entries_are_merged() {
service.shutdown();
}

#[tokio::test]
async fn linux_serves_the_catalog_read_only_and_refuses_installs() {
let _serial = serial().lock().await;
let db = database();
let store: Arc<dyn PortStore> = Arc::new(db.ports_store());
let local: Arc<dyn LocalGameStore> = Arc::new(db.local_game_store());
let catalog = Arc::new(FakeCatalog::new(
vec![entry()],
Some(entry()),
vec![release(Some(format!("sha256:{}", "a".repeat(64))), None)],
));
let mut config = service_config(store, local, catalog);
config.platform = gamenode_core::ports::PortPlatform::Linux;
assert!(
config.install.is_none(),
"a Linux build has no install dependencies"
);
let (service, rx) = start(config);
assert!(!service.is_supported());
service.open();
let view = wait_for_view(&rx, |view| view.catalog.state == PortCatalogState::Ready);
assert_eq!(view.catalog.entry_count, 1);
assert_eq!(view.entries.len(), 1);
assert!(view.jobs.is_empty(), "a read-only build queues no jobs");

let error = service
.install(&PortInstallRequest {
plugin_request_id: None,
catalog_id: "qcat_lantern".into(),
parent_folder: std::env::temp_dir().to_string_lossy().into_owned(),
supplied: Vec::new(),
accept_unverified_checksum: false,
accept_malware_flag: false,
retry_job_id: None,
})
.expect_err("a Linux build cannot install");
assert_eq!(error, PortsError::Unsupported);
service.shutdown();
}

#[tokio::test]
async fn preferences_round_trip_and_reach_the_view() {
let _serial = serial().lock().await;
Expand All @@ -541,13 +581,18 @@ async fn preferences_round_trip_and_reach_the_view() {
guided: Some(true),
verified: Some(false),
installed: Some(false),
platform: Some(gamenode_core::ports::PortPlatformFilter::NativeLinux),
}),
last_parent_folder: Some(Some(r"D:\Ports".into())),
})
.expect("saved");
let stored = store.preferences().unwrap();
assert_eq!(stored.view, PortViewMode::List);
assert_eq!(stored.consoles, ["PlayStation 4"]);
assert_eq!(
stored.platform_filter,
gamenode_core::ports::PortPlatformFilter::NativeLinux
);
assert!(stored.guided);
assert_eq!(stored.last_parent.as_deref(), Some(r"D:\Ports"));
let view = wait_for_view(&rx, |view| {
Expand Down
47 changes: 26 additions & 21 deletions crates/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,30 +414,35 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
));

// The service loads the overlay, recovers interrupted installs and starts its workers on a
// dedicated thread; construction returns immediately.
let pc_ports = if gamenode_core::ports::PortPlatform::current().supports_installs() {
let data_dir = paths.data_dir().to_owned();
Some(PortsService::start(PortsServiceConfig {
store: Arc::clone(&port_store),
local_games: local_game_store.clone(),
catalog: Arc::new(gamenode_platform::ports::QuiverClient::new()?),
overlay_fetcher: Arc::new(
gamenode_platform::ports::overlay_source::HttpOverlayFetcher::new(),
),
clock: Arc::new(gamenode_platform::ports::SystemClock),
data_dir: data_dir.clone(),
platform: gamenode_core::ports::PortPlatform::current(),
install: Some(InstallDeps {
fetcher: Arc::new(gamenode_platform::download::HttpDownloadFetcher::new()?),
url_policy: Arc::new(gamenode_platform::download::HttpsDownloadPolicy),
user_roots: gamenode_platform::ports::UserDataRoots::host()?,
identity: Arc::new(gamenode_platform::ports::SystemExecutableIdentity),
packages: Arc::new(gamenode_platform::ports::PinnedExtractor::new(data_dir)?),
}),
}))
// dedicated thread; construction returns immediately. The catalog also runs where installs are
// unsupported: the service is read-only there and the install runner stays absent.
let port_platform = gamenode_core::ports::PortPlatform::current();
let data_dir = paths.data_dir().to_owned();
let install = if port_platform.supports_installs() {
Some(InstallDeps {
fetcher: Arc::new(gamenode_platform::download::HttpDownloadFetcher::new()?),
url_policy: Arc::new(gamenode_platform::download::HttpsDownloadPolicy),
user_roots: gamenode_platform::ports::UserDataRoots::host()?,
identity: Arc::new(gamenode_platform::ports::SystemExecutableIdentity),
packages: Arc::new(gamenode_platform::ports::PinnedExtractor::new(
data_dir.clone(),
)?),
})
} else {
None
};
let pc_ports = Some(PortsService::start(PortsServiceConfig {
store: Arc::clone(&port_store),
local_games: local_game_store.clone(),
catalog: Arc::new(gamenode_platform::ports::QuiverClient::new()?),
overlay_fetcher: Arc::new(
gamenode_platform::ports::overlay_source::HttpOverlayFetcher::new(),
),
clock: Arc::new(gamenode_platform::ports::SystemClock),
data_dir,
platform: port_platform,
install,
}));

let pub_clone = publisher.clone();
let achievement_store = store.achievement_store();
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/ports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub use plan::{
sanitize_folder_name, select_asset, select_release, space_estimate,
};
pub use store::{
PortInstallation, PortJobResume, PortJobRow, PortOverlayRow, PortPreferences, PortStore,
PortViewMode,
PortInstallation, PortJobResume, PortJobRow, PortOverlayRow, PortPlatformFilter,
PortPreferences, PortStore, PortViewMode,
};
pub use view::{
PortArgumentKind, PortArgumentSpec, PortArtKind, PortArtView, PortCatalogError,
Expand Down
21 changes: 20 additions & 1 deletion crates/core/src/ports/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ pub enum PortViewMode {
List,
}

/// Which platform slice of the catalog the remembered filter shows.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PortPlatformFilter {
/// Every entry, including Windows-only ports.
#[default]
All,
/// Entries whose declared platforms include Linux.
NativeLinux,
/// Entries that declare Windows and do not declare Linux.
WindowsOnly,
}

/// Remembered catalog view, filters and last install parent folder. The search text is not stored.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -198,6 +211,8 @@ pub struct PortPreferences {
pub verified: bool,
/// Only entries installed by GameNode.
pub installed: bool,
/// The remembered platform slice; defaults to every entry.
pub platform_filter: PortPlatformFilter,
/// The parent folder offered first by the next install.
pub last_parent: Option<String>,
}
Expand Down Expand Up @@ -247,10 +262,14 @@ mod tests {
assert!(!preferences.guided);
assert!(!preferences.verified);
assert!(!preferences.installed);
assert_eq!(
preferences.platform_filter,
crate::ports::PortPlatformFilter::All
);
assert_eq!(preferences.last_parent, None);
assert_eq!(
serde_json::to_string(&preferences).unwrap(),
r#"{"view":"grid","consoles":[],"guided":false,"verified":false,"installed":false,"lastParent":null}"#
r#"{"view":"grid","consoles":[],"guided":false,"verified":false,"installed":false,"platformFilter":"all","lastParent":null}"#
);
}
}
6 changes: 5 additions & 1 deletion crates/core/src/ports/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use crate::ports::store::PortViewMode;
use crate::ports::store::{PortPlatformFilter, PortViewMode};

/// Where the PC ports destination exists. Reported through `AppInfo.platform` as well.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -130,6 +130,8 @@ pub enum PortNoAssetReason {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PortInstallBlockReason {
/// This build serves the catalog but cannot install ports yet (Linux phase 1).
ComingSoon,
Withdrawn,
NoVerifiedRelease,
InstallerOnly,
Expand Down Expand Up @@ -333,6 +335,8 @@ pub struct PortFiltersView {
pub guided: bool,
pub verified: bool,
pub installed: bool,
#[serde(default)]
pub platform: PortPlatformFilter,
}

/// Remembered view state.
Expand Down
Loading
Loading