V2 Release

This commit is contained in:
Ujwal223
2026-05-25 22:12:38 +05:45
parent 2d33dcb889
commit 842dc70829
38 changed files with 642 additions and 334 deletions
+33 -1
View File
@@ -46,7 +46,39 @@ class ExtrasSettingsPage extends StatelessWidget {
HapticFeedback.selectionClick();
},
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.amber.withValues(alpha: 0.07),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.amber.withValues(alpha: 0.12)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 8, top: 2),
child: Icon(
Icons.info_outline,
size: 14,
color: Colors.amber,
),
),
const Expanded(
child: Text(
'NOTE: The seen indicator is not sent to the sender while you are active in the chat, but as soon as you close and reopen the chat, the seen indicator is sent.',
style: TextStyle(fontSize: 11, color: Colors.amber),
),
),
],
),
),
),
/* TRIED BUT IT DIDNT WORK 98% oF THE TIME)
const _SectionHeader(title: 'FOCUSGRAM V2'),
_SwitchTile(
title: 'Ad Blocker',
@@ -66,7 +98,7 @@ class ExtrasSettingsPage extends StatelessWidget {
HapticFeedback.selectionClick();
},
),
*/
const SizedBox(height: 40),
],
),
+123 -11
View File
@@ -27,7 +27,7 @@ import '../v2_integration/script_engine_v2_overlay.dart';
import '../v2_integration/script_registry_v2_overlay.dart';
import '../scripts/focus_scripts.dart';
import '../focus_settings.dart';
import 'package:http/http.dart' as http;
import '../services/adblock/adblock_content_blocker_loader.dart';
@@ -127,7 +127,10 @@ class _MainWebViewPageState extends State<MainWebViewPage>
// Check for updates on launch
context.read<UpdateCheckerService>().checkForUpdates();
unawaited(_loadAdblockerData());
// Load adblock data early. If adblock is enabled, we wait for initial data
// to be loaded so the WebView can apply contentBlockers on first render.
// This prevents ads from loading before filters are applied.
unawaited(_loadAdblockerDataEarly());
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<SessionManager>().addListener(_onSessionChanged);
@@ -155,6 +158,9 @@ class _MainWebViewPageState extends State<MainWebViewPage>
_lastV2AutoplayBlockerEnabled = settings.blockAutoplay;
_lastAdblockToggleValue = settings.v2AdBlockerDomEnabled;
_onScreenTimeChanged();
// Load full adblock data with longer timeout after UI is initialized
unawaited(_loadAdblockerData());
});
FocusGramRouter.pendingUrl.addListener(_onPendingUrlChanged);
@@ -581,6 +587,28 @@ class _MainWebViewPageState extends State<MainWebViewPage>
return data;
}
Future<void> _loadAdblockerDataEarly() async {
final settings = context.read<SettingsService>();
if (!settings.v2AdBlockerDomEnabled) return;
try {
final prefs = await SharedPreferences.getInstance();
final loader = AdblockContentBlockerLoader();
final data = await loader.loadOrUpdateIfNeeded(
enabled: true,
prefs: prefs,
timeoutMs: 5000, // Short timeout for early load
);
if (mounted) {
setState(() => _adblockData = data);
}
} catch (_) {
// If loading fails, continue without blocking app startup
// AdblockData will be retried in _loadAdblockerData()
}
}
bool _isBlockedByAdblockHostList(WebUri uri, Set<String>? blockedHosts) {
if (blockedHosts == null || blockedHosts.isEmpty) return false;
@@ -911,6 +939,24 @@ class _MainWebViewPageState extends State<MainWebViewPage>
pullToRefreshController: _pullToRefreshController,
shouldInterceptRequest: (controller, request) async {
final url = request.url.toString();
const adDomains = [
'an.facebook.com',
'connect.facebook.net',
'pixel.facebook.com',
'graph.facebook.com/logging',
'www.instagram.com/ajax/bz',
'www.instagram.com/api/v1/web/comet/logcalls',
'doubleclick.net',
'googletagmanager.com',
'scorecardresearch.com',
];
if (adDomains.any(url.contains)) {
return WebResourceResponse(
data: Uint8List(0),
);
}
final referrer =
request.headers?['Referer'] ??
request.headers?['referer'];
@@ -919,7 +965,7 @@ class _MainWebViewPageState extends State<MainWebViewPage>
_syncDirectThreadState(referrer);
}
if (_isInDirectThread &&
/*if (_isInDirectThread &&
_isFktmInstagramCdn(url)) {
if (_dmThreadCdnBlockArmed) {
return WebResourceResponse(
@@ -928,7 +974,7 @@ class _MainWebViewPageState extends State<MainWebViewPage>
}
_dmThreadCdnBlockArmed = true;
}
*/
// Strict/high-priority domain blocking from uBlock-style lists.
final adblockHosts = _adblockData?.blockedHosts;
if (_isBlockedByAdblockHostList(
@@ -983,11 +1029,11 @@ class _MainWebViewPageState extends State<MainWebViewPage>
);
}
// Strip ads from feed
/* Strip ads from feed (JS handles it)
if (settings.noAds &&
url.contains(
'instagram.com/graphql/query',
)) {
)) {/
try {
final res = await http.post(
Uri.parse(url),
@@ -1006,10 +1052,76 @@ class _MainWebViewPageState extends State<MainWebViewPage>
edges.removeWhere((e) {
final node = e['node'];
if (node == null) return false;
return node['ad'] != null ||
node['explore_story'] != null ||
node['media']?['inventory_source'] ==
'mixed_unconnected';
// Strip ads from feed
if (settings.noAds &&
url.contains(
'instagram.com/graphql',
)) {
try {
final res = await http.post(
Uri.parse(url),
headers: Map<String, String>.from(
request.headers ?? {},
),
);
final json = jsonDecode(res.body);
void filterEdges(dynamic obj) {
if (obj == null) return;
if (obj is Map) {
if (obj['edges'] is List) {
(obj['edges'] as List).removeWhere((
e,
) {
final node = e is Map
? e['node']
: null;
if (node == null ||
node is! Map)
return false;
return node['is_ad'] ==
true ||
node['ad_id'] != null ||
node['ad_action_links'] !=
null ||
node['is_paid_partnership'] ==
true ||
node['sponsor_tags'] !=
null ||
node['commerciality_status'] ==
'ad' ||
node['commerciality_status'] ==
'shoppable_feed_ad' ||
(node['__typename']
?.toString()
.toLowerCase()
.contains(
'ad',
) ??
false);
});
}
obj.values.forEach(filterEdges);
} else if (obj is List) {
obj.forEach(filterEdges);
}
}
filterEdges(json);
return WebResourceResponse(
data: Uint8List.fromList(
utf8.encode(jsonEncode(json)),
),
headers: res.headers,
statusCode: 200,
contentType: 'application/json',
);
} catch (_) {
return null;
}
}
});
}
@@ -1025,7 +1137,7 @@ class _MainWebViewPageState extends State<MainWebViewPage>
// if anything fails, pass through original request unmodified
return null;
}
}
}*/
return null;
},
+14 -42
View File
@@ -46,7 +46,7 @@ class SettingsPage extends StatelessWidget {
title: 'Focus Mode',
subtitle: settings.minimalModeEnabled
? 'Minimal mode on'
: 'Blocking, friction, media',
: 'Blocking, Content Hider, Feed Blur and more',
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const FocusSettingsPage()),
@@ -71,7 +71,7 @@ class SettingsPage extends StatelessWidget {
icon: Icons.download_rounded,
iconColor: Colors.orangeAccent,
title: 'Extras',
subtitle: 'Download media, Ghost Mode, Ad Blocker',
subtitle: 'Download media, Ghost Mode',
enabled: true,
onTap: () => Navigator.push(
context,
@@ -100,7 +100,7 @@ class SettingsPage extends StatelessWidget {
icon: Icons.lock_outline,
iconColor: Colors.tealAccent,
title: 'Privacy & Notifications',
subtitle: 'Session end alerts',
subtitle: 'Manage Your Notifications',
onTap: () => Navigator.push(
context,
MaterialPageRoute(
@@ -379,12 +379,16 @@ class FocusSettingsPage extends StatelessWidget {
),
const _SectionHeader(title: 'MEDIA'),
/*
( I TRIED SO HARD, AND GOT SO FAR, BUT IN THE END...
IT DOESNT EVEN MATTER ..... (didnt work))
_SwitchTile(
title: 'Block Autoplay Videos',
subtitle: 'Videos won\'t play until you tap them',
value: settings.blockAutoplay,
onChanged: (v) => settings.setBlockAutoplay(v),
),
),*/
_SwitchTile(
title: 'Blur Feed & Explore',
subtitle: 'Blurs post thumbnails until tapped',
@@ -403,48 +407,16 @@ class FocusSettingsPage extends StatelessWidget {
),
),
const _SectionHeader(title: 'FOCUSGRAM V2 OVERLAY'),
const _SectionHeader(title: 'CONTENT HIDER'),
_SwitchTile(
title: 'Content Hider',
subtitle: 'Hide stories tray, feed posts, reels, suggested content',
value: settings.v2ContentHiderEnabled,
onChanged: (v) => settings.setV2ContentHiderEnabled(v),
title: 'Hide Feed Posts',
subtitle:
'Hides home feed posts (stories tray, posts, suggested content)',
value: settings.contentPosts,
onChanged: (v) => settings.setContentPostsEnabled(v),
),
if (settings.v2ContentHiderEnabled)
Padding(
padding: const EdgeInsets.only(left: 32),
child: Column(
children: [
_SwitchTile(
title: 'Hide Stories Tray',
subtitle: 'Story bubbles row',
value: settings.contentStories,
onChanged: (v) => settings.setContentStoriesEnabled(v),
),
_SwitchTile(
title: 'Hide Feed Posts',
subtitle: 'Home feed posts',
value: settings.contentPosts,
onChanged: (v) => settings.setContentPostsEnabled(v),
),
_SwitchTile(
title: 'Hide Reels (Feed)',
subtitle: 'Reels shown in the feed',
value: settings.contentReels,
onChanged: (v) => settings.setContentReelsEnabled(v),
),
_SwitchTile(
title: 'Hide Suggested Content',
subtitle: 'Suggested posts and recommendation units',
value: settings.contentSuggested,
onChanged: (v) => settings.setContentSuggestedEnabled(v),
),
],
),
),
const SizedBox(height: 40),
],
),