@@ -41,13 +41,55 @@ class Accounts extends Table {
41
41
];
42
42
}
43
43
44
+ /// The visual theme of the app.
45
+ ///
46
+ /// See [zulipThemeData] for how themes are determined.
47
+ enum ThemeSetting {
48
+ /// Corresponds to the default platform setting.
49
+ none,
50
+
51
+ /// Corresponds to [Brightness.light] .
52
+ light,
53
+
54
+ /// Corresponds to [Brightness.dark] .
55
+ dark,
56
+ }
57
+
58
+ /// What browser the user has set to use for opening links in messages.
59
+ ///
60
+ /// See https://chat.zulip.org/#narrow/stream/48-mobile/topic/in-app.20browser
61
+ /// for the reasoning behind these options.
62
+ enum BrowserPreference {
63
+ /// Use [UrlLaunchMode.externalApplication] on iOS,
64
+ /// [UrlLaunchMode.platformDefault] on Android.
65
+ none,
66
+
67
+ /// Use the in-app browser.
68
+ embedded,
69
+
70
+ /// Use the user's default browser app.
71
+ external ,
72
+ }
73
+
74
+ /// The table of the user's chosen settings independent of account, on this
75
+ /// client.
76
+ ///
77
+ /// These apply across all the user's accounts on this client (i.e. on this
78
+ /// install of the app on this device).
79
+ @DataClassName ('GlobalSettingsData' )
80
+ class GlobalSettings extends Table {
81
+ Column <String > get themeSetting => textEnum <ThemeSetting >()();
82
+
83
+ Column <String > get browserPreference => textEnum <BrowserPreference >()();
84
+ }
85
+
44
86
class UriConverter extends TypeConverter <Uri , String > {
45
87
const UriConverter ();
46
88
@override String toSql (Uri value) => value.toString ();
47
89
@override Uri fromSql (String fromDb) => Uri .parse (fromDb);
48
90
}
49
91
50
- @DriftDatabase (tables: [Accounts ])
92
+ @DriftDatabase (tables: [Accounts , GlobalSettings ])
51
93
class AppDatabase extends _$AppDatabase {
52
94
AppDatabase (super .e);
53
95
@@ -58,7 +100,7 @@ class AppDatabase extends _$AppDatabase {
58
100
// * Write a migration in `onUpgrade` below.
59
101
// * Write tests.
60
102
@override
61
- int get schemaVersion => 2 ; // See note.
103
+ int get schemaVersion => 3 ; // See note.
62
104
63
105
@override
64
106
MigrationStrategy get migration {
@@ -84,6 +126,10 @@ class AppDatabase extends _$AppDatabase {
84
126
if (from < 2 && 2 <= to) {
85
127
await m.addColumn (accounts, accounts.ackedPushToken);
86
128
}
129
+
130
+ if (from < 3 && 3 <= to) {
131
+ await m.createTable (globalSettings);
132
+ }
87
133
// New migrations go here.
88
134
}
89
135
);
@@ -104,6 +150,20 @@ class AppDatabase extends _$AppDatabase {
104
150
rethrow ;
105
151
}
106
152
}
153
+
154
+ Future <GlobalSettingsData > ensureGlobalSettings () async {
155
+ final settings = await select (globalSettings).getSingleOrNull ();
156
+ // TODO(db): Enforce the singleton constraint more robustly.
157
+ if (settings != null ) {
158
+ return settings;
159
+ }
160
+
161
+ await into (globalSettings).insert (GlobalSettingsCompanion .insert (
162
+ themeSetting: ThemeSetting .none,
163
+ browserPreference: BrowserPreference .none,
164
+ ));
165
+ return select (globalSettings).getSingle ();
166
+ }
107
167
}
108
168
109
169
class AccountAlreadyExistsException implements Exception {}
0 commit comments