feat: bookmark the site directory on a first start

This commit is contained in:
randogoth 2026-10-11 22:58:02 +03:00
parent 95602ac623
commit dcb70a93d1
14 changed files with 506 additions and 1 deletions

View file

@ -127,6 +127,16 @@ class ClientCertificates extends Table {
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
}
/// What a fresh install has already been given, so it is given once: what
/// the reader removes afterwards stays removed.
class FirstStart extends Table {
IntColumn get id => integer().withDefault(const Constant(0))();
BoolColumn get directorySeeded => boolean().withDefault(const Constant(false))();
@override
Set<Column> get primaryKey => {id};
}
/// Which certificate the reader presents to one host: a binding the reader
/// made on a certificate request, worn only there.
class SiteCertificates extends Table {
@ -149,6 +159,7 @@ class SiteCertificates extends Table {
KnownHosts,
ClientCertificates,
SiteCertificates,
FirstStart,
])
class MewsDatabase extends _$MewsDatabase {
MewsDatabase() : super(_open());
@ -157,7 +168,7 @@ class MewsDatabase extends _$MewsDatabase {
MewsDatabase.test(super.executor);
@override
int get schemaVersion => 5;
int get schemaVersion => 6;
@override
MigrationStrategy get migration => MigrationStrategy(
@ -183,6 +194,9 @@ class MewsDatabase extends _$MewsDatabase {
await m.createTable(clientCertificates);
await m.createTable(siteCertificates);
}
if (from < 6) {
await m.createTable(firstStart);
}
},
);
@ -309,6 +323,28 @@ class MewsDatabase extends _$MewsDatabase {
await _removeTagsOf(TagKind.bookmark, url);
});
/// Gives a fresh install the project's directory of sites as a bookmark,
/// so the reader starts somewhere. It happens once: removing it is the
/// reader's, and later starts never bring it back.
Future<void> seedDirectoryBookmark(String url, String title) async {
await transaction(() async {
if (await directorySeeded()) return;
await addBookmark(url, title);
await into(firstStart).insert(
FirstStartCompanion.insert(
id: const Value(0),
directorySeeded: const Value(true),
),
mode: InsertMode.insertOrReplace);
});
}
/// Whether the directory bookmark has been given to this install.
Future<bool> directorySeeded() async {
final row = await (select(firstStart)..where((r) => r.id.equals(0))).getSingleOrNull();
return row?.directorySeeded ?? false;
}
// Subscriptions ---------------------------------------------------------
Future<void> addSubscription(String url, String? title, String? atomHref) =>