@@ -6,6 +6,67 @@ sidebar:
6
6
variant : caution
7
7
---
8
8
9
- import Stub from ' @components/Stub.astro ' ;
9
+ import { Steps } from ' @astrojs/starlight/components ' ;
10
10
11
- <Stub />
11
+ In this lab we'll be implementing a basic splashscreen functionality in a Tauri app. Doing so
12
+ is quite straight forward, a splashscreen is effectively just a matter of creating a new window
13
+ that displays some contents during the period your app is doing some heavy setup related tasks.
14
+
15
+ ## Prerequisites
16
+
17
+ - [ A basic development environment setup] ( /start/prerequisites )
18
+ - [ Create a new lab app] ( /learn#create-lab-apps )
19
+
20
+ ## Steps
21
+
22
+ <Steps >
23
+
24
+ 1 . <a id = " step-1" href = " #step-1" >** Register new windows in ` tauri.conf.json ` ** </a >
25
+
26
+ The easiest way of adding new windows is by adding them directly to ` tauri.conf.json ` . You can also create them dynamically at startup,
27
+ but for the sake of simplicity lets just register them instead.
28
+
29
+ 2 . <a id = " step-2" href = " #step-2" >** Create a new page to host your splashscreen** </a >
30
+
31
+ Before you begin you'll need to have some content to show. How you develop new pages depend on your chosen framework,
32
+ most have the concept of a "router" that handles page navigation which should work just like normal in Tauri in which case
33
+ you just create a new splashscreen page. Or as we're going to be doing here, create a new ` splashscreen.html ` file to host
34
+ the contents.
35
+
36
+ All that's important here is that you can navigate to a ` /splashscreen ` URL and be shown the contents you want for your
37
+ splashscreen.
38
+
39
+ 3 . <a id = " step-3" href = " #step-3" >** Open your main window in hidden mode** </a >
40
+
41
+ Splashscreens are primarily used to hide loading times, so it makes sense to show your main window so that its contents can
42
+ be loaded. Additionally, for apps that are more frontend heavy, this is how you'd get your JS based setup scripts to run.
43
+
44
+ 4 . <a id = " step-4" href = " #step-4" >** Perform some heavy setup task in the backend** </a >
45
+
46
+ Perform some heavy setup functions in the ` .setup(|app| {}) ` hook, then store its readiness in a ` State ` . We do this because
47
+ it lets us perform work in both the frontend and the backend before the splashscreen is closed.
48
+
49
+ 5 . <a id = " step-5" href = " #step-5" >** Create a command to determine if setup is complete** </a >
50
+
51
+ Using a custom Tauri command we can synchronize our frontend and backend related setup tasks to determine if everything we
52
+ expect to be done is in fact so, after which we can close the splashscreen and unhide the main window.
53
+
54
+ 6 . <a id = " step-6" href = " #step-6" >** Close the splashscreen window** </a >
55
+
56
+ </Steps >
57
+
58
+ ## Discuss
59
+
60
+ ** Should you have a splashscreen?**
61
+
62
+ In general having a splashscreen is an admittance of defeat that you couldn't make your
63
+ app load fast enough to not need one. In fact it tends to be better to just go straight
64
+ to a main window that then shows some little spinner somewhere in a corner informing the
65
+ user there's still setup tasks happening in the background.
66
+
67
+ However, with that said, it can be a stylistic choice that you want to have a splashscreen,
68
+ or you might have some very particular requirement that makes it impossible to even start the
69
+ app until some tasks are performed. It's definitely not * wrong* to have a splashscreen, it
70
+ just tends to not be necessary and can make users feel like the app isn't very well optimized.
71
+
72
+ ****
0 commit comments