From 89622697d5bb5591a57b250b3cf331f1d8b76c9d Mon Sep 17 00:00:00 2001
From: Cory McWilliams <cory@unprompted.com>
Date: Wed, 21 May 2025 18:48:29 -0400
Subject: [PATCH] intro: The default app is intro, and complete intro changes
 the default app to ssb.

---
 apps/intro.json       |  2 +-
 apps/intro/app.js     |  8 ++++
 apps/intro/index.html | 86 ++++++++++++++++++++-----------------------
 src/ssb.db.c          |  3 +-
 src/util.js.c         |  2 +-
 5 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/apps/intro.json b/apps/intro.json
index 707f795a..74e0fad1 100644
--- a/apps/intro.json
+++ b/apps/intro.json
@@ -1,5 +1,5 @@
 {
 	"type": "tildefriends-app",
 	"emoji": "📦",
-	"previous": "&To+YNrnau33KxhwpnZK7ctSLK/S/2KgEHJXYxffCels=.sha256"
+	"previous": "&jv/hWMidzVn7apsmPSWQRETz/saDQ79EPGgWVv+qPt0=.sha256"
 }
diff --git a/apps/intro/app.js b/apps/intro/app.js
index 4dae5544..42a23c62 100644
--- a/apps/intro/app.js
+++ b/apps/intro/app.js
@@ -1,5 +1,13 @@
+import * as tfrpc from '/tfrpc.js';
+
 async function main() {
 	await app.setDocument(utf8Decode(getFile('index.html')));
 }
 
+tfrpc.register(async function complete() {
+	if ((await core.globalSettingsGet('index')) == '/~core/intro/') {
+		return await core.globalSettingsSet('index', '/~core/ssb/');
+	}
+});
+
 main();
diff --git a/apps/intro/index.html b/apps/intro/index.html
index b3c4594f..56c479f4 100644
--- a/apps/intro/index.html
+++ b/apps/intro/index.html
@@ -41,7 +41,7 @@
 					<div>~😎 Tilde Friends.</div>
 				</div>
 				<footer>
-					<button class="w3-button w3-yellow" onclick="show(1)">Next</button>
+					<button class="w3-button w3-yellow proceed">Next</button>
 				</footer>
 			</div>
 			<div class="slide w3-card-4 w3-gray" style="width: 90%">
@@ -59,7 +59,7 @@
 					</li>
 				</ul>
 				<footer class="w3-center w3-xlarge w3-padding">
-					<button class="w3-button w3-yellow" onclick="show(1)">Onward</button>
+					<button class="w3-button w3-yellow proceed">Onward</button>
 				</footer>
 			</div>
 			<div class="slide w3-gray" style="width: 90%">
@@ -101,9 +101,7 @@
 							target="_blank"
 							>See scuttlebutt.nz</a
 						>
-						<button class="w3-button w3-yellow" onclick="show(1)">
-							Got It
-						</button>
+						<button class="w3-button w3-yellow proceed">Got It</button>
 					</footer>
 				</div>
 			</div>
@@ -172,9 +170,7 @@
 						</ul>
 					</div>
 					<footer class="w3-center w3-xlarge w3-padding">
-						<a class="w3-button w3-yellow" target="_top" href="/~core/ssb/"
-							>Let's Go!</a
-						>
+						<button class="w3-button w3-yellow" id="complete">Let's Go!</button>
 					</footer>
 				</div>
 			</div>
@@ -183,42 +179,21 @@
 			class="w3-text-white w3-xlarge w3-center w3-flex"
 			style="width: 100%; flex: 0 1; flex-direction: row; align-items: center"
 		>
-			<div
-				class="w3-jumbo"
-				onclick="show(-1)"
-				style="flex: 1 0; cursor: pointer"
-			>
+			<div class="w3-jumbo" id="left" style="flex: 1 0; cursor: pointer">
 				&#10094;
 			</div>
-			<span
-				class="w3-badge dot w3-border w3-hover-yellow"
-				onclick="set(0)"
-			></span>
-			<span
-				class="w3-badge dot w3-border w3-hover-yellow"
-				onclick="set(1)"
-			></span>
-			<span
-				class="w3-badge dot w3-border w3-hover-yellow"
-				onclick="set(2)"
-			></span>
-			<span
-				class="w3-badge dot w3-border w3-hover-yellow"
-				onclick="set(3)"
-			></span>
-			<span
-				class="w3-badge dot w3-border w3-hover-yellow"
-				onclick="set(4)"
-			></span>
-			<div
-				class="w3-jumbo"
-				style="flex: 1 0; cursor: pointer"
-				onclick="show(1)"
-			>
+			<span class="w3-badge dot w3-border w3-hover-yellow"></span>
+			<span class="w3-badge dot w3-border w3-hover-yellow"></span>
+			<span class="w3-badge dot w3-border w3-hover-yellow"></span>
+			<span class="w3-badge dot w3-border w3-hover-yellow"></span>
+			<span class="w3-badge dot w3-border w3-hover-yellow"></span>
+			<div class="w3-jumbo" style="flex: 1 0; cursor: pointer" id="right">
 				&#10095;
 			</div>
 		</div>
-		<script>
+		<script type="module">
+			import * as tfrpc from '/static/tfrpc.js';
+
 			let index = 0;
 			function set(i) {
 				show(i - index);
@@ -238,15 +213,32 @@
 						dot.classList.remove('w3-white');
 					}
 				}
-				for (let left of document.getElementsByClassName('w3-left')) {
-					left.style.visibility = index == 0 ? 'hidden' : 'visible';
-				}
-				for (let right of document.getElementsByClassName('w3-right')) {
-					console.log(index, slides.length - 1);
-					right.style.visibility =
-						index == slides.length - 1 ? 'hidden' : 'visible';
-				}
+				document.getElementById('left').style.visibility =
+					index == 0 ? 'hidden' : 'visible';
+				document.getElementById('right').style.visibility =
+					index == slides.length - 1 ? 'hidden' : 'visible';
 			}
+
+			let dots = [...document.getElementsByClassName('dot')];
+			for (let dot of dots) {
+				dot.onclick = () => set(dots.indexOf(dot));
+			}
+			for (let button of document.getElementsByClassName('proceed')) {
+				button.onclick = () => show(1);
+			}
+			document.getElementById('left').onclick = () => show(-1);
+			document.getElementById('right').onclick = () => show(1);
+			document.getElementById('complete').onclick = function () {
+				console.log('completing');
+				tfrpc.rpc.complete().then(function () {
+					console.log('completed');
+					let a = document.createElement('a');
+					a.href = '/~core/ssb/';
+					a.target = '_top';
+					document.body.appendChild(a);
+					a.click();
+				});
+			};
 			window.addEventListener('keyup', function (event) {
 				if (event.key == 'ArrowLeft') {
 					show(-1);
diff --git a/src/ssb.db.c b/src/ssb.db.c
index 35aa533c..08dd41fc 100644
--- a/src/ssb.db.c
+++ b/src/ssb.db.c
@@ -2202,8 +2202,7 @@ static void _tf_ssb_db_resolve_index_work(tf_ssb_t* ssb, void* user_data)
 
 	if (!request->path)
 	{
-		/* From default global settings. */
-		request->path = tf_strdup("/~core/ssb/");
+		request->path = tf_strdup(tf_util_get_default_global_setting_string("index"));
 	}
 }
 
diff --git a/src/util.js.c b/src/util.js.c
index 947ce37d..fedb87b5 100644
--- a/src/util.js.c
+++ b/src/util.js.c
@@ -368,7 +368,7 @@ static const setting_t k_settings[] = {
 		.type = "string",
 		.description = "If connecting by HTTP and HTTPS is configured, Location header prefix (ie, \"http://example.com\")",
 		.default_value = { .kind = k_kind_string, .string_value = NULL } },
-	{ .name = "index", .type = "string", .description = "Default path.", .default_value = { .kind = k_kind_string, .string_value = "/~core/ssb/" } },
+	{ .name = "index", .type = "string", .description = "Default path.", .default_value = { .kind = k_kind_string, .string_value = "/~core/intro/" } },
 	{ .name = "index_map",
 		.type = "textarea",
 		.description = "Mappings from hostname to redirect path, one per line, as in: \"www.tildefriends.net=/~core/index/\"",