Skip to content

Commit b93f7cf

Browse files
committed
Add welcome screen for first-time users
Show a welcome screen on first launch and add a GSettings key to track first boot. Integrate WelcomeScreen into application startup flow.
1 parent 3f627a4 commit b93f7cf

4 files changed

Lines changed: 86 additions & 9 deletions

File tree

data/io.github.lainsce.Notejot.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
<summary>Active map source</summary>
1010
<description>The type of the map last used</description>
1111
</key>
12+
<key type="b" name="is-first-boot">
13+
<default>true</default>
14+
<summary>First run indicator</summary>
15+
<description>Whether to show the welcome screen on startup</description>
16+
</key>
1217
</schema>
1318
</schemalist>

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ sources = [
4141
'src/ReminderService.vala',
4242
'src/SettingsWindow.vala',
4343
'src/SettingsManager.vala',
44+
'src/WelcomeScreen.vala',
4445
]
4546

4647
dependencies = [

src/Application.vala

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ namespace Notejot {
77
{ "quit", quit },
88
};
99

10+
// Hold a strong reference so the welcome window isn't GC'ed
11+
private WelcomeScreen? welcome_screen = null;
12+
1013
public NotejotApp () {
11-
Object (application_id: "io.github.lainsce.Notejot");
14+
Object (application_id : "io.github.lainsce.Notejot");
1215
}
1316

1417
static construct {
@@ -21,7 +24,40 @@ namespace Notejot {
2124
}
2225

2326
public override void activate () {
24-
this.active_window?.present ();
27+
var window = this.active_window;
28+
if (window == null) {
29+
window = new Window (this);
30+
}
31+
window.present ();
32+
33+
if (WelcomeScreen.should_show (settings)) {
34+
this.welcome_screen = new WelcomeScreen (window);
35+
36+
// Make the Gtk.Application own the welcome window as well
37+
this.add_window (this.welcome_screen);
38+
39+
GLib.Idle.add (() => {
40+
// It may have been closed quickly; guard against null
41+
if (this.welcome_screen != null) {
42+
this.welcome_screen.present ();
43+
}
44+
return false;
45+
});
46+
47+
this.welcome_screen.finished.connect (() => {
48+
this.welcome_screen.mark_completed ();
49+
50+
// Close the welcome window and drop our reference
51+
this.welcome_screen.close ();
52+
this.welcome_screen = null;
53+
54+
this.reminder_service = new ReminderService ();
55+
this.reminder_service.start ();
56+
});
57+
} else {
58+
this.reminder_service = new ReminderService ();
59+
this.reminder_service.start ();
60+
}
2561
}
2662

2763
public override void startup () {
@@ -44,19 +80,16 @@ namespace Notejot {
4480
base.startup ();
4581

4682
add_action_entries (APP_ENTRIES, this);
83+
new Window (this);
4784

4885
// React to dark-mode changes
4986
this.app_css_provider = new Gtk.CssProvider ();
50-
var settings = Gtk.Settings.get_default ();
51-
if (settings != null) {
52-
settings.notify["gtk-application-prefer-dark-theme"].connect (() => {
87+
var gsettings = Gtk.Settings.get_default ();
88+
if (gsettings != null) {
89+
gsettings.notify["gtk-application-prefer-dark-theme"].connect (() => {
5390
load_theme_css ();
5491
});
5592
}
56-
57-
new Window (this);
58-
this.reminder_service = new ReminderService ();
59-
this.reminder_service.start ();
6093
}
6194

6295
private void load_theme_css () {

src/WelcomeScreen.vala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace Notejot {
2+
public class WelcomeScreen : He.WelcomeScreen {
3+
public signal void finished ();
4+
5+
public WelcomeScreen (Gtk.Window parent) {
6+
Object (parent: parent);
7+
8+
this.app_name = "Notejot";
9+
10+
this.add_row (new He.WelcomeRow ("list-add-symbolic",
11+
_("Create Entries"),
12+
_("Capture your thoughts quickly with a simple, focused editor."),
13+
He.Colors.ORANGE));
14+
15+
this.add_row (new He.WelcomeRow ("tag-symbolic",
16+
_("Organize with Tags"),
17+
_("Group related notes with colorful tags and icons."),
18+
He.Colors.PURPLE));
19+
20+
this.add_row (new He.WelcomeRow ("alarm-symbolic",
21+
_("Keep Your Streak"),
22+
_("Enable reminders to build a daily writing habit."),
23+
He.Colors.GREEN));
24+
25+
this.get_start_button ().clicked.connect (() => {
26+
this.finished ();
27+
});
28+
}
29+
30+
public static bool should_show (GLib.Settings settings) {
31+
return settings.get_boolean ("is-first-boot");
32+
}
33+
34+
public void mark_completed () {
35+
NotejotApp.settings.set_boolean ("is-first-boot", false);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)