Repository: ruffle-rs/ruffle (language: rust)

Issue:
[Linux] "Open with Ruffle" does not work
### Describe the bug

Double-clicking a SWF file or right-clicking and using "Open with Ruffle" on Linux, KDE Plasma, Wayland, using the Flatpak distribution, does not work.

If I open a SWF file in this way, Ruffle only gives me a white screen and becomes a bit unresponsive. Closing the SWF (not the Ruffle window) and opening another SWF also does not work. It only works when I restart Ruffle and open a SWF using the "Open..." submenu in the app (or the "Recents" submenu).

My SWF files are stored in an external drive, and the Flatpak app has read+write access to the entire folder where the SWFs are located.

It works normally when I use the app's built-in option, but the desktop integration doesn't.

I tried changing the `Exec=` line of the `.desktop` file to `%U` instead of `%u`, but it didn't work. (https://specifications.freedesktop.org/desktop-entry-spec/latest/exec-variables.html)

Since this happens with any SWF, I think I don't need to provide a specific SWF for testing, but let me know if you need one.

### Expected behavior

N/A

### Content Location

N/A

### Affected platform

Desktop app

### Operating system

Linux

### Browser

N/A

### Additional information

N/A
[Linux] "Open with Ruffle" does not work
### Describe the bug

Double-clicking a SWF file or right-clicking and using "Open with Ruffle" on Linux, KDE Plasma, Wayland, using the Flatpak distribution, does not work.

If I open a SWF file in this way, Ruffle only gives me a white screen and becomes a bit unresponsive. Closing the SWF (not the Ruffle window) and opening another SWF also does not work. It only works when I restart Ruffle and open a SWF using the "Open..." submenu in the app (or the "Recents" submenu).

My SWF files are stored in an external drive, and the Flatpak app has read+write access to the entire folder where the SWFs are located.

It works normally when I use the app's built-in option, but the desktop integration doesn't.

I tried changing the `Exec=` line of the `.desktop` file to `%U` instead of `%u`, but it didn't work. (https://specifications.freedesktop.org/desktop-entry-spec/latest/exec-variables.html)

Since this happens with any SWF, I think I don't need to provide a specific SWF for testing, but let me know if you need one.

### Expected behavior

N/A

### Content Location

N/A

### Affected platform

Desktop app

### Operating system

Linux

### Browser

N/A

### Additional information

N/A


Discussion / hints:
Opening files with Ruffle on Fedora KDE, Wayland works for me.

Is there any difference between clicking "Open with Ruffle" and running `flatpak run rs.ruffle.Ruffle <path to the SWF>` from the command line?
I'm also on Fedora.

> Is there any difference [...]

There is no difference. From the cmd line it also doesn't work. Here is the output from the terminal if it helps: https://0.jaegers.net/?08baef5ab0192883#64JcVJXZLcbUvvEaemG566ePXDjzyrJAHs6sWN4EpVwd
Can you share the SWF that doesn't work?
Sure. No SWF works in this bugged state, so I don't believe it is a SWF-specific thing.
SWFs work normally when I use the built-in "Open" option.

Please let me know if I can use some env. var. or something similar to provide more useful debug logs.

Here's the SWF: https://send.vis.ee/download/97650db147febfc8/#7imvcqxnEKwZTLtPeusJEQ
Maybe this is a file-forwarding problem rather than a Flash problem.
Doesn't the last line in the log indicate that the file was loaded and read successfully?
> 2025-01-26T10:50:10.339514Z  INFO ruffle_core::context: Loaded SWF version 10, resolution 498x310 @ 10 FPS
Yes, it seems like it. However, it doesn't work. Here's a screenshot:

![image](https://github.com/user-attachments/assets/bcd15cb8-eb34-4923-ab6c-4e0715268cfc)

It works when I use the "Open" option in the app itself.
Anything changes when you resize the window?
Yes. After resizing the window and opening the file again (via Recents) it works normally.

I also discovered the issue is caused by my window rule to maximize Ruffle when opening. Removing the window rule fixes the problem, but it starts not maximized, which is not desired for me.

I think either Ruffle or KDE is trying to maximize the SWF instead of the window (somehow), resulting in this issue.
Symptoms and conditions similar to https://github.com/ruffle-rs/ruffle/issues/11364

I think we have to be more lax and make less assumptions about events we're gonna get.

CC @sleepycatcoding 
Opening files with Ruffle on Fedora KDE, Wayland works for me.

Is there any difference between clicking "Open with Ruffle" and running `flatpak run rs.ruffle.Ruffle <path to the SWF>` from the command line?
I'm also on Fedora.

> Is there any difference [...]

There is no difference. From the cmd line it also doesn't work. Here is the output from the terminal if it helps: https://0.jaegers.net/?08baef5ab0192883#64JcVJXZLcbUvvEaemG566ePXDjzyrJAHs6sWN4EpVwd
Can you share the SWF that doesn't work?
Sure. No SWF works in this bugged state, so I don't believe it is a SWF-specific thing.
SWFs work normally when I use the built-in "Open" option.

Please let me know if I can use some env. var. or something similar to provide more useful debug logs.

Here's the SWF: https://send.vis.ee/download/97650db147febfc8/#7imvcqxnEKwZTLtPeusJEQ
Maybe this is a file-forwarding problem rather than a Flash problem.
Doesn't the last line in the log indicate that the file was loaded and read successfully?
> 2025-01-26T10:50:10.339514Z  INFO ruffle_core::context: Loaded SWF version 10, resolution 498x310 @ 10 FPS
Yes, it seems like it. However, it doesn't work. Here's a screenshot:

![image](https://github.com/user-attachments/assets/bcd15cb8-eb34-4923-ab6c-4e0715268cfc)

It works when I use the "Open" option in the app itself.
Anything changes when you resize the window?
Yes. After resizing the window and opening the file again (via Recents) it works normally.

I also discovered the issue is caused by my window rule to maximize Ruffle when opening. Removing the window rule fixes the problem, but it starts not maximized, which is not desired for me.

I think either Ruffle or KDE is trying to maximize the SWF instead of the window (somehow), resulting in this issue.
Symptoms and conditions similar to https://github.com/ruffle-rs/ruffle/issues/11364

I think we have to be more lax and make less assumptions about events we're gonna get.

CC @sleepycatcoding 

Fix patch:
diff --git a/desktop/src/app.rs b/desktop/src/app.rs
index c9e2ba82c0992..42278f70c4cfc 100644
--- a/desktop/src/app.rs
+++ b/desktop/src/app.rs
@@ -257,7 +257,7 @@ impl MainWindow {
         // do not resize while window is maximized.
         let should_resize = !self.gui.window().is_maximized();
 
-        let viewport_size = if should_resize {
+        let (viewport_size, state) = if should_resize {
             let movie_width = swf_header.stage_size().width().to_pixels();
             let movie_height = swf_header.stage_size().height().to_pixels();
 
@@ -312,17 +312,19 @@ impl MainWindow {
             // On X11 (and possibly other platforms), the window size is not updated immediately.
             // On a successful resize request, wait for the window to be resized to the requested size
             // before we start running the SWF (which can observe the viewport size in "noScale" mode)
-            if !window_resize_denied && window_size != viewport_size.into() {
-                self.loaded = LoadingState::WaitingForResize;
+            let state = if !window_resize_denied && window_size != viewport_size.into() {
+                LoadingState::WaitingForResize
             } else {
-                self.loaded = LoadingState::Loaded;
-            }
+                LoadingState::Loaded
+            };
 
-            viewport_size
+            (viewport_size, state)
         } else {
-            self.gui.window().inner_size()
+            (self.gui.window().inner_size(), LoadingState::Loaded)
         };
 
+        self.loaded = state;
+
         self.gui.window().set_fullscreen(if self.start_fullscreen {
             Some(Fullscreen::Borderless(None))
         } else {


Test patch: