Skip to content

Commit

Permalink
feat: qr code login, feat: add new scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
not-nullptr committed Sep 18, 2024
1 parent cb80ffe commit 0b5be69
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 40 deletions.
8 changes: 8 additions & 0 deletions Aerochat/Aerochat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@
<None Remove="Scenes\0006.png" />
<None Remove="Scenes\0007.png" />
<None Remove="Scenes\0008.png" />
<None Remove="Scenes\BetaFish.png" />
<None Remove="Scenes\ButterflyPattern.png" />
<None Remove="Scenes\CarbonFiber.jpg" />
<None Remove="Scenes\CarbonFiber.png" />
<None Remove="Scenes\default.png" />
<None Remove="Scenes\DottieGreen.png" />
<None Remove="Scenes\Floral.png" />
<None Remove="Scenes\Graffiti.jpg" />
<None Remove="Scenes\Graffiti.png" />
<None Remove="Scenes\Halo.png" />
<None Remove="Scenes\HelloKitty.png" />
<None Remove="Scenes\MesmerizingWhite.png" />
<None Remove="Scenes\Morty.png" />
<None Remove="Scenes\Robot.jpg" />
Expand Down Expand Up @@ -298,10 +302,14 @@
<Resource Include="Scenes\0006.png" />
<Resource Include="Scenes\0007.png" />
<Resource Include="Scenes\0008.png" />
<Resource Include="Scenes\BetaFish.png" />
<Resource Include="Scenes\ButterflyPattern.png" />
<Resource Include="Scenes\CarbonFiber.png" />
<Resource Include="Scenes\DottieGreen.png" />
<Resource Include="Scenes\Floral.png" />
<Resource Include="Scenes\Graffiti.png" />
<Resource Include="Scenes\Halo.png" />
<Resource Include="Scenes\HelloKitty.png" />
<Resource Include="Scenes\MesmerizingWhite.png" />
<Resource Include="Scenes\Morty.png" />
<Resource Include="Scenes\Robot.png" />
Expand Down
21 changes: 18 additions & 3 deletions Aerochat/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ public App()
// no token saved - that's fine, continue. we'll catch this case later
}
bool tokenFound = encryptedToken != null && encryptedToken.Length > 0;
string token = "";
if (tokenFound)
{
token = Encoding.UTF8.GetString(ProtectedData.Unprotect(encryptedToken, null, DataProtectionScope.CurrentUser));
}
try
{
Discord.Client = new(new()
{
TokenType = TokenType.User,
Token = tokenFound ? Encoding.UTF8.GetString(ProtectedData.Unprotect(encryptedToken, null, DataProtectionScope.CurrentUser)) : "",
Token = tokenFound ? token : "",
});
} catch (CryptographicException)
{
Expand All @@ -115,8 +120,18 @@ public App()

if (tokenFound)
{
string token = Encoding.UTF8.GetString(ProtectedData.Unprotect(encryptedToken, null, DataProtectionScope.CurrentUser));
BeginLogin(token);
Task.Run(async () =>
{
bool success = await BeginLogin(token);
if (!success)
{
Dispatcher.Invoke(() =>
{
LoginWindow = new(true);
LoginWindow.Show();
});
}
});
} else
{
// token doesn't exist - user hasn't saved it. show the login window
Expand Down
Binary file added Aerochat/Scenes/BetaFish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Aerochat/Scenes/Floral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Aerochat/Scenes/Halo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Aerochat/Scenes/HelloKitty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Aerochat/Scenes/Scenes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
<item id="21" mimetype="image/png" contenttype="D" file="0008.png" default="false" displayname="Mesmerizing Brown" color="#614040" />
<item id="22" mimetype="image/png" contenttype="D" file="zune_03.png" default="false" displayname="zune_03" color="#832727" />
<item id="23" mimetype="image/png" contenttype="D" file="ButterflyPattern.png" default="false" displayname="Butterfly Pattern" color="#575757" />
<item id="24" mimetype="image/png" contenttype="D" file="BetaFish.png" default="false" displayname="Beta Fish" color="#24b3ce" />
<item id="25" mimetype="image/png" contenttype="D" file="Halo.png" default="false" displayname="Halo" color="#a13d12" />
<item id="26" mimetype="image/png" contenttype="D" file="Floral.png" default="false" displayname="Floral" color="#f9aed4" />
<item id="27" mimetype="image/png" contenttype="D" file="HelloKitty.png" default="false" displayname="Hello Kitty" color="#f4a1cb" />
</package>
2 changes: 1 addition & 1 deletion Aerochat/Windows/DiscordLoginWV2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Aerochat.Windows"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
Title=".NET Passport Log-on" Height="450" Width="800">
Title=".NET Passport Log-on" Height="500" Width="850">
<Grid>
<wv2:WebView2 x:Name="LoginWebView" />
</Grid>
Expand Down
46 changes: 14 additions & 32 deletions Aerochat/Windows/DiscordLoginWV2.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,24 @@ public async void OnLoad()
LoginWebView.Source = new Uri("https://discord.com/login");
// inject js alert("Hello, World!");
string script = @"
function onRes(res) {
if (res.captcha_key?.includes(""captcha-required"")) return;
if (!res.token) return;
window.chrome.webview.postMessage(res.token);
function onUrlChange() {
window.chrome.webview.postMessage((webpackChunkdiscord_app.push([[''], {}, e => { m = []; for (let c in e.c) m.push(e.c[c]) }]), m).find(m => m?.exports?.default?.getToken !== void 0).exports.default.getToken());
}
(function (send) {
XMLHttpRequest.prototype.send = function (data) {
console.log('Request', this);
const pushState = history.pushState;
history.pushState = function () {
pushState.apply(history, arguments);
onUrlChange();
};
const url = new URL(this.__sentry_xhr_v3__.url);
if (url.pathname === ""/api/v9/auth/login"" || url.pathname === ""/api/v9/auth/mfa/totp"") {
if (this.responseText) {
onRes(JSON.parse(this.responseText));
} else {
this.addEventListener(""readystatechange"", function () {
onRes(JSON.parse(this.responseText));
});
}
}
send.call(this, data);
};
})(XMLHttpRequest.prototype.send);
function clearStorage() {
localStorage.clear();
sessionStorage.clear();
// all cookies
document.cookie.split(';').forEach(function(c) {
document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
});
}
clearStorage();
const replaceState = history.replaceState;
history.replaceState = function () {
replaceState.apply(history, arguments);
onUrlChange();
};
window.addEventListener('popstate', onUrlChange);
window.addEventListener('hashchange', onUrlChange);
";
await coreWebView.ExecuteScriptAsync(script);
}
Expand Down
18 changes: 14 additions & 4 deletions Aerochat/Windows/Login.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@ namespace Aerochat.Windows
public partial class Login : Window
{
public LoginWindowViewModel ViewModel { get; set; } = new LoginWindowViewModel();
public Login()
public Login(bool alreadyErrored = false)
{
InitializeComponent();
DataContext = ViewModel;
ViewModel.Scene = ThemeService.Instance.Scenes.FirstOrDefault(x => x.Default);
if (alreadyErrored)
{
Show();
ShowErrorDialog();
}
}

private void ShowErrorDialog()
{
var dialog = new Dialog("We can't sign you in to Windows Live Messenger", "The Windows Live Messenger token you entered is incorrect.", SystemIcons.Information);
dialog.Owner = this;
dialog.ShowDialog();
}

private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
Expand Down Expand Up @@ -101,9 +113,7 @@ private async void SignIn_Click(object sender, RoutedEventArgs e)
if (!success)
{
ViewModel.NotLoggingIn = true;
var dialog = new Dialog("We can't sign you in to Windows Live Messenger", "The Windows Live Messenger token you entered is incorrect.", SystemIcons.Information);
dialog.Owner = this;
dialog.ShowDialog();
ShowErrorDialog();
}
}

Expand Down

0 comments on commit 0b5be69

Please sign in to comment.