flet icon indicating copy to clipboard operation
flet copied to clipboard

long app loading time looks like app crashes on startup

Open clstaudt opened this issue 3 years ago • 2 comments

I am building a desktop app with flet, which depends on a couple of Python libraries. Pyinstaller works like a charm, however, the resulting app bundle on a Mac has 300 MB.

When starting the app from the bundle, a startup icon appears:

Screenshot 2022-09-14 at 14 23 32

It then disappears for 10-20 seconds. The user might think that the app has failed to start. In fact it is still loading.

Finally the app appears in the dock with the flet default app icon:

Screenshot 2022-09-14 at 14 26 45

This will be a source of confusion for users. Is there a way to:

  • display a loading screen?
  • have the app icon be there and bounce during the entire startup phase?

clstaudt avatar Sep 14 '22 12:09 clstaudt

I think you are fighting here with PyInstaller mostly, not Flet. When you package everything into a single executable it becomes bascially just a zip which is unpacked on the first run and I guess it takes time to unpack 300 MB. What times do you get when not packing to a single file?

There is a splash screen for pyinstaller https://pyinstaller.org/en/stable/usage.html#splash-screen-experimental, but it doesn't work on macOS.

Another thing is to change Flet client to start Python program as a sub-process (vs Python starting Flet client as currently implemented). This way we would have more control over loading process. However, packaging would be different - pyinstaller won't work. Need to think about that scenario.

FeodorFitsner avatar Sep 14 '22 16:09 FeodorFitsner

What times do you get when not packing to a single file?

If I omit the --onefile option, I get a 770 MB .app bundle that opens almost instantly... but with another Python&FloppyDisk app icon bouncing next to it for a minute. That's also likely to confuse and annoy users who expect a native look and feel.

Screenshot 2022-09-14 at 18 58 24

So the choice is between a huge app file and slow loading? Is there anything else one could try?

My list of Python dependencies is not too large here, so I assume most real-world flet apps will have similar issues.

pytest
pandas
altair
pydantic
sqlalchemy
sqlmodel
pyicloud
ics
babel
loguru
pdfkit
flet
pandera

ps. Perhaps pandas & numpy are the culprits for the large app size.

clstaudt avatar Sep 14 '22 17:09 clstaudt

The use of the "onefile" option also concerns me. As pyinstaller/issues/4843, security checks are repeated every time the app is extracted to the temp directory.

Additionally, if "windowed" and "onedir" are used, FloppyDisk and flet icons appear simultaneously and system report the app crash upon closure, which will confuse the user.

ningzichun avatar Jan 31 '23 03:01 ningzichun

@FeodorFitsner do you have any idea how to prevent the pyinstaller icon from bouncing when using -windowed option? The -onefile option is really unusable on newer macos systems due to the security features mentioned above. The app gets unpacked on each run and treated as new. So no notarizing or signing differently will fix this.

I am sure we can find a solution to this bouncing icon issue and switch to windowed mode on macOS. Do you want me to open a new issue for that?

cbenhagen avatar Jun 09 '23 12:06 cbenhagen

@cbenhagen PyInstaller is a temporary solution, of course. We are going to implement a generation of macOS Flutter app with embedded Python, so you get a completely white-labeled, clean Flutter app without any hacks.

FeodorFitsner avatar Jun 09 '23 17:06 FeodorFitsner

@FeodorFitsner very interesting! Where can I learn more about this new approach?

cbenhagen avatar Jun 09 '23 17:06 cbenhagen

Sure, the solution is currently piloting for iOS. There is serious_python Flutter package that will be implemented for macOS (and other platforms) as well. Flutter app is just a bootstrap: https://github.com/flet-dev/serious-python/blob/main/example/flet_example/lib/main.dart

FeodorFitsner avatar Jun 09 '23 18:06 FeodorFitsner

Great project @FeodorFitsner! As much as I like Flet, serious-python is going to be much more useful to what I do as I am comfortable with Flutter but have some legacy Python apps I need to support as well as new projects where I like to use some Python libraries while using Flutter for the GUI. Looking forward to the macOS version!

cbenhagen avatar Jun 09 '23 18:06 cbenhagen