Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to macOS UI #83

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ExtensionInstaller/ExtensionInstaller.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\TuneLab\bin</BaseOutputPath>

<CFBundleShortVersionString>1.0.0</CFBundleShortVersionString>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions ExtensionInstaller/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text.Json;
Expand Down Expand Up @@ -67,7 +67,7 @@ static void Main(string[] args)
Console.WriteLine(name + " has been successfully installed!\n");
}

if (restart) Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TuneLab.exe"));
if (restart) Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "TuneLab.exe" : "TuneLab"));
}
catch (Exception ex)
{
Expand Down
7 changes: 6 additions & 1 deletion TuneLab.Base/TuneLab.Base.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<CFBundleShortVersionString>1.0.0</CFBundleShortVersionString>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion TuneLab.Extensions.Formats/TuneLab.Extensions.Formats.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<CFBundleShortVersionString>1.0.0</CFBundleShortVersionString>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TuneLab.Base\TuneLab.Base.csproj" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion TuneLab.Extensions.Voices/TuneLab.Extensions.Voices.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<CFBundleShortVersionString>1.0.0</CFBundleShortVersionString>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TuneLab.Base\TuneLab.Base.csproj" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>

</Project>
14 changes: 10 additions & 4 deletions TuneLab/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -55,13 +55,16 @@ public static AppBuilder BuildAvaloniaApp()
{
GC.KeepAlive(typeof(Avalonia.Svg.Skia.SvgImageExtension).Assembly);
GC.KeepAlive(typeof(Avalonia.Svg.Skia.Svg).Assembly);
return AppBuilder.Configure<App>()
var appBuilder = AppBuilder.Configure<App>()
.UsePlatformDetect()
.UseSkia()
.WithInterFont()
.LogToTrace()
.UseReactiveUI()
.With(new FontManagerOptions()
.UseReactiveUI();

if (PlatformHelper.GetOS() == "win")
{
return appBuilder.With(new FontManagerOptions()
{
FontFallbacks =
[
Expand All @@ -70,5 +73,8 @@ public static AppBuilder BuildAvaloniaApp()
new FontFallback() { FontFamily = "Microsoft YaHei" },
]
});
}

return appBuilder;
}
}
16 changes: 15 additions & 1 deletion TuneLab/TuneLab.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
Expand All @@ -9,6 +9,19 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<LangVersion>latest</LangVersion>
<Version>1.5.4</Version>

<!-- macOS Options -->
<CFBundleName>TuneLab</CFBundleName> <!-- Also defines .app file name -->
<CFBundleDisplayName>TuneLab</CFBundleDisplayName>
<CFBundleIdentifier>app.tunelab.editor</CFBundleIdentifier>
<CFBundleVersion>1.5.4</CFBundleVersion>
<CFBundleShortVersionString>1.5.4</CFBundleShortVersionString>
<CFBundlePackageType>APPL</CFBundlePackageType>
<CFBundleSignature>????</CFBundleSignature>
<CFBundleExecutable>TuneLab</CFBundleExecutable>
<!-- <CFBundleIconFile>AppName.icns</CFBundleIconFile> Will be copied from output directory -->
<NSPrincipalClass>NSApplication</NSPrincipalClass>
<NSHighResolutionCapable>true</NSHighResolutionCapable>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -37,6 +50,7 @@
<PackageReference Include="Svg.Skia" Version="1.0.0.18" />
<PackageReference Include="Tomlyn" Version="0.17.0" />
<PackageReference Include="ZstdSharp.Port" Version="0.8.1" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions TuneLab/UI/MainWindow/Editor/Editor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -40,6 +40,7 @@ namespace TuneLab.UI;
internal class Editor : DockPanel, PianoWindow.IDependency, TrackWindow.IDependency
{
public Menu Menu { get; }
public NativeMenu NativeMenu { get; }
public TrackWindow TrackWindow => mTrackWindow;
public PianoWindow PianoWindow => mPianoWindow;
public ProjectDocument Document => mDocument;
Expand Down Expand Up @@ -646,7 +647,7 @@ public async void InstallExtensions(IEnumerable<string> files)
{
List<string> args = ["-restart"];
args.AddRange(installedExtension);
ProcessHelper.CreateProcess(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtensionInstaller.exe"), args);
ProcessHelper.CreateProcess(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PlatformHelper.GetOS() == "win" ? "ExtensionInstaller.exe" : "ExtensionInstaller"), args);
this.Window().Close();
};
dialog.AddButton("No".Tr(TC.Dialog), ButtonType.Primary);
Expand Down
49 changes: 32 additions & 17 deletions TuneLab/UI/MainWindow/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Avalonia;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
Expand Down Expand Up @@ -30,6 +30,14 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
// if macOS
if (PlatformHelper.GetOS() == "osx")
{
ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.PreferSystemChrome;
CustomTitleBar.Height = 28;
ExtendClientAreaTitleBarHeightHint = 28;
}

platform = Environment.OSVersion.Platform;
WindowStartupLocation = WindowStartupLocation.CenterScreen;

Expand All @@ -43,24 +51,28 @@ public MainWindow()
Background = Style.BACK.ToBrush();
Content.Margin = new(1, 0);

var binimizeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = Colors.White.Opacity(0.2), PressedColor = Colors.White.Opacity(0.2) } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.WindowMin }, ColorSet = new() { Color = Style.TEXT_LIGHT.Opacity(0.7) } });
binimizeButton.Clicked += () => WindowState = WindowState.Minimized;
// if not macOS
if (PlatformHelper.GetOS() != "osx")
{
var binimizeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = Colors.White.Opacity(0.2), PressedColor = Colors.White.Opacity(0.2) } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.WindowMin }, ColorSet = new() { Color = Style.TEXT_LIGHT.Opacity(0.7) } });
binimizeButton.Clicked += () => WindowState = WindowState.Minimized;

maximizeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = Colors.White.Opacity(0.2), PressedColor = Colors.White.Opacity(0.2) } })
.AddContent(maximizeIconContent);
maximizeButton.Clicked += () => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
maximizeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = Colors.White.Opacity(0.2), PressedColor = Colors.White.Opacity(0.2) } })
.AddContent(maximizeIconContent);
maximizeButton.Clicked += () => WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;

var closeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = new(255, 232, 17, 35), PressedColor = new(255, 232, 17, 35) } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.WindowClose }, ColorSet = new() { Color = Style.TEXT_LIGHT.Opacity(0.7) } });
closeButton.Clicked += () => Close();
var closeButton = new Button() { Width = 48, Height = 40 }
.AddContent(new() { Item = new BorderItem() { CornerRadius = 0 }, ColorSet = new() { HoveredColor = new(255, 232, 17, 35), PressedColor = new(255, 232, 17, 35) } })
.AddContent(new() { Item = new IconItem() { Icon = Assets.WindowClose }, ColorSet = new() { Color = Style.TEXT_LIGHT.Opacity(0.7) } });
closeButton.Clicked += () => Close();

WindowControl.Children.Add(binimizeButton);
WindowControl.Children.Add(maximizeButton);
WindowControl.Children.Add(closeButton);
WindowControl.Children.Add(binimizeButton);
WindowControl.Children.Add(maximizeButton);
WindowControl.Children.Add(closeButton);
}

this.AttachWindowStateHandler();

Expand All @@ -69,7 +81,10 @@ public MainWindow()
mEditor = new Editor();
mEditor.Document.ProjectNameChanged.Subscribe(UpdateTitle);
mEditor.Document.StatusChanged += UpdateTitle;
MenuBar.Children.Add(mEditor.Menu);

// if not macOS
if (PlatformHelper.GetOS() != "osx")
MenuBar.Children.Add(mEditor.Menu);

var dockPanelEditor = new DockPanel();

Expand Down
Loading