Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
update check on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleinrotti committed Oct 3, 2020
1 parent fbac62d commit 0211a81
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
1 change: 0 additions & 1 deletion TeamCord.Core/Discord/ConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using TeamCord.Core.Notification;

namespace TeamCord.Core
{
Expand Down
28 changes: 28 additions & 0 deletions TeamCord.Core/Notification/UpdateNotification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace TeamCord.Core
{
public class UpdateNotification : NotificationBase
{
/// <summary>
/// Create a update notification. Only pass the version as message.
/// </summary>
/// <param name="message"></param>
/// <param name="title"></param>
public UpdateNotification(string message, string title = "Update") : base(message, title)
{
Message = $"There is a new version of TeamCord available: {message}";
Title = title;
}

/// <summary>
/// Display a notification on the tray icon with a given callback which should be called when balloon tip is clicked
/// </summary>
/// <param name="balloonClickAction"></param>
public void Notify(Action balloonClickAction)
{
BalloonClick = balloonClickAction;
base.Notify();
}
}
}
5 changes: 5 additions & 0 deletions TeamCord.Core/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public class PluginSettings
[Description("When enabled, TeamCord creates a client description for your teamspeak user with your discord id.\n" +
" This allows automuting when other users using TeamCord too and are also connected to that same channel to avoid doubled audio. \nNOTE: Other teamspeak users can find your discord profile this way too!")]
public bool EnableDiscordID { get; set; }

[ControlType(typeof(CheckBox))]
[DisplayName("Check for updates on startup")]
[Description("Automatically check for Teamcord updates when Teamspeak starts.")]
public bool AutoUpdateCheck { get; set; }
}
}
1 change: 1 addition & 0 deletions TeamCord.Core/TeamCord.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Enums\LogTypes.cs" />
<Compile Include="Notification\NotificationBase.cs" />
<Compile Include="Notification\DiscordStatusNotification.cs" />
<Compile Include="Notification\UpdateNotification.cs" />
<Compile Include="PluginSettings.cs" />
<Compile Include="PluginUserCredential.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
3 changes: 2 additions & 1 deletion TeamCord.GUI/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
WindowStyle="ToolWindow"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
Title="Settings" Height="300" Width="300">
Title="Settings" Height="350" Width="300">
<Grid>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
Expand All @@ -31,6 +31,7 @@
<CheckBox Name="checkBox_DebugLogging" Content="Debug logging" />
<CheckBox Name="checkBox_Notifications" Content="Notifications" />
<CheckBox Name="checkBox_Discordid" Content="Discord auto mute" />
<CheckBox Name="checkBox_AutoUpdateCheck" Content="Check for updates on startup" />
<Button Grid.Row="1" Name="button_Save" Content="Apply" Width="50" Click="button_Save_Click" />
</StackPanel>
<Button Name="buttonLogout" Grid.Row="1" Content="Logout" Click="buttonLogout_Click" Visibility="Collapsed" Width="50" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
Expand Down
2 changes: 2 additions & 0 deletions TeamCord.GUI/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public SettingsWindow(PluginSettings settings)
checkBox_DebugLogging.IsChecked = _settings.DebugLogging;
checkBox_Notifications.IsChecked = _settings.Notifications;
checkBox_Discordid.IsChecked = _settings.EnableDiscordID;
checkBox_AutoUpdateCheck.IsChecked = _settings.AutoUpdateCheck;
if (_settings.Token != null)
{
stackPanelLogin.Visibility = Visibility.Collapsed;
Expand All @@ -48,6 +49,7 @@ private void button_Save_Click(object sender, RoutedEventArgs e)
newSettings.DebugLogging = checkBox_DebugLogging.IsChecked ?? false;
newSettings.Notifications = checkBox_Notifications.IsChecked ?? false;
newSettings.EnableDiscordID = checkBox_Discordid.IsChecked ?? false;
newSettings.AutoUpdateCheck = checkBox_AutoUpdateCheck.IsChecked ?? false;
var storage = new DataStorage();
storage.StoreSettings(newSettings);
_changed = true;
Expand Down
13 changes: 13 additions & 0 deletions TeamCord.Plugin/TSPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using TeamCord.Core;
Expand Down Expand Up @@ -118,6 +119,18 @@ public int Init()
TrayIcon.Visible = true;
TrayIcon.ShowNotifications = _settings.Notifications;
TrayIcon.VolumeMenuItemClicked += TrayIcon_VolumeChangedClicked;
if (Settings.AutoUpdateCheck)
{
Updater update = new Updater(new Version(Assembly.GetExecutingAssembly().GetName().Version.ToString()));
update.CheckUpdate();
if (update.UpdateAvailable)
{
new UpdateNotification(update.Version.ToString()).Notify(new Action(() =>
{
Process.Start(update.LatestVersionUrl.AbsoluteUri);
}));
}
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 0211a81

Please sign in to comment.