Serve Google calendar app config from Jarvis
This commit is contained in:
@@ -351,6 +351,7 @@ class _HomeShellState extends State<HomeShell> {
|
||||
connections: widget.googleConnections,
|
||||
cachedEvents: widget.syncedEvents,
|
||||
people: widget.people,
|
||||
jarvisSettings: widget.jarvisSettings,
|
||||
onChanged: widget.onGoogleConnectionsChanged,
|
||||
onSyncedEventsChanged: widget.onSyncedEventsChanged,
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@ class AccountsPage extends StatefulWidget {
|
||||
required this.connections,
|
||||
required this.cachedEvents,
|
||||
required this.people,
|
||||
required this.jarvisSettings,
|
||||
required this.onChanged,
|
||||
required this.onSyncedEventsChanged,
|
||||
});
|
||||
@@ -13,6 +14,7 @@ class AccountsPage extends StatefulWidget {
|
||||
final List<GoogleCalendarConnection> connections;
|
||||
final List<CalendarEvent> cachedEvents;
|
||||
final List<Person> people;
|
||||
final JarvisSettings jarvisSettings;
|
||||
final ValueChanged<List<GoogleCalendarConnection>> onChanged;
|
||||
final ValueChanged<List<CalendarEvent>> onSyncedEventsChanged;
|
||||
|
||||
@@ -28,6 +30,7 @@ class _AccountsPageState extends State<AccountsPage> {
|
||||
final googleSignIn = GoogleSignIn.instance;
|
||||
List<GoogleCalendarInfo> googleCalendars = [];
|
||||
GoogleSignInAccount? signedInAccount;
|
||||
String runtimeServerClientId = googleCalendarServerClientId;
|
||||
bool initialized = false;
|
||||
bool loadingCalendars = false;
|
||||
bool syncing = false;
|
||||
@@ -36,17 +39,62 @@ class _AccountsPageState extends State<AccountsPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (googleCalendarServerClientId.trim().isEmpty) {
|
||||
statusMessage =
|
||||
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve ebbe az appverzi\u00f3ba. A csal\u00e1dtagoknak nem kell client ID-t megadniuk; ezt egyszer, fejleszt\u0151i be\u00e1ll\u00edt\u00e1sk\u00e9nt kell az apphoz rendelni.';
|
||||
} else {
|
||||
_initializeGoogle();
|
||||
}
|
||||
_loadGoogleAppConfigAndInitialize();
|
||||
}
|
||||
|
||||
GoogleCalendarConnection? get connection =>
|
||||
widget.connections.isEmpty ? null : widget.connections.first;
|
||||
|
||||
Future<void> _loadGoogleAppConfigAndInitialize() async {
|
||||
setState(() {
|
||||
loadingCalendars = true;
|
||||
statusMessage = 'Google napt\u00e1rkapcsolat el\u0151k\u00e9sz\u00edt\u00e9se...';
|
||||
});
|
||||
|
||||
final configuredClientId = await _loadGoogleServerClientId();
|
||||
if (!mounted) return;
|
||||
if (configuredClientId == null || configuredClientId.trim().isEmpty) {
|
||||
setState(() {
|
||||
loadingCalendars = false;
|
||||
statusMessage =
|
||||
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve. A csal\u00e1dtagoknak nem kell client ID-t megadniuk; a JARVIS admin fel\u00fcleten kell egyszer be\u00e1ll\u00edtani a Google Calendar OAuth azonos\u00edt\u00f3t.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
runtimeServerClientId = configuredClientId.trim();
|
||||
await _initializeGoogle();
|
||||
}
|
||||
|
||||
Future<String?> _loadGoogleServerClientId() async {
|
||||
if (googleCalendarServerClientId.trim().isNotEmpty) {
|
||||
return googleCalendarServerClientId.trim();
|
||||
}
|
||||
|
||||
final apiToken = widget.jarvisSettings.apiToken.trim();
|
||||
if (apiToken.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
final baseUri = Uri.parse(normalizeJarvisUrl(widget.jarvisSettings.apiUrl));
|
||||
final uri = baseUri.replace(path: '/api/app-config', query: '');
|
||||
final response = await http
|
||||
.get(uri, headers: {'X-Otthon-Token': apiToken})
|
||||
.timeout(const Duration(seconds: 10));
|
||||
if (response.statusCode != 200) {
|
||||
return null;
|
||||
}
|
||||
final payload = jsonDecode(response.body);
|
||||
if (payload is! Map<String, dynamic>) {
|
||||
return null;
|
||||
}
|
||||
return payload['googleCalendarServerClientId'] as String?;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initializeGoogle() async {
|
||||
setState(() {
|
||||
loadingCalendars = true;
|
||||
@@ -121,10 +169,10 @@ class _AccountsPageState extends State<AccountsPage> {
|
||||
}
|
||||
|
||||
Future<void> _ensureGoogleInitialized() async {
|
||||
final clientId = googleCalendarServerClientId.trim();
|
||||
final clientId = runtimeServerClientId.trim();
|
||||
if (clientId.isEmpty) {
|
||||
throw Exception(
|
||||
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve ebbe az appverzi\u00f3ba.',
|
||||
'A Google napt\u00e1rkapcsolat m\u00e9g nincs bek\u00f6tve.',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user