Skip to content

Commit

Permalink
Update Notification on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
TheXorog committed Jan 10, 2022
1 parent ab49e2b commit f7f2e61
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions BeatRecorder/Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace BeatRecorder;
class Objects
{
public static bool SettingsRequired = false;
public static bool UpdateAvailable = false;
public static string UpdateText = "";

public static ulong SteamNotificationId = 0;

Expand Down
5 changes: 4 additions & 1 deletion BeatRecorder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ await Task.Run(async () =>
LogFatal($"[BR] You're running an outdated version of BeatRecorder, please update at https://github.com/TheXorog/BeatRecorder/releases/latest." +
$"\n\nWhat changed in the new version:\n\n" +
$"{repo.Body}\n");

Objects.UpdateText = repo.Body;
Objects.UpdateAvailable = true;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -241,7 +244,7 @@ private static void ResetSettings()
LogInfo($"Please configure BeatRecorder using the config file that was just opened. If you're done, save and quit notepad and BeatRecorder will restart for you.");

Objects.SettingsRequired = true;
var infoUI = new InfoUI(Objects.LoadedSettings.DisplayUITopmost, Objects.SettingsRequired);
var infoUI = new InfoUI(Program.CurrentVersion, Objects.LoadedSettings.DisplayUITopmost, Objects.SettingsRequired);
infoUI.ShowDialog();
LogDebug("Settings updated via UI");
Process.Start(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Expand Down
12 changes: 10 additions & 2 deletions BeatRecorder/UIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ internal async Task HandleUI()
{
await Task.Delay(500);

bool DisplayedUpdateNotice = false;

if (!Objects.LoadedSettings.HideConsole)
Program.ShowWindow(Program.GetConsoleWindow(), 2);
else
Program.ShowWindow(Program.GetConsoleWindow(), 0);

LogDebug($"Displaying InfoUI");

var infoUI = new InfoUI(Objects.LoadedSettings.DisplayUITopmost, Objects.SettingsRequired);
var infoUI = new InfoUI(Program.CurrentVersion, Objects.LoadedSettings.DisplayUITopmost, Objects.SettingsRequired);

_ = Task.Run(async () =>
{
Expand All @@ -34,14 +36,20 @@ internal async Task HandleUI()

MessageBox.Show($"A password is required to log into the obs websocket.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

var infoUI2 = new InfoUI(Objects.LoadedSettings.DisplayUITopmost, true);
var infoUI2 = new InfoUI(Program.CurrentVersion, Objects.LoadedSettings.DisplayUITopmost, true);
infoUI2.ShowDialog();
Process.Start(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Thread.Sleep(2000);
Environment.Exit(0);
return;
}

if (Objects.UpdateAvailable && !DisplayedUpdateNotice)
{
DisplayedUpdateNotice = true;
MessageBox.Show($"There's a new version available.\n\n{Objects.UpdateText}", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

if (Program.obsWebSocket.IsRunning)
{
if (infoUI.OBSConnectionLabel.BackColor != Color.DarkGreen && infoUI.OBSConnectionLabel.BackColor != Color.Orange)
Expand Down
34 changes: 32 additions & 2 deletions BeatRecorderUI/InfoUI.Designer.cs

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

8 changes: 7 additions & 1 deletion BeatRecorderUI/InfoUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ public partial class InfoUI : Form

bool SettingsRequired = false;

public InfoUI(bool alwaysTopMost = false, bool settingsRequired = false)
public InfoUI(string version, bool alwaysTopMost = false, bool settingsRequired = false)
{
InitializeComponent();

loadedTopmost = alwaysTopMost;

SettingsRequired = settingsRequired;
VersionLabel.Text = $"v{version}";
}

private void InfoUI_Shown(object sender, EventArgs e)
Expand Down Expand Up @@ -54,4 +55,9 @@ private void Restart_Click(object sender, EventArgs e)
SettingsUpdated = true;
this.Close();
}

private void CheckForUpdates_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("cmd", "/C start https://github.com/TheXorog/BeatRecorder/releases");
}
}
2 changes: 2 additions & 0 deletions BeatRecorderUI/Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace BeatRecorder;
class Objects
{
public static bool SettingsRequired = false;
public static bool UpdateAvailable = false;
public static string UpdateText = "";

public static ulong SteamNotificationId = 0;

Expand Down
2 changes: 1 addition & 1 deletion BeatRecorderUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal static class Program
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new InfoUI());
Application.Run(new InfoUI("0.0"));
}
}

0 comments on commit f7f2e61

Please sign in to comment.