Skip to content

Commit 02e555d

Browse files
committed
fix: somewhat fix discord login
1 parent 12f2ade commit 02e555d

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

lib/Api/Discord/Login.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ class MobileLoginState extends State<MobileLogin> {
1818
late InAppWebViewController _controller;
1919

2020
Future<void> _extractToken() async {
21+
if (!mounted) return;
2122
await Future.delayed(const Duration(seconds: 2));
2223
try {
2324
final result = await _controller.evaluateJavascript(source: '''
24-
(function() {
25-
const m = []; webpackChunkdiscord_app.push([[""], {}, e => {for (let c in e.c)m.push(e.c[c])}]);
26-
return m.find(n => n?.exports?.default?.getToken !== void 0)?.exports?.default?.getToken();
27-
})()''');
25+
(function() {
26+
return window.LOCAL_STORAGE.getItem('token');
27+
})()
28+
''');
2829

2930
if (result != null && result != 'null') {
3031
_login(result.trim().replaceAll('"', ''));
@@ -53,12 +54,20 @@ class MobileLoginState extends State<MobileLogin> {
5354
javaScriptEnabled: true,
5455
),
5556
),
57+
onLoadStart: (controller, url) async {
58+
await controller.evaluateJavascript(source: '''
59+
try {
60+
window.LOCAL_STORAGE = localStorage;
61+
} catch (e) {}
62+
''');
63+
},
5664
onWebViewCreated: (controller) {
5765
_controller = controller;
5866
_clearDiscordData();
5967
},
6068
onUpdateVisitedHistory: (controller, url, isReload) async {
61-
if (url.toString() != 'https://discord.com/login') {
69+
if (url.toString() != 'https://discord.com/login' &&
70+
url.toString() != 'about:blank') {
6271
await _extractToken();
6372
}
6473
},
@@ -75,7 +84,7 @@ class MobileLoginState extends State<MobileLogin> {
7584
Future<void> _clearDiscordData() async {
7685
await _controller.evaluateJavascript(source: '''
7786
if (window.location.hostname === 'discord.com') {
78-
window.localStorage.clear();
87+
window.LOCAL_STORAGE.clear();
7988
window.sessionStorage.clear();
8089
}
8190
''');
@@ -118,6 +127,10 @@ class LinuxLoginState extends State<LinuxLogin> {
118127
..setBrightness(Brightness.dark)
119128
..launch('https://discord.com/login');
120129

130+
await Future.delayed(const Duration(milliseconds: 1000));
131+
132+
await _controller.evaluateJavaScript('''window.LOCAL_STORAGE = window.localStorage;
133+
Object.keys(window.localStorage);''');
121134
_controller.addOnUrlRequestCallback(
122135
(String url) async {
123136
if (url != 'https://discord.com/login' && url != 'about:blank') {
@@ -129,11 +142,12 @@ class LinuxLoginState extends State<LinuxLogin> {
129142

130143
Future<void> _extractToken() async {
131144
try {
145+
132146
final result = await _controller.evaluateJavaScript('''
133-
(function() {
134-
const m = []; webpackChunkdiscord_app.push([[""], {}, e => {for (let c in e.c)m.push(e.c[c])}]);
135-
return m.find(n => n?.exports?.default?.getToken !== void 0)?.exports?.default?.getToken();
136-
})()''');
147+
(function() {
148+
return window.LOCAL_STORAGE.getItem('token');
149+
})()
150+
''');
137151

138152
if (result != null && result != 'null') {
139153
_login(result.trim().replaceAll('"', ''));

lib/Functions/Function.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Future<void> snackString(
8080
}) async {
8181
var context = c ?? Get.context;
8282
Logger.log('Showing SnackBar with message: $s');
83+
debugPrint('Showing SnackBar with message: $s');
8384
if (context != null && s != null && s.isNotEmpty) {
8485
var theme = Theme.of(context).colorScheme;
8586
try {

lib/Screens/Home/HomeScreen.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,23 @@ class HomeScreenState extends State<HomeScreen> {
104104
children: [
105105
SizedBox(
106106
height: backgroundHeight,
107-
child: Obx(
108-
() {
107+
child: AnimatedSwitcher(
108+
duration: const Duration(milliseconds: 500),
109+
switchInCurve: Curves.easeInOut,
110+
switchOutCurve: Curves.easeInOut,
111+
transitionBuilder: (Widget child, Animation<double> animation) {
112+
return FadeTransition(
113+
opacity: animation,
114+
child: SlideTransition(
115+
position: Tween<Offset>(
116+
begin: const Offset(0.0, 0.05),
117+
end: Offset.zero,
118+
).animate(animation),
119+
child: child,
120+
),
121+
);
122+
},
123+
child: Obx(() {
109124
if (!service.running.value) {
110125
return const LoadingWidget();
111126
}
@@ -118,8 +133,9 @@ class HomeScreenState extends State<HomeScreen> {
118133
_buildCards(service, data),
119134
],
120135
);
121-
},
136+
}),
122137
),
138+
123139
),
124140
],
125141
);

lib/Screens/Home/Widgets/LoadingWidget.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ class LoadingWidget extends StatelessWidget {
2222
child: const LinearProgressIndicator(),
2323
),
2424
Positioned(
25-
right: 34,
26-
top: 36.statusBar(),
27-
child: GestureDetector(
28-
child: const SettingIconWidget(icon: Icons.settings),
29-
onTap: () =>
30-
showCustomBottomDialog(context, const SettingsBottomSheet()),
31-
)),
25+
right: 34,
26+
top: 36.statusBar(),
27+
child: GestureDetector(
28+
child: const SettingIconWidget(icon: Icons.settings),
29+
onTap: () =>
30+
showCustomBottomDialog(context, const SettingsBottomSheet()),
31+
),
32+
),
3233
],
3334
);
3435
}

lib/Screens/Settings/SettingsAccountScreen.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class SettingsAccountScreenState extends BaseSettingsScreen {
8282
..show(),
8383
onLogIn: () => Simkl.login(context),
8484
),
85-
const SizedBox(height: 16),
8685
_buildAccountSection(
8786
context,
8887
iconPath: 'assets/svg/discord.svg',

0 commit comments

Comments
 (0)