Skip to content

Commit 4edaf62

Browse files
committed
feat: added a splashscreen lab
1 parent 6e7cb75 commit 4edaf62

File tree

3 files changed

+83
-6
lines changed

3 files changed

+83
-6
lines changed

src/content/docs/learn/index.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ sidebar:
1111
import Stub from '@components/Stub.astro';
1212

1313
<Stub />
14+
15+
## Create lab apps
16+
17+
Each lab assumes you've created a fresh new app for each of them. That doesn't necessarily have to be
18+
the case, you can certainly experiment using your own app, or using different options than what the
19+
lab assumes, but we strongly recommend you set up a new app for each lab so that it becomes as easy
20+
as possible to follow along.
21+
22+
```sh
23+
# Create a new app using CTA
24+
npx create-tauri-app --beta --mobile
25+
# Spam hit "Enter" to get all defaults
26+
```

src/content/docs/learn/splashscreen.mdx

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,67 @@ sidebar:
66
variant: caution
77
---
88

9-
import Stub from '@components/Stub.astro';
9+
import { Steps } from '@astrojs/starlight/components';
1010

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+
****

src/styles/custom.css

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
}
119119

120120
/* Tauri logo on index page */
121-
.hero > img {
121+
.hero>img {
122122
animation: 3s intro;
123123
opacity: 0.4;
124124
}
@@ -127,7 +127,7 @@
127127
display: inline-block;
128128
}
129129

130-
html[data-theme='light'] .hero > img {
130+
html[data-theme='light'] .hero>img {
131131
filter: invert(1);
132132
}
133133

@@ -141,12 +141,15 @@ html[data-theme='light'] .hero > img {
141141
scale: 0.9;
142142
}
143143

144-
100% {
145-
}
144+
100% {}
146145
}
147146

148147
@media (prefers-reduced-motion) {
149148
* {
150149
transition: none !important;
151150
}
152151
}
152+
153+
.sl-steps>li>a:first-of-type {
154+
text-decoration: none;
155+
}

0 commit comments

Comments
 (0)