Skip to content

Commit

Permalink
Try to fix Win32 build
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Jul 4, 2024
1 parent c2303f8 commit 9884276
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
7 changes: 5 additions & 2 deletions pot-browser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ bytesize.workspace = true
camino.workspace = true
anyhow.workspace = true
url.workspace = true
opener = { version = "0.7.1", features = ["reveal"] }

[target.'cfg(target_os = "macos")'.dependencies]
rfd = "0.12.1"
rfd = "0.12.1"

[target.'cfg(not(all(target_os = "windows", target_arch = "x86")))'.dependencies]
# This doesn't work on win32
opener = { version = "0.7.1", features = ["reveal"] }
40 changes: 31 additions & 9 deletions pot-browser/src/pot_browser_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ fn process_dialogs<I: PotBrowserIntegration>(input: ProcessDialogsInput<I>, ctx:
|ui, change_dialog| {
if ui.button("Close").clicked() {
if let PreviewOutputConfig::Export(c) = output_config_clone {
reveal(c.base_dir.as_std_path());
reveal_path(c.base_dir.as_std_path());
}
*change_dialog = Some(None);
};
Expand Down Expand Up @@ -1634,7 +1634,7 @@ fn add_preset_table(mut input: PresetTableInput, ui: &mut Ui, preset_cache: &mut
if let pot::PotPresetKind::FileBased(k) = &data.preset.kind {
if ui.button("Show preset in file manager").clicked() {
if k.path.exists() {
reveal(&k.path);
reveal_path(&k.path);
} else {
show_error_toast(
"Preset file doesn't exist",
Expand All @@ -1646,7 +1646,7 @@ fn add_preset_table(mut input: PresetTableInput, ui: &mut Ui, preset_cache: &mut
}
if let Some(preview_file) = &data.preview_file {
if ui.button("Show preview in file manager").clicked() {
reveal(preview_file);
reveal_path(preview_file);
ui.close_menu();
}
}
Expand Down Expand Up @@ -3480,20 +3480,42 @@ fn get_preview_rpp_path(

fn open_link(thing: &str) {
if thing.starts_with("file://") {
reveal(Path::new(thing));
reveal_path(Path::new(thing));
} else {
let _ = opener::open_browser(thing);
#[cfg(not(all(target_os = "windows", target_arch = "x86")))]
{
if opener::open_browser(thing).is_err() {
open_link_fallback(thing);
}
}
#[cfg(all(target_os = "windows", target_arch = "x86"))]
{
open_link_fallback(thing);
}
}
}

fn reveal(path: impl AsRef<Path>) {
fn open_link_fallback(link: &str) {
Reaper::get().show_console_msg(format!(
"Failed to open the following link in your browser. Please open it manually:\n\n{link}\n\n"
));
}

fn reveal_path(path: impl AsRef<Path>) {
let path = path.as_ref();
if opener::reveal(path).is_err() {
reveal_fallback(path);
#[cfg(not(all(target_os = "windows", target_arch = "x86")))]
{
if opener::reveal(path).is_err() {
reveal_path_fallback(path);
}
}
#[cfg(all(target_os = "windows", target_arch = "x86"))]
{
reveal_path_fallback(path);
}
}

fn reveal_fallback(path: &Path) {
fn reveal_path_fallback(path: &Path) {
Reaper::get().show_console_msg(
format!("Failed to open the following path in your file manager. Please open it manually:\n\n{path:?}\n\n")
);
Expand Down

0 comments on commit 9884276

Please sign in to comment.