Skip to content

Commit

Permalink
Add Toast Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
qubqub committed Oct 26, 2023
1 parent e7b24ef commit 65f4e14
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 21 deletions.
11 changes: 7 additions & 4 deletions Entities/LogFileWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Enums;
using System.IO;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -474,9 +475,12 @@ private void SetCountryCodeByIP(string ip) {
string alpha2Code = countryInfo.Split(';')[0].ToLower();
Stats.LastCountryAlpha2Code = alpha2Code;
if (this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(alpha2Code)) {
this.StatsForm.ShowNotification(Multilingual.GetWord("message_connected_to_server_caption"),
$"{Multilingual.GetWord("message_connected_to_server_prefix")} {Multilingual.GetCountryName(alpha2Code)}, {countryInfo.Split(';')[1]} {Multilingual.GetWord("message_connected_to_server_suffix")}",
System.Windows.Forms.ToolTipIcon.Info, 2000);
// this.StatsForm.ShowNotification(Multilingual.GetWord("message_connected_to_server_caption"),
// $"{Multilingual.GetWord("message_connected_to_server_prefix")} {Multilingual.GetCountryName(alpha2Code)}, {countryInfo.Split(';')[1]} {Multilingual.GetWord("message_connected_to_server_suffix")}",
// System.Windows.Forms.ToolTipIcon.Info, 2000);
this.StatsForm.ShowToastNotification(Multilingual.GetWord("message_connected_to_server_caption"),
$"{Multilingual.GetWord("message_connected_to_server_prefix")}{Multilingual.GetCountryName(alpha2Code)}{(countryInfo.Split(';').Length > 1 ? $", {countryInfo.Split(';')[1]}" : "")}{Multilingual.GetWord("message_connected_to_server_suffix")}",
Position.BottomRight, Duration.LENGTH_LONG, Animation.FADE, this.StatsForm.Theme == MetroFramework.MetroThemeStyle.Light ? Theme.SuccessLight : Theme.SuccessDark, false);
}
} catch {
this.toggleCountryInfoApi = false;
Expand Down Expand Up @@ -582,7 +586,6 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
if (!this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId) && (DateTime.UtcNow - Stats.ConnectedToServerDate).TotalMinutes <= 40) {
this.gameStateWatcher.Start();
}
Console.WriteLine($"{this.sessionId} / {this.selectedShowId} / {!this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId)}");
this.StatsForm.UpsertServerConnectionLog(this.sessionId, this.selectedShowId, Stats.LastServerIp, Stats.ConnectedToServerDate);
}

Expand Down
Binary file added EunmaToast.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions FallGuysStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<AllowedReferenceRelatedFileExtensions>.allowedextension</AllowedReferenceRelatedFileExtensions>
<Prefer32bit>false</Prefer32bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DebugType>embedded</DebugType>
Expand All @@ -72,6 +73,9 @@
<Prefer32bit>false</Prefer32bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="EunmaToast">
<HintPath>.\EunmaToast.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down Expand Up @@ -263,6 +267,7 @@
<None Include="Resources\fallguys_icon.png" />
<None Include="Resources\fallguys_db_logo.png" />
<None Include="Resources\main_icon.png" />
<None Include="Resources\main_120_icon.png" />
<None Include="Resources\fandom_icon.png" />
<None Include="Resources\reddit_icon.png" />
<None Include="Resources\roll_off_club_icon.png" />
Expand Down
10 changes: 10 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<data name="main_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\main_icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="main_120_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\main_120_icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fandom_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fandom_icon.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added Resources/main_120_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 40 additions & 17 deletions Views/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Enums;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -17,6 +18,7 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.UI.Widget;
using System.Windows.Forms;
using LiteDB;
using Microsoft.Win32;
Expand Down Expand Up @@ -403,7 +405,7 @@ public static string ComputeHash(byte[] input, HashTypes hashType) {
// return destinationArray;
// }

private Stats() {
private Stats() {
Task.Run(() => {
if (this.IsInternetConnected()) {
HostCountryCode = this.GetIpToCountryCode(this.GetUserPublicIp()).Split(';')[0];
Expand Down Expand Up @@ -438,21 +440,6 @@ private Stats() {

this.InitializeComponent();

this.infoStrip.Renderer = new CustomToolStripSystemRenderer();
this.infoStrip2.Renderer = new CustomToolStripSystemRenderer();
DwmSetWindowAttribute(this.menu.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuFilters.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuStatsFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuPartyFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuProfile.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuLookHere.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayCMenu.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayFilters.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayStatsFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayPartyFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayProfile.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayLookHere.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));

#if !AllowUpdate
this.menu.Items.Remove(this.menuUpdate);
this.trayCMenu.Items.Remove(this.trayUpdate);
Expand Down Expand Up @@ -572,6 +559,21 @@ private Stats() {
this.SaveUserSettings();

this.SetTheme(CurrentTheme);

this.infoStrip.Renderer = new CustomToolStripSystemRenderer();
this.infoStrip2.Renderer = new CustomToolStripSystemRenderer();
DwmSetWindowAttribute(this.menu.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuFilters.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuStatsFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuPartyFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuProfile.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.menuLookHere.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayCMenu.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayFilters.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayStatsFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayPartyFilter.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayProfile.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
DwmSetWindowAttribute(this.trayLookHere.DropDown.Handle, DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, ref windowConerPreference, sizeof(uint));
}

[DllImport("User32.dll")]
Expand Down Expand Up @@ -3788,6 +3790,21 @@ private void UpdateTotals() {
MetroMessageBox.Show(this, ex.ToString(), $"{Multilingual.GetWord("message_program_error_caption")}", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public void ShowToastNotification(string caption, string description, Position position, Duration duration, Animation animation, Theme theme, bool muting) {
Toast toast = new ToastBuilder(this)
.SetThumbnail(Properties.Resources.main_120_icon)
.SetCaption(caption)
.SetDescription(description)
.SetDuration(duration)
.SetAnimation(animation)
.SetCloseStyle(CloseStyle.ButtonAndClickEntire)
.SetPosition(position)
.SetTheme(theme)
.SetMuting(muting)
.Build();
toast.ShowAsync();
}
public void ShowNotification(string title, string text, ToolTipIcon toolTipIcon, int timeout) {
if (this.trayIcon.Visible) {
this.trayIcon.BalloonTipTitle = title;
Expand Down Expand Up @@ -4791,7 +4808,6 @@ public string GetIpToCountryCode(string ip) {
if (!string.IsNullOrEmpty(ip)) {
try {
// countryCode = this.GetCountryCodeUsingIp2c(ip)[0]; // alpha-2 code

if (string.IsNullOrEmpty(countryCode)) {
rtnValue = this.GetCountryCodeUsingIpapi(ip);
countryCode = $"{rtnValue[0]};{rtnValue[1]}"; // alpha-2 code ; region
Expand All @@ -4806,6 +4822,10 @@ public string GetIpToCountryCode(string ip) {
rtnValue = this.GetCountryCodeUsingNordvpn(ip);
countryCode = $"{rtnValue[0]};{rtnValue[1]}"; // alpha-2 code ; region
}

if (string.IsNullOrEmpty(countryCode)) {
countryCode = this.GetCountryCodeUsingIp2c(ip)[0]; // alpha-2 code
}
} catch {
return string.Empty;
}
Expand Down Expand Up @@ -5800,6 +5820,9 @@ private async void menuSettings_Click(object sender, EventArgs e) {
}
}
private void menuOverlay_Click(object sender, EventArgs e) {
this.ShowToastNotification("서버 연결 알림",
"(미국, New York) 서버에 연결되었습니다.",
Position.BottomRight, System.Enums.Duration.LENGTH_LONG, Animation.FADE, this.Theme == MetroThemeStyle.Light ? System.Enums.Theme.SuccessLight : System.Enums.Theme.SuccessDark, false);
this.ToggleOverlay(this.overlay);
}
public void ToggleOverlay(Overlay overlay) {
Expand Down

0 comments on commit 65f4e14

Please sign in to comment.