mirror of
https://github.com/Ujwal223/FocusGram.git
synced 2026-07-14 07:47:22 +02:00
improvement/;
bugfixes added word libraby (~500 words)
This commit is contained in:
@@ -94,9 +94,12 @@ class AboutPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future<void> _launchURL(String url) async {
|
||||
final uri = Uri.parse(url);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri == null) return;
|
||||
try {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} catch (_) {
|
||||
// Ignore if cannot launch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,6 +209,12 @@ class _FrictionSliderTileState extends State<_FrictionSliderTile> {
|
||||
_draftValue = widget.value;
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(_FrictionSliderTile old) {
|
||||
super.didUpdateWidget(old);
|
||||
if (!_pendingConfirm) _draftValue = widget.value;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final divisions = ((widget.max - widget.min) / widget.divisor).round();
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import '../services/session_manager.dart';
|
||||
import '../services/settings_service.dart';
|
||||
@@ -29,6 +30,7 @@ class _MainWebViewPageState extends State<MainWebViewPage>
|
||||
// Watchdog for app-session expiry
|
||||
Timer? _watchdog;
|
||||
bool _extensionDialogShown = false;
|
||||
bool _lastSessionActive = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -36,12 +38,28 @@ class _MainWebViewPageState extends State<MainWebViewPage>
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_initWebView();
|
||||
_startWatchdog();
|
||||
|
||||
// Listen to session changes to update JS context immediately
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<SessionManager>().addListener(_onSessionChanged);
|
||||
_lastSessionActive = context.read<SessionManager>().isSessionActive;
|
||||
});
|
||||
}
|
||||
|
||||
void _onSessionChanged() {
|
||||
if (!mounted) return;
|
||||
final sm = context.read<SessionManager>();
|
||||
if (_lastSessionActive != sm.isSessionActive) {
|
||||
_lastSessionActive = sm.isSessionActive;
|
||||
_applyInjections();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_watchdog?.cancel();
|
||||
context.read<SessionManager>().removeListener(_onSessionChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -154,6 +172,15 @@ class _MainWebViewPageState extends State<MainWebViewPage>
|
||||
);
|
||||
},
|
||||
onNavigationRequest: (request) {
|
||||
// Handle external links (non-Instagram/Facebook)
|
||||
final uri = Uri.tryParse(request.url);
|
||||
if (uri != null &&
|
||||
!uri.host.contains('instagram.com') &&
|
||||
!uri.host.contains('facebook.com')) {
|
||||
launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
return NavigationDecision.prevent;
|
||||
}
|
||||
|
||||
final decision = NavigationGuard.evaluate(url: request.url);
|
||||
|
||||
if (decision.blocked) {
|
||||
@@ -255,7 +282,11 @@ class _MainWebViewPageState extends State<MainWebViewPage>
|
||||
await _navigateTo('/explore/');
|
||||
break;
|
||||
case 2:
|
||||
_openSessionModal();
|
||||
if (context.read<SessionManager>().isSessionActive) {
|
||||
await _navigateTo('/reels/');
|
||||
} else {
|
||||
_openSessionModal();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
await _navigateTo('/direct/inbox/');
|
||||
@@ -393,11 +424,21 @@ class _EdgePanelState extends State<_EdgePanel> {
|
||||
// Hits will pass through the Stack to the WebView except on our children.
|
||||
return Stack(
|
||||
children: [
|
||||
// ── Tap-to-close Backdrop (only when expanded) ──
|
||||
if (_isExpanded)
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onTap: _toggleExpansion,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(color: Colors.black.withValues(alpha: 0.15)),
|
||||
),
|
||||
),
|
||||
|
||||
// ── The Handle (Minimized State) ──
|
||||
if (!_isExpanded)
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: MediaQuery.of(context).size.height * 0.35,
|
||||
top: MediaQuery.of(context).size.height * 0.35 + 30, // Added margin
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Column(
|
||||
@@ -480,7 +521,7 @@ class _EdgePanelState extends State<_EdgePanel> {
|
||||
duration: const Duration(milliseconds: 350),
|
||||
curve: Curves.easeOutQuart,
|
||||
left: _isExpanded ? 0 : -220,
|
||||
top: MediaQuery.of(context).size.height * 0.25,
|
||||
top: MediaQuery.of(context).size.height * 0.25 + 30, // Added margin
|
||||
child: GestureDetector(
|
||||
onHorizontalDragUpdate: (details) {
|
||||
if (details.delta.dx < -10) _toggleExpansion();
|
||||
|
||||
@@ -10,7 +10,7 @@ class SettingsPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = context.watch<SettingsService>();
|
||||
// Watching services ensures the UI rebuilds when settings or session state change.
|
||||
final sm = context.watch<SessionManager>();
|
||||
|
||||
return Scaffold(
|
||||
@@ -45,7 +45,7 @@ class SettingsPage extends StatelessWidget {
|
||||
title: 'Distraction Management',
|
||||
subtitle: 'Blur explore and reel controls',
|
||||
icon: Icons.visibility_off_outlined,
|
||||
destination: _DistractionSettingsPage(settings: settings),
|
||||
destination: const _DistractionSettingsPage(),
|
||||
),
|
||||
_buildSettingsTile(
|
||||
context: context,
|
||||
@@ -149,11 +149,11 @@ class SettingsPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _DistractionSettingsPage extends StatelessWidget {
|
||||
final SettingsService settings;
|
||||
const _DistractionSettingsPage({required this.settings});
|
||||
const _DistractionSettingsPage();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settings = context.watch<SettingsService>();
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
|
||||
Reference in New Issue
Block a user