Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/console.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ jobs:
- name: NVDEC streams
run: sudo apt-get update && sudo apt-get install -y ffmpeg && scripts/nvdec-streams.sh
- uses: actions/upload-artifact@v4
# A storage quota must not red the build; the title is proven by the link above.
continue-on-error: true
with:
name: pf-nx-probe
path: |
dist/pf-nx-probe.nro
dist/pf-nx-probe.elf
dist/nvdec-*
- uses: actions/upload-artifact@v4
# A storage quota must not red the build; the title is proven by the link above.
continue-on-error: true
with:
name: punktfunk
path: |
Expand Down
32 changes: 21 additions & 11 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ ash = { version = "0.38", default-features = false, features = ["debug", "std"]
skia-safe = { version = "0.153", features = ["textlayout"] }
# One REV for all shared crates: a tag and a rev build two copies whose types don't unify.
# At least the merge of monorepo #2180, which carries the Horizon cfgs this client builds on.
punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", features = ["quic"] }
pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false }
pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false }
punktfunk-core = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", features = ["quic", "l10n"] }
pf-client-core = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false }
pf-console-ui = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false }
# The parts this crate reads itself. The host's sentences come worded from the core.
pf-l10n = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false, features = ["client", "console", "host"] }
# No `pyrowave` here: pf-nx-vk's own feature turns the lane on (plan D14), so a default build
# compiles none of the wavelet decoder for the console.
pf-client-video = { git = "https://git.unom.io/unom/punktfunk", rev = "12e4dfd1ba7855d0043a15c2939fc923a85771ef", default-features = false }
pf-client-video = { git = "https://git.unom.io/unom/punktfunk", rev = "b58dc3cfe152c48c584c8e2f77dc05d08f6aeb12", default-features = false }

[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "deny"
Expand Down
5 changes: 5 additions & 0 deletions crates/pf-nx-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tracing-appender = "0.2"
punktfunk-core.workspace = true
pf-client-core.workspace = true
pf-console-ui.workspace = true
pf-l10n.workspace = true
skia-safe.workspace = true
# Library and art fetch over pinned TLS. No ureq backend feature: the provider is named in code.
# `~3.4`: the connector uses ureq's `unversioned` transport API, which 3.5 changed.
Expand All @@ -32,5 +33,9 @@ miniz_oxide = "0.8"
serde_json = "1"
miniz_oxide = "0.8"

[dev-dependencies]
# `en-XA`, the pseudo-language the tests word in to find text that does not come from pf-l10n.
pf-l10n = { workspace = true, features = ["pseudo"] }

[lints]
workspace = true
103 changes: 40 additions & 63 deletions crates/pf-nx-app/src/core/errors.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,37 @@
//! User-facing sentences for `punktfunk-core`'s error and rejection types.
//!
//! Ported from `pf-client-core::trust`'s `connect_reject_message`/`pair_error_message` —
//! the same wording every other punktfunk client shows — rather than depending on that
//! crate (see `session`'s module docs for why this client can't).
//!
//! Without this, failures render as Debug strings (e.g. "connect: Rejected(Busy)").
use punktfunk_core::reject::RejectReason;

//! A host's refusal is worded by `pf-client-core`; the rest are this client's own, from
//! `pf-l10n`. Without this, failures render as Debug strings (e.g. "connect: Rejected(Busy)").
use pf_client_core::trust::connect_reject_message;
use pf_l10n::{client, console};
use punktfunk_core::PunktfunkError;

/// Why the host turned this connection away.
fn reject_message(reason: RejectReason) -> String {
match reason {
RejectReason::Denied => "The host declined this device's request.".into(),
RejectReason::ApprovalTimeout => {
"Nobody approved the request in time — approve this device, then try again.".into()
}
RejectReason::Superseded => {
"A newer request from this device replaced this one — approve the latest request.".into()
}
RejectReason::IdentityRequired => {
"The host requires pairing — pair this device (PIN or request access) first.".into()
}
RejectReason::PairingNotArmed => {
"Pairing isn't armed on the host — arm it on the host's Pairing page, then try again.".into()
}
RejectReason::PairingBoundToOtherDevice => {
"The host's pairing window is armed for a different device — arm it for this one.".into()
}
RejectReason::PairingRateLimited => {
"Too many pairing attempts — wait a couple of seconds and try again.".into()
}
RejectReason::WireVersionMismatch => {
"Client and host versions don't match — update both to the same release.".into()
}
RejectReason::Busy => "The host is busy with another session.".into(),
RejectReason::SetupFailed => {
"The host accepted the connection but couldn't start the stream — see host's logs.".into()
}
RejectReason::AccessExpired => {
"Your access to this host has expired — ask the host's owner to grant it again.".into()
}
RejectReason::HostPower => {
"The host is going to sleep or shutting down — wake it when you want to play again.".into()
}
RejectReason::LaunchNotPermitted => {
"This device isn't permitted to launch games on the host — connect without picking a game, \
or ask the host's owner to allow launching."
.into()
}
RejectReason::ProfileUnknown => "That profile is gone from this host. Pick another one.".into(),
RejectReason::NoSeat => "All seats are taken.".into(),
RejectReason::SeatOccupied => "Someone is already playing as that profile.".into(),
RejectReason::SeatUnavailable => "That profile can't play on this host right now.".into(),
}
}

/// Why connect/probe failed (distinguishes rejection from transport trouble).
fn connect_message(err: &PunktfunkError) -> String {
match err {
PunktfunkError::Rejected(reason, _) => reject_message(*reason),
PunktfunkError::Timeout => "The host didn't answer. Is it running and reachable?".into(),
PunktfunkError::Rejected(reason, _) => connect_reject_message(*reason),
PunktfunkError::Timeout => client::error_host_timeout().into(),
PunktfunkError::Io(e) => {
format!("Couldn't reach the host ({e}) — the console and the host must be on the same network.")
tracing::warn!(error = %e, "host unreachable");
client::error_host_unreachable().into()
}
PunktfunkError::Closed => "The host closed the connection.".into(),
other => format!("Connection failed: {other}"),
PunktfunkError::Closed => console::console_error_host_closed().into(),
other => console::console_error_connect_failed_detail(other),
}
}

/// Why PIN pairing failed (Crypto = wrong PIN, not network problem).
pub fn pair_message(err: &PunktfunkError) -> String {
match err {
PunktfunkError::Crypto => "Wrong PIN — check the PIN on the host's Pairing page and try again.".into(),
PunktfunkError::Crypto => client::pair_wrong_pin().into(),
other => connect_message(other),
}
}

/// Why a request for access failed. It has no PIN, so Crypto is a host that didn't match its advert.
pub fn access_message(err: &PunktfunkError) -> String {
match err {
PunktfunkError::Crypto => {
"The host didn't present the identity it advertised. Pair with its PIN instead.".into()
}
PunktfunkError::Crypto => client::pair_identity_mismatch().into(),
other => connect_message(other),
}
}
Expand All @@ -92,3 +41,31 @@ pub fn friendly(err: &anyhow::Error) -> String {
err.downcast_ref::<PunktfunkError>()
.map_or_else(|| format!("{err:#}"), connect_message)
}

#[cfg(test)]
mod tests {
use super::*;
use punktfunk_core::reject::RejectReason;

/// Every sentence a failure shows comes from `pf-l10n`: in the pseudo-language each reads
/// bracketed, and a literal would not.
#[test]
fn every_failure_reads_the_language() {
let errors = [
PunktfunkError::Rejected(RejectReason::Busy, String::new()),
PunktfunkError::Timeout,
PunktfunkError::Io(std::io::ErrorKind::NotFound.into()),
PunktfunkError::Closed,
PunktfunkError::Crypto,
PunktfunkError::BadPacket,
];
pf_l10n::with_language("en-XA", || {
for e in &errors {
for said in [pair_message(e), access_message(e)] {
assert!(said.starts_with('['), "{e:?}: {said}");
}
}
});
assert!(!pair_message(&PunktfunkError::Timeout).starts_with('['));
}
}
2 changes: 2 additions & 0 deletions crates/pf-nx-app/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct DeviceInfo {
pub ui: String,
/// Launched as an applet (from the album), with a fraction of the title's memory (plan D13).
pub applet_mode: bool,
/// The system's UI language as BCP-47 tags, most preferred first. Empty reads as English.
pub languages: Vec<String>,
}

/// Refresh rate of the scan-out, in millihertz (60 000, 59 940).
Expand Down
15 changes: 11 additions & 4 deletions crates/pf-nx-app/src/runtime/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ pub(super) fn run(app: &mut App, notice: Option<String>) -> Result<UiOutcome> {
gpu_cache_bytes: pf_console_ui::DEFAULT_GPU_CACHE_BYTES,
screen: None,
profiles: false,
// No profile picker, so a locked profile is dialled as it stands.
prompts_unlock: false,
spatial: false,
languages: app.device.languages.clone(),
};
let scripted = app.test_run.as_ref().and_then(|run| {
let host = run.host.as_deref()?;
Expand Down Expand Up @@ -166,7 +169,9 @@ pub(super) fn run(app: &mut App, notice: Option<String>) -> Result<UiOutcome> {
}
Err(e) => {
tracing::warn!("console: launch refused: {e:#}");
handles.console.set_notice(format!("Couldn't start the stream — {e}"));
handles
.console
.set_notice(pf_l10n::client::dial_stream_start_failed().to_string());
}
}
}
Expand Down Expand Up @@ -244,7 +249,7 @@ fn pad_label(batch: &[PadSample]) -> Option<&'static str> {
PadKind::JoyConLeft => "Joy-Con (L)",
PadKind::JoyConRight => "Joy-Con (R)",
PadKind::SwitchPro => "Pro Controller",
PadKind::Other => "Controller",
PadKind::Other => pf_l10n::console::console_pad_fallback_name(),
})
}

Expand All @@ -265,12 +270,14 @@ fn legend_pref(pref: GamepadPref) -> GamepadPref {

fn pad_infos(batch: &[PadSample], stored: GamepadType) -> impl Iterator<Item = PadInfo> + '_ {
batch.iter().map(move |s| PadInfo {
name: pad_label(std::slice::from_ref(s)).unwrap_or("Controller").into(),
name: pad_label(std::slice::from_ref(s))
.unwrap_or_else(pf_l10n::console::console_pad_fallback_name)
.into(),
key: format!("slot{}", s.slot),
pref: shown_kind(stored, std::slice::from_ref(s)).to_core(),
steam_virtual: false,
battery: None,
detail: format!("Player {}", s.slot + 1),
detail: pf_l10n::console::console_pad_player(s.slot + 1),
forwarded: true,
rumble: true,
})
Expand Down
12 changes: 8 additions & 4 deletions crates/pf-nx-app/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub fn run(platform: Platform) -> ! {
// Without a log there is nothing to diagnose a failure from; the title still runs.
let flush = crate::logger::init_subscriber(&crate::services::paths::logs_dir(), log).ok();
install_panic_hook();
let language = pf_l10n::set_languages(&device.languages);
tracing::info!(
"punktfunk-switch {} on {} ({} firmware {}), gpu {}, ui {}{}",
crate::core::build_id(),
Expand All @@ -113,6 +114,7 @@ pub fn run(platform: Platform) -> ! {
device.ui,
if device.applet_mode { ", applet mode" } else { "" },
);
tracing::info!("language {language} for the system's {:?}", device.languages);
punktfunk_core::client::set_client_label(&client_label(&device));
crate::core::caps::install(video.caps());
// ureq's agents resolve their provider from the process default and panic without one.
Expand Down Expand Up @@ -157,13 +159,15 @@ pub fn run(platform: Platform) -> ! {
lifecycle.exit()
}

/// What the first menu says when the title runs as an applet (plan D13).
const APPLET_MODE_NOTICE: &str =
"Opened from the Album, punktfunk has little memory and may close — hold R while starting a game to open it with full memory.";
/// What the first menu says when the title runs as an applet (plan D13). Holding `R` at
/// launch starts it with full memory.
fn applet_mode_notice() -> String {
pf_l10n::console::console_switch_applet_mode("R")
}

/// The menu and the stream in turn, until one of them quits.
fn alternate(app: &mut App) -> Option<ExitPlan> {
let mut notice = app.device.applet_mode.then(|| APPLET_MODE_NOTICE.to_string());
let mut notice = app.device.applet_mode.then(applet_mode_notice);
loop {
let outcome = match menu::run(app, notice.take()) {
Ok(outcome) => outcome,
Expand Down
Loading