mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 08:38:00 +00:00
Fixed the page argument vocabulary being dead code on Linux
This commit is contained in:
1 file changed
+39
-25
+39
-25
@@ -519,42 +519,44 @@ fn refuse_document(requested_path: &Path) -> Option<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to show the document on the given page, and says whether it did.
|
/// Tries to show the document on the given page, and says whether it did.
|
||||||
///
|
#[cfg(any(windows, target_os = "linux"))]
|
||||||
/// On macOS this always answers `false`: `open` drops the fragment of a URL before the program it
|
|
||||||
/// starts ever sees it, with and without `-a`, so a page cannot be named from the command line.
|
|
||||||
/// The document opens on its first page there, and the source names the page for the reader.
|
|
||||||
async fn try_open_at_page(path: &Path, page: u32) -> bool {
|
async fn try_open_at_page(path: &Path, page: u32) -> bool {
|
||||||
#[cfg(any(windows, target_os = "linux"))]
|
let DocumentOpenPlan::WithPage { program, arguments } = resolve_document_open_plan(path, page).await else {
|
||||||
{
|
return false;
|
||||||
let DocumentOpenPlan::WithPage { program, arguments } = resolve_document_open_plan(path, page).await else {
|
};
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
return match start_page_aware_viewer(&program, &arguments) {
|
match start_page_aware_viewer(&program, &arguments) {
|
||||||
Ok(()) => true,
|
Ok(()) => true,
|
||||||
|
|
||||||
//
|
//
|
||||||
// Failing to start the viewer ourselves is not something the user has to hear about:
|
// Failing to start the viewer ourselves is not something the user has to hear about: the
|
||||||
// the caller opens the document plainly afterwards, only without the page.
|
// caller opens the document plainly afterwards, only without the page.
|
||||||
//
|
//
|
||||||
Err(issue) => {
|
Err(issue) => {
|
||||||
warn!(Source = "Tauri"; "Could not open '{}' at page {page}, opening it without a page instead: {issue}", path.to_string_lossy());
|
warn!(Source = "Tauri"; "Could not open '{}' at page {page}, opening it without a page instead: {issue}", path.to_string_lossy());
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
/// Never shows a page on macOS.
|
||||||
{
|
///
|
||||||
let _ = (path, page);
|
/// `open` drops the fragment of a URL before the program it starts ever sees it, with and without
|
||||||
false
|
/// `-a`, so a page cannot be named from the command line at all. The document opens on its first
|
||||||
}
|
/// page, and the source names the page for the reader.
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn try_open_at_page(_path: &Path, _page: u32) -> bool {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How a document viewer wants to be told which page to show.
|
/// How a document viewer wants to be told which page to show.
|
||||||
///
|
///
|
||||||
/// They all mean the same thing and every one of them spells it differently. A viewer which is not
|
/// They all mean the same thing and every one of them spells it differently. A viewer which is not
|
||||||
/// covered here shows its first page, which is what the system would have done anyway.
|
/// covered here shows its first page, which is what the system would have done anyway.
|
||||||
|
///
|
||||||
|
/// Which spellings exist follows from where a viewer is found: Acrobat is named by the Windows
|
||||||
|
/// registration and by nothing else, and the three Linux viewers are named by a desktop entry and
|
||||||
|
/// by nothing else. Only a browser is reached on both, so only its spelling is needed everywhere.
|
||||||
#[cfg(any(windows, target_os = "linux", test))]
|
#[cfg(any(windows, target_os = "linux", test))]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
enum PageArgument {
|
enum PageArgument {
|
||||||
@@ -563,15 +565,19 @@ enum PageArgument {
|
|||||||
UrlFragment,
|
UrlFragment,
|
||||||
|
|
||||||
/// Acrobat and Acrobat Reader take an open action: `/A page=12`.
|
/// Acrobat and Acrobat Reader take an open action: `/A page=12`.
|
||||||
|
#[cfg(any(windows, test))]
|
||||||
AcrobatOpenAction,
|
AcrobatOpenAction,
|
||||||
|
|
||||||
/// The GNOME document viewer and its forks count from zero, so page 12 is index 11.
|
/// The GNOME document viewer and its forks count from zero, so page 12 is index 11.
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
ZeroBasedIndex,
|
ZeroBasedIndex,
|
||||||
|
|
||||||
/// Okular takes `-p 12`.
|
/// Okular takes `-p 12`.
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
OkularPage,
|
OkularPage,
|
||||||
|
|
||||||
/// Zathura takes `-P 12`.
|
/// Zathura takes `-P 12`.
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
ZathuraPage,
|
ZathuraPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,9 +608,17 @@ fn page_arguments(argument: PageArgument, path: &Path, page: u32) -> Option<Vec<
|
|||||||
let path_argument = path.to_string_lossy().to_string();
|
let path_argument = path.to_string_lossy().to_string();
|
||||||
Some(match argument {
|
Some(match argument {
|
||||||
PageArgument::UrlFragment => vec![document_url_with_page(path, page)?],
|
PageArgument::UrlFragment => vec![document_url_with_page(path, page)?],
|
||||||
|
|
||||||
|
#[cfg(any(windows, test))]
|
||||||
PageArgument::AcrobatOpenAction => vec![String::from("/A"), format!("page={page}"), path_argument],
|
PageArgument::AcrobatOpenAction => vec![String::from("/A"), format!("page={page}"), path_argument],
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
PageArgument::ZeroBasedIndex => vec![format!("--page-index={}", page.saturating_sub(1)), path_argument],
|
PageArgument::ZeroBasedIndex => vec![format!("--page-index={}", page.saturating_sub(1)), path_argument],
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
PageArgument::OkularPage => vec![String::from("-p"), page.to_string(), path_argument],
|
PageArgument::OkularPage => vec![String::from("-p"), page.to_string(), path_argument],
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", test))]
|
||||||
PageArgument::ZathuraPage => vec![String::from("-P"), page.to_string(), path_argument],
|
PageArgument::ZathuraPage => vec![String::from("-P"), page.to_string(), path_argument],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user