Skip to content

Commit

Permalink
- hyerlink and window show/hide logic cleanup
Browse files Browse the repository at this point in the history
- use clickonce deployment info to display app on updates/first launch
  • Loading branch information
pjmagee committed Jun 24, 2024
1 parent 287eb7b commit 0012911
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 45 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./Heroesprofile.Uploader.Windows/bin/publish
keep_files: true
keep_files: false

- name: Upload artifact
uses: actions/upload-artifact@v4
Expand All @@ -61,9 +61,8 @@ jobs:
artifacts: "./Heroesprofile.Uploader.Windows/bin/publish/**"
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
allowUpdates: true
makeLatest: true
replacesArtifacts: true
generateReleaseNotes: true
artifactErrorsFailBuild: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 23 additions & 15 deletions Heroesprofile.Uploader.Windows/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,24 @@ private void Application_Startup(object sender, StartupEventArgs e)
settingsManager.SaveSettings(UserSettings);
};

if (StartWithWindows) {
// TODO: running in the background
} else {
MainWindow = new MainWindow();
MainWindow.Deactivated += (o, ev) => {
// TODO: TrayIcon.Visible = true;
};
var showWindow = false;

MainWindow = new MainWindow();
MainWindow.Deactivated += (o, ev) => { };

#if DEBUG
showWindow = true;
#else
showWindow = ApplicationDeployment.CurrentDeployment?.IsFirstRun == true ||
ApplicationDeployment.IsNetworkDeployed == false ||
UserSettings.MinimizeToTray == false;
#endif


if (showWindow) {
MainWindow.Show();
}

Manager.Start(new Monitor(), new LiveMonitor(), new Analyzer(), new Common.Uploader(), new LiveProcessor(Manager.PreMatchPage));
}

Expand All @@ -157,14 +166,13 @@ public void ApplyTheme(string theme)
}

public void Activate()
{
MainWindow = new MainWindow();
MainWindow.Activate();
MainWindow.WindowState = WindowState.Normal;
MainWindow.Show();

//
// TaskbarIcon.Visible = false;
{
if (MainWindow == null){
MainWindow = new MainWindow();
MainWindow.Activate();
MainWindow.WindowState = WindowState.Normal;
MainWindow.Show();
}
}

private void SetupTrayIcon()
Expand Down
4 changes: 4 additions & 0 deletions Heroesprofile.Uploader.Windows/Core/ApplicationDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public string DataDirectory
get { return Environment.GetEnvironmentVariable("ClickOnce_DataDirectory"); }
}

/// <summary>
/// The value of this property is reset whenever the user upgrades from one version to the next.
/// If you want to perform an operation only the very first time any version of the application is run, you will need to perform an additional test, such as checking for the existence of a file you created the first time, or storing a flag using Application Settings.
/// </summary>
public bool IsFirstRun
{
get {
Expand Down
8 changes: 5 additions & 3 deletions Heroesprofile.Uploader.Windows/Core/NotifyIconViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public partial class NotifyIconViewModel : ObservableObject
[RelayCommand(CanExecute = nameof(CanExecuteShowWindow))]
public void ShowWindow()
{
Application.Current.MainWindow ??= new MainWindow();
Application.Current.MainWindow.WindowState = WindowState.Normal;
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Activate();
Application.Current.MainWindow.WindowState = WindowState.Normal;


}

/// <summary>
Expand All @@ -32,7 +34,7 @@ public void ShowWindow()
[RelayCommand(CanExecute = nameof(CanExecuteHideWindow))]
public void HideWindow()
{
Application.Current.MainWindow.Hide(enableEfficiencyMode: true);
Application.Current.MainWindow.Hide(enableEfficiencyMode: false);
}

/// <summary>
Expand Down
12 changes: 9 additions & 3 deletions Heroesprofile.Uploader.Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
xmlns:local="clr-namespace:Heroesprofile.Uploader.Windows"
xmlns:helpers="clr-namespace:Heroesprofile.Uploader.Windows.UIHelpers"
xmlns:heroesprofile="clr-namespace:Heroesprofile.Uploader.Common;assembly=Heroesprofile.Uploader.Common"
mc:Ignorable="d"
StateChanged="Window_StateChanged" Closed="Window_Closed"
mc:Ignorable="d"
Deactivated="Window_Deactivated" Closed="Window_Closed"
Height="{Binding UserSettings.WindowHeight, Mode=TwoWay}" Width="{Binding UserSettings.WindowWidth, Mode=TwoWay}"
Top="{Binding UserSettings.WindowTop, Mode=TwoWay}" Left="{Binding UserSettings.WindowLeft, Mode=TwoWay}"
Title="{Binding VersionString, StringFormat=Heroesprofile.com Uploader {0}}"
Expand All @@ -31,7 +31,13 @@
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid Grid.ColumnSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="Resources/uploader_light.png" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="HighQuality" Cursor="Hand" MouseUp="Logo_MouseUp" Margin="0,0,131,0" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
<TextBlock>
<Hyperlink NavigateUri="https://heroesprofile.com" RequestNavigate="Hyperlink_RequestNavigate">
<Image
Source="Resources/uploader_dark.png" SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="HighQuality"
Cursor="Hand" Margin="0,0,131,0" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Hyperlink>
</TextBlock>
</Grid>
<ListBox Grid.Row="1" ItemsSource="{Binding Files}" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
Expand Down
42 changes: 21 additions & 21 deletions Heroesprofile.Uploader.Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,43 @@ public MainWindow()
{
InitializeComponent();
DataContext = this;


}

private void Window_Closed(object sender, EventArgs e)
{
App.Current.Shutdown();
}

private void Window_StateChanged(object sender, EventArgs e)
private void ShowLog_Click(object sender, RoutedEventArgs e)
{
if (App.Current.UserSettings.MinimizeToTray) {
if (WindowState == WindowState.Minimized) {
Hide();
}
}
Process.Start("explorer.exe", $@"{App.Current.SettingsDir}\logs");
}

private void Window_Closed(object sender, EventArgs e)
private void Settings_Click(object sender, RoutedEventArgs e)
{
if (App.Current.UserSettings.MinimizeToTray) {

} else {
App.Current.Shutdown();
}
var settings = new SettingsWindow() { Owner = this, DataContext = this };
settings.ShowDialog();
}

private void Logo_MouseUp(object sender, MouseButtonEventArgs e)
private void Window_Closing(object sender, CancelEventArgs e)
{
Process.Start("https://www.heroesprofile.com/");
if (App.Current.UserSettings.MinimizeToTray) {
e.Cancel = true;
Hide();
}
}

private void ShowLog_Click(object sender, RoutedEventArgs e)
private void Window_Deactivated(object sender, EventArgs e)
{
Process.Start("explorer.exe", $@"{App.Current.SettingsDir}\logs");
if (App.Current.UserSettings.MinimizeToTray) {
Hide();
}
}

private void Settings_Click(object sender, RoutedEventArgs e)
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
var settings = new SettingsWindow() { Owner = this, DataContext = this };
settings.ShowDialog();
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
e.Handled = true;
}
}
}

0 comments on commit 0012911

Please sign in to comment.