Skip to content

Commit

Permalink
Close to tray & build ci
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Apr 20, 2024
1 parent 552f647 commit 3430ee4
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 3 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
types: [opened, reopened, synchronize]
workflow_call:
workflow_dispatch:

name: ci-windowsl

env:
DOTNET_VERSION: 8.0.x
REGISTRY: ghcr.io

jobs:

build:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET SDK ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Install dependencies
run: dotnet restore

- name: Install maui workload
run: dotnet workload install maui

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --no-restore --verbosity normal

- name: Publish ShockOSC Windows
run: dotnet publish ShockOsc/ShockOsc.csproj -c Release -f net8.0-windows10.0.19041.0 -o ./publish/API

- name: Upload ShockOSC Windows artifacts
uses: actions/upload-artifact@v4
with:
name: ShockOsc
path: publish/ShockOsc/*
retention-days: 1
if-no-files-found: error

instller:
runs-on: windows-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
Installer
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: ShockOsc
path: publish/


6 changes: 6 additions & 0 deletions ShockOsc/Config/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace OpenShock.ShockOsc.Config;

public sealed class AppConfig
{
public bool CloseToTray { get; set; } = true;
}
2 changes: 1 addition & 1 deletion ShockOsc/Config/ShockOscConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public sealed class ShockOscConfig
public IDictionary<Guid, Group> Groups { get; set; } = new Dictionary<Guid, Group>();
public Version? LastIgnoredVersion { get; set; } = null;


public AppConfig App { get; set; } = new();
}
42 changes: 40 additions & 2 deletions ShockOsc/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace OpenShock.ShockOsc;

public static class MauiProgram
{
private static ShockOscConfig? _config;

public static Microsoft.Maui.Hosting.MauiApp CreateMauiApp()
{
var builder = Microsoft.Maui.Hosting.MauiApp.CreateBuilder();
Expand Down Expand Up @@ -76,9 +78,43 @@ public static Microsoft.Maui.Hosting.MauiApp CreateMauiApp()

builder.Services.AddSingleton<Services.ShockOsc>();
builder.Services.AddSingleton<UnderscoreConfig>();



#if WINDOWS
builder.ConfigureLifecycleEvents(lifecycleBuilder =>
{
lifecycleBuilder.AddWindows(windowsLifecycleBuilder =>
{
windowsLifecycleBuilder.OnWindowCreated(window =>
{
//use Microsoft.UI.Windowing functions for window
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);
var id = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(handle);
var appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(id);
//When user execute the closing method, we can push a display alert. If user click Yes, close this application, if click the cancel, display alert will dismiss.
appWindow.Closing += async (s, e) =>
{
e.Cancel = true;
if (_config?.App.CloseToTray ?? false)
{
appWindow.Hide();
return;
}
var result = await Application.Current.MainPage.DisplayAlert(

Check warning on line 105 in ShockOsc/MauiProgram.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 105 in ShockOsc/MauiProgram.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 105 in ShockOsc/MauiProgram.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 105 in ShockOsc/MauiProgram.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
"Close?",
"Do you want to close ShockOSC?",
"Yes",
"Cancel");
if (result) Application.Current.Quit();
};
});
});
});


builder.Services.AddSingleton<ITrayService, WindowsTrayService>();
#endif

Expand All @@ -99,6 +135,8 @@ public static Microsoft.Maui.Hosting.MauiApp CreateMauiApp()

var app = builder.Build();

_config = app.Services.GetRequiredService<ConfigManager>().Config;

app.Services.GetService<ITrayService>()?.Initialize();

// <---- Warmup ---->
Expand Down
2 changes: 2 additions & 0 deletions ShockOsc/Platforms/Windows/WindowsTrayService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ private static void OnMainClick(object? sender, EventArgs eventArgs)
var windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);
var appWindow = AppWindow.GetFromWindowId(windowId);



if (appWindow.IsVisible) appWindow.Hide();
else appWindow.Show();
}
Expand Down

0 comments on commit 3430ee4

Please sign in to comment.