Skip to content

Commit

Permalink
chore: fix windows cookie invalid characters
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jul 5, 2024
1 parent f2f35bd commit 7dd76d2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
6 changes: 6 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ import 'package:timezone/data/latest.dart' as tz;
import 'package:window_manager/window_manager.dart';

Future<void> main(List<String> rawArgs) async {
WidgetsFlutterBinding.ensureInitialized();

if (runWebViewTitleBarWidget(rawArgs)) {
return;
}

final arguments = await startCLI(rawArgs);
AppLogger.initialize(arguments["verbose"]);

Expand Down
44 changes: 24 additions & 20 deletions lib/pages/settings/sections/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SettingsAccountSection extends HookConsumerWidget {
return;
}

final exp = RegExp(r"https:\/\/accounts.spotify.com\/.+\/status");
final applicationSupportDir = await getApplicationSupportDirectory();
final userDataFolder = Directory(
join(applicationSupportDir.path, "webview_window_Webview2"));
Expand All @@ -55,30 +56,33 @@ class SettingsAccountSection extends HookConsumerWidget {
}

final webview = await WebviewWindow.create(
configuration:
CreateConfiguration(userDataFolderWindows: userDataFolder.path),
configuration: CreateConfiguration(
title: "Spotify Login",
titleBarTopPadding: kIsMacOS ? 20 : 0,
windowHeight: 720,
windowWidth: 1280,
userDataFolderWindows: userDataFolder.path,
),
);
webview
..setBrightness(theme.colorScheme.brightness)
..launch("https://accounts.spotify.com/")
..setOnUrlRequestCallback((url) {
if (exp.hasMatch(url)) {
webview.getAllCookies().then((cookies) async {
final cookieHeader =
"sp_dc=${cookies.firstWhere((element) => element.name.contains("sp_dc")).value.replaceAll("\u0000", "")}";

webview.setOnUrlRequestCallback((url) {
final exp = RegExp(r"https:\/\/accounts.spotify.com\/.+\/status");
await authNotifier.login(cookieHeader);
webview.close();
if (context.mounted) {
context.go("/");
}
});
}

if (exp.hasMatch(url)) {
webview.getAllCookies().then((cookies) async {
final cookieHeader =
"sp_dc=${cookies.firstWhere((element) => element.name == "sp_dc").value}";

await authNotifier.login(cookieHeader);
webview.close();
if (context.mounted) {
context.go("/");
}
});
return true;
}
return false;
});

webview.launch("https://accounts.spotify.com/");
});
}

return SectionCardWithHeading(
Expand Down

0 comments on commit 7dd76d2

Please sign in to comment.