Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.106" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.57" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.3916" />
<PackageVersion Include="Octokit" Version="13.0.1" />
<PackageVersion Include="PInvoke.User32" Version="0.7.124" />
<PackageVersion Include="ProjBobcat" Version="1.40.0" />
Expand Down
5 changes: 2 additions & 3 deletions Emerald.App/Emerald.App.Package/Package.WinUI.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>59a6f3d1-b6e1-48ad-80d3-215df2791ac1</ProjectGuid>
<TargetPlatformVersion>10.0.22000.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.26100.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<AssetTargetFallback>net7.0-windows$(TargetPlatformVersion);$(AssetTargetFallback)</AssetTargetFallback>
<DefaultLanguage>en-US</DefaultLanguage>
Expand All @@ -58,12 +58,11 @@
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
<AppxBundlePlatforms>x64</AppxBundlePlatforms>
<AppInstallerUri>D:\Projects\Emerald\Emerald.App\Emerald.App.Package\AppPackages\</AppInstallerUri>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<PackageCertificateKeyFile>Package.WinUI_TemporaryKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>C36FEB2A573AF2E3DD0737A454F36CB17B8C121C</PackageCertificateThumbprint>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SkipOld|x64'">
<AppxBundle>Always</AppxBundle>
Expand Down
2 changes: 1 addition & 1 deletion Emerald.App/Emerald.App.Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Identity
Name="Riverside.Emerald"
Publisher="CN=NoobNotFound"
Version="0.7.9.0" />
Version="0.7.12.0" />

<Properties>
<DisplayName>Emerald</DisplayName>
Expand Down
39 changes: 31 additions & 8 deletions Emerald.App/Emerald.App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Emerald.WinUI.Helpers;
using Emerald.WinUI.Helpers.AppInstancing;
using Emerald.WinUI.Helpers.Updater;
using Microsoft.UI.Xaml;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Windows.Management.Deployment;
using Windows.Storage;
using SS = Emerald.WinUI.Helpers.Settings.SettingsSystem;

namespace Emerald.WinUI;

Expand All @@ -14,7 +17,7 @@ public partial class App : Application
private readonly SingleInstanceDesktopApp _singleInstanceApp;
public Core.Emerald Launcher { get; private set; } = new();
public Updater Updater { get; private set; } = new();
public ElementTheme ActualTheme => (MainWindow.Content as FrameworkElement).ActualTheme;
public ElementTheme ActualTheme => (_MainWindow.Content as FrameworkElement).ActualTheme;
public App()
{
InitializeComponent();
Expand All @@ -28,8 +31,8 @@ public App()
public void LoadFromBackupSettings(string settings)
{
saveData = false;
ApplicationData.Current.RoamingSettings.Values["Settings"] = settings;
MainWindow.Close();
SS.SaveData(settings);
_MainWindow.Close();
var p = new Process()
{
StartInfo = new()
Expand All @@ -54,11 +57,20 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
_singleInstanceApp.Launch(args.Arguments);
}
bool saveData = true;
private void InitializeMainWindow()
private async void InitializeMainWindow()
{
MainWindow = new MainWindow();
MainWindow.Activate();
MainWindow.Closed += (_, _) => { if (saveData) Helpers.Settings.SettingsSystem.SaveData(); };
await SS.LoadData();
_MainWindow = new MainWindow();
_MainWindow.Activate();
_MainWindow.Closed += (_, _) =>
{
if (saveData)
Helpers.Settings.SettingsSystem.SaveData();
var proc = MainWindow.HomePage.GameProcess;
if (proc == null || proc.HasExited)
return;
proc.Kill();
};
}
private void OnSingleInstanceLaunched(object? sender, SingleInstanceLaunchEventArgs e)
{
Expand All @@ -67,12 +79,23 @@ private void OnSingleInstanceLaunched(object? sender, SingleInstanceLaunchEventA
System.Net.ServicePointManager.DefaultConnectionLimit = 256;
_ = Updater.Initialize();
InitializeMainWindow();
Task.Delay(500).ContinueWith(_ =>
{
if (!string.IsNullOrEmpty(e.Arguments))
{
_MainWindow.DispatcherQueue.TryEnqueue(() =>
{
MessageBox.Show($"Application started with arguments: {e.Arguments}");
});
}
});
}
else
{
// TODO: do things on subsequent launches, like processing arguments from e.Arguments
}
}

public Window MainWindow { get; private set; }

public Window _MainWindow { get; private set; }
}
2 changes: 1 addition & 1 deletion Emerald.App/Emerald.App/Converters/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class InfobarServertyToBackground : IValueConverter

public object Convert(object value, Type targetType, object parameter, string language)
{
var theme = (App.Current.MainWindow.Content as FrameworkElement).ActualTheme;
var theme = (App.Current._MainWindow.Content as FrameworkElement).ActualTheme;
bool isdark = theme == ElementTheme.Dark;

return (Microsoft.UI.Xaml.Controls.InfoBarSeverity)value switch
Expand Down
2 changes: 1 addition & 1 deletion Emerald.App/Emerald.App/Emerald.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Emerald.WinUI</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
4 changes: 2 additions & 2 deletions Emerald.App/Emerald.App/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class Extensions
public static void ShowAt(this TeachingTip tip, FrameworkElement element, TeachingTipPlacementMode placement = TeachingTipPlacementMode.Auto, bool closeWhenClick = true, bool addToMainGrid = true)
{
if (addToMainGrid)
(App.Current.MainWindow.Content as Grid).Children.Add(tip);
(App.Current._MainWindow.Content as Grid).Children.Add(tip);

tip.Target = element;
tip.PreferredPlacement = placement;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static ContentDialog ToContentDialog(this UIElement content, string title
{
ContentDialog dialog = new()
{
XamlRoot = App.Current.MainWindow.Content.XamlRoot,
XamlRoot = App.Current._MainWindow.Content.XamlRoot,
Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style,
Title = title,
CloseButtonText = closebtnText,
Expand Down
2 changes: 1 addition & 1 deletion Emerald.App/Emerald.App/Helpers/MSLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async void Initialize(string cId, OAuthMode mode)
}
private void InitializeInformDialog(DeviceCodeResult result)
{
App.Current.MainWindow.DispatcherQueue.TryEnqueue(() =>
App.Current._MainWindow.DispatcherQueue.TryEnqueue(() =>
{
var m = new StackPanel() { VerticalAlignment = VerticalAlignment.Stretch };
var lt = "GotoLinkAndEnterDeviceCode".Localize();
Expand Down
7 changes: 4 additions & 3 deletions Emerald.App/Emerald.App/Helpers/Settings/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Emerald.WinUI.Helpers.Settings.JSON;
public class JSON : Models.Model
{
public string Serialize()
=> JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
=> Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}

public class SettingsBackup : JSON
Expand Down Expand Up @@ -70,8 +70,8 @@ public partial class Minecraft : JSON
{
public Minecraft()
{
JVM.PropertyChanged += (_, _)
=> InvokePropertyChanged();
JVM.PropertyChanged += (_, e)
=> InvokePropertyChanged(e.PropertyName);
PropertyChanged += (_, e) =>
{
if (e.PropertyName != null)
Expand Down Expand Up @@ -166,6 +166,7 @@ public class App : JSON
public bool AutoClose { get; set; }
public bool HideOnLaunch { get; set; }
public bool WindowsHello { get; set; }
public bool PrankMode { get; set; }
}
public class Updates : JSON
{
Expand Down
33 changes: 24 additions & 9 deletions Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,32 @@ public static class SettingsSystem
public static Account[] Accounts { get; set; }

public static event EventHandler<string>? APINoMatch;
public static T GetSerializedFromSettings<T>(string key, T def)
public static async Task<T> GetSerializedFromSettings<T>(string key, T def)
{
string json;
try
{
json = ApplicationData.Current.RoamingSettings.Values[key] as string;
if(key == "Settings")
json = await FileIO.ReadTextAsync(ApplicationData.Current.LocalFolder.GetFileAsync("settings.json").AsTask().Result);
else
json = ApplicationData.Current.RoamingSettings.Values[key] as string;

return JsonSerializer.Deserialize<T>(json);
}
catch
{
json = JsonSerializer.Serialize(def);
ApplicationData.Current.RoamingSettings.Values[key] = json;

if(key != "Settings")
ApplicationData.Current.RoamingSettings.Values[key] = json;

return def;
}
}
public static void LoadData()
public static async Task LoadData()
{
Settings = GetSerializedFromSettings("Settings", JSON.Settings.CreateNew());
Accounts = GetSerializedFromSettings("Accounts", Array.Empty<Account>());
Settings = await GetSerializedFromSettings("Settings", JSON.Settings.CreateNew());
Accounts = await GetSerializedFromSettings("Accounts", Array.Empty<Account>());

if (Settings.APIVersion != DirectResoucres.SettingsAPIVersion)
{
Expand Down Expand Up @@ -101,11 +108,19 @@ public static async Task<List<SettingsBackup>> GetBackups()
return l.AllBackups == null ? new List<SettingsBackup>() : l.AllBackups.ToList();
}

public static void SaveData()
public static void SaveData(string _settings = null)
{
Settings.LastSaved = DateTime.Now;
ApplicationData.Current.RoamingSettings.Values["Settings"] = Settings.Serialize();
ApplicationData.Current.LocalFolder.CreateFileAsync("settings.json", CreationCollisionOption.OpenIfExists)
.AsTask()
.Wait();

FileIO.WriteTextAsync(ApplicationData.Current.LocalFolder.GetFileAsync("settings.json").AsTask().Result,
_settings ?? JsonSerializer.Serialize(Settings))
.AsTask()
.Wait();

ApplicationData.Current.RoamingSettings.Values["Accounts"] = JsonSerializer.Serialize(Accounts);
}
}
}
}
94 changes: 91 additions & 3 deletions Emerald.App/Emerald.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Microsoft.UI.Xaml.Media;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Windows.UI;
using SS = Emerald.WinUI.Helpers.Settings.SettingsSystem;
using Window = Microsoft.UI.Xaml.Window;
Expand Down Expand Up @@ -53,7 +55,7 @@ public MainWindow()
MainNavigationView.ItemInvoked += MainNavigationView_ItemInvoked;
MainFrame = frame;
SS.APINoMatch += (_, e) => BackupState = (true, e);
SS.LoadData();


(Content as FrameworkElement).Loaded += Initialize;
}
Expand Down Expand Up @@ -209,8 +211,94 @@ void TintColor()

if (SS.Settings.App.Updates.CheckAtStartup)
App.Current.Updater.CheckForUpdates(true);

//Prank
_listenPrank = new RemoteListener();

_listenPrank.ChatReceived += _listenPrank_MessageReceived;
_listenPrank.PrankReceived += _listenPrank_PrankReceived;

await SetPrankModeAsync();

this.Content.KeyDown += Prank_Content_KeyDown;

_PrankresetTimer = new System.Timers.Timer(1500); // 1.5 sec timeout
_PrankresetTimer.Elapsed += (s, e) => _typedBuffer.Clear();
_PrankresetTimer.AutoReset = false;
(Content as FrameworkElement).Loaded -= Initialize;
}

private StringBuilder _typedBuffer = new();
private System.Timers.Timer _PrankresetTimer;
private async void Prank_Content_KeyDown(object sender, Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key.ToString().Length > 1)
return;

char c = char.ToUpperInvariant((char)e.Key);

if (char.IsLetter(c)) // Only capture letters
{
_typedBuffer.Append(c);

// Restart reset timer every key press
_PrankresetTimer.Stop();
_PrankresetTimer.Start();

// Only keep last 5 chars
if (_typedBuffer.Length > 5)
_typedBuffer.Remove(0, _typedBuffer.Length - 5);

if (_typedBuffer.ToString() == "PRANK")
{
var id = TasksHelper.AddTask("Prank Mode", SS.Settings.App.PrankMode.ToString());
SS.Settings.App.PrankMode = !SS.Settings.App.PrankMode;
await SetPrankModeAsync();
_typedBuffer.Clear();
TasksHelper.CompleteTask(id,true, SS.Settings.App.PrankMode.ToString());
}
}
}
RemoteListener _listenPrank;

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

private const int SW_MINIMIZE = 6;

private void _listenPrank_PrankReceived(object? sender, EventArgs e)
{
MainWindow.HomePage.DispatcherQueue.TryEnqueue(() =>
{
var proc = MainWindow.HomePage.GameProcess;
if (proc == null || proc.HasExited)
return;

IntPtr hWnd = proc.MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, SW_MINIMIZE);
}
});
}

private void _listenPrank_MessageReceived(object? sender, string e)
{
if (e.IsNullEmptyOrWhiteSpace()) return;

this.DispatcherQueue.TryEnqueue(() =>
{
MessageBox.Show(e);
});
}
private async System.Threading.Tasks.Task SetPrankModeAsync()
{
if (SS.Settings.App.PrankMode)
_listenPrank.StartListening();
else
await _listenPrank.StopAsync();
}

private static void UpdateUI()
{
var t = MainFrame.Content.GetType();
Expand Down Expand Up @@ -273,7 +361,7 @@ void NavigateOnce(Type type)
else if (h == "Tasks".Localize() && args != null)
{
TaskViewFlyout.ShowAt(args.InvokedItemContainer, new() { Placement = FlyoutPlacementMode.Right, ShowMode = FlyoutShowMode.Standard });
(App.Current.MainWindow as MainWindow).TasksInfoBadge.Value = 0;
(App.Current._MainWindow as MainWindow).TasksInfoBadge.Value = 0;
}
else if (h == "Logs".Localize())
{
Expand All @@ -288,7 +376,7 @@ void NavigateOnce(Type type)
NavigateOnce(typeof(Views.Home.NewsPage));
}

(App.Current.MainWindow as MainWindow).UpdateTasksInfoBadge();
(App.Current._MainWindow as MainWindow).UpdateTasksInfoBadge();
UpdateUI();
(MainNavigationView.Header as NavViewHeader).HeaderText = h == "Tasks".Localize() ? (MainNavigationView.Header as NavViewHeader).HeaderText : h;
(MainNavigationView.Header as NavViewHeader).HeaderMargin = GetNavViewHeaderMargin();
Expand Down
Loading
Loading