Skip to content

Commit

Permalink
Fix MRPACK export file include, add webview2 fail msg, fix window sta…
Browse files Browse the repository at this point in the history
…te (#2273)

* Fix MRPACK export file include, add webview2 fail msg, fix window state

* fix limt
  • Loading branch information
Geometrically authored Aug 23, 2024
1 parent c8befb6 commit 58dac27
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 24 deletions.
71 changes: 71 additions & 0 deletions Cargo.lock

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

12 changes: 2 additions & 10 deletions apps/app-frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ initialize_state()
})
const handleClose = async () => {
await saveWindowState(StateFlags.ALL)
await TauriWindow.getCurrent().close()
}
Expand Down Expand Up @@ -293,16 +294,7 @@ async function handleCommand(e) {
<Button class="titlebar-button" icon-only @click="() => appWindow.toggleMaximize()">
<MaximizeIcon />
</Button>
<Button
class="titlebar-button close"
icon-only
@click="
() => {
saveWindowState(StateFlags.ALL)
handleClose()
}
"
>
<Button class="titlebar-button close" icon-only @click="handleClose">
<XIcon />
</Button>
</section>
Expand Down
2 changes: 2 additions & 0 deletions apps/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ paste = "1.0.15"

opener = { version = "0.7.2", features = ["reveal", "dbus-vendored"] }

native-dialog = "0.7.0"

[target.'cfg(not(target_os = "linux"))'.dependencies]
window-shadows = "0.2.1"

Expand Down
68 changes: 55 additions & 13 deletions apps/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
windows_subsystem = "windows"
)]

use native_dialog::{MessageDialog, MessageType};
use tauri::{Manager, PhysicalSize};
use tauri_plugin_window_state::{StateFlags, WindowExt};
use theseus::prelude::*;

mod api;
Expand Down Expand Up @@ -31,15 +33,28 @@ async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
#[tauri::command]
fn show_window(app: tauri::AppHandle) {
let win = app.get_window("main").unwrap();
win.show().unwrap();
win.set_focus().unwrap();

// fix issue where window shows as extremely small
if let Ok(size) = win.inner_size() {
let width = if size.width < 1100 { 1280 } else { size.width };
let height = if size.height < 700 { 800 } else { size.height };

win.set_size(PhysicalSize::new(width, height)).unwrap();
if let Err(e) = win.show() {
MessageDialog::new()
.set_type(MessageType::Error)
.set_title("Initialization error")
.set_text(&format!(
"Cannot display application window due to an error:\n{}",
e
))
.show_alert()
.unwrap();
panic!("cannot display application window")
} else {
let _ = win.restore_state(StateFlags::all());
let _ = win.set_focus();

// fix issue where window shows as extremely small
if let Ok(size) = win.inner_size() {
let width = if size.width < 1100 { 1280 } else { size.width };
let height = if size.height < 700 { 800 } else { size.height };

let _ = win.set_size(PhysicalSize::new(width, height));
}
}
}

Expand Down Expand Up @@ -160,7 +175,7 @@ fn main() {

if let Some(window) = app.get_window("main") {
// Hide window to prevent white flash on startup
window.hide().unwrap();
let _ = window.hide();

#[cfg(not(target_os = "linux"))]
{
Expand Down Expand Up @@ -215,7 +230,34 @@ fn main() {
show_window,
]);

builder
.run(tauri::generate_context!())
.expect("error while running tauri application");
if let Err(e) = builder.run(tauri::generate_context!()) {
#[cfg(target_os = "windows")]
{
// tauri doesn't expose runtime errors, so matching a string representation seems like the only solution
if format!("{:?}", e)
.contains("Runtime(CreateWebview(WebView2Error(WindowsError")
{
MessageDialog::new()
.set_type(MessageType::Error)
.set_title("Initialization error")
.set_text("Your Microsoft Edge WebView2 installation is corrupt.\n\nMicrosoft Edge WebView2 is required to run Modrinth App.\n\nLearn how to repair it at https://docs.modrinth.com/faq/app/webview2")
.show_alert()
.unwrap();

panic!("webview2 initialization failed")
}
}

MessageDialog::new()
.set_type(MessageType::Error)
.set_title("Initialization error")
.set_text(&format!(
"Cannot initialize application due to an error:\n{:?}",
e
))
.show_alert()
.unwrap();

panic!("{1}: {:?}", e, "error while running tauri application")
}
}
4 changes: 3 additions & 1 deletion packages/app-lib/src/api/profile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ pub async fn export_mrpack(
let relative_path = pack_get_relative_path(&profile_base_path, &path)?;

if packfile.files.iter().any(|f| f.path == relative_path)
|| !included_candidates_set.contains(&relative_path)
|| !included_candidates_set
.iter()
.any(|x| relative_path.starts_with(&**x))
{
continue;
}
Expand Down

0 comments on commit 58dac27

Please sign in to comment.