Skip to content

Commit c830ad7

Browse files
committed
Update build logic for macOS
1 parent 781bbd6 commit c830ad7

File tree

6 files changed

+101
-32
lines changed

6 files changed

+101
-32
lines changed

.github/workflows/BuildMacOS.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,48 @@ jobs:
3333
run: |
3434
pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
3535
-Platform "arm64" `
36-
-outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64"
36+
-outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64" `
37+
-appVersion "${{steps.get-version.outputs.version}}"
3738
shell: pwsh
39+
40+
# Step 5: Create DMG for arm64
41+
- name: Create DMG for arm64
42+
run: |
43+
hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg"
44+
3845
39-
# Step 5: Upload arm64 artifact
40-
- name: Upload arm64 artifact
46+
# Step 6: Upload arm64 artifacts
47+
- name: Upload arm64 artifacts
4148
uses: actions/upload-artifact@v4
4249
with:
4350
name: PicView-v${{steps.get-version.outputs.version}}-macOS-arm64
44-
path: ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/
51+
path: |
52+
${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app
53+
${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg
4554
retention-days: 14
4655

47-
# Step 6: Build x64 version
56+
# Step 7: Build and create x64 .app bundle
4857
- name: Build x64 version
4958
run: |
5059
pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
5160
-Platform "x64" `
52-
-outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64"
61+
-outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64" `
62+
-appVersion "${{steps.get-version.outputs.version}}"
5363
shell: pwsh
64+
65+
# Step 8: Create DMG for x64
66+
- name: Create DMG for x64
67+
run: |
68+
hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg"
69+
70+
5471
55-
# Step 7: Upload x64 artifact
56-
- name: Upload x64 artifact
72+
# Step 9: Upload x64 artifacts
73+
- name: Upload x64 artifacts
5774
uses: actions/upload-artifact@v4
5875
with:
5976
name: PicView-v${{steps.get-version.outputs.version}}-macOS-x64
60-
path: ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/
77+
path: |
78+
${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app
79+
${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg
6180
retention-days: 14

Build/Build Avalonia.MacOS.ps1

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
[string]$Platform,
44

55
[Parameter()]
6-
[string]$outputPath
6+
[string]$outputPath,
7+
8+
[Parameter()]
9+
[string]$appVersion
710
)
811

912
# Define the core project path relative to the script's location
@@ -34,24 +37,81 @@ $coreCsproj.Save($coreProjectPath)
3437
# Define the project path for the actual build target
3538
$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj"
3639

40+
# Create temporary build output directory
41+
$tempBuildPath = Join-Path -Path $outputPath -ChildPath "temp"
42+
New-Item -ItemType Directory -Force -Path $tempBuildPath
43+
3744
# Run dotnet publish for the Avalonia project
3845
dotnet publish $avaloniaProjectPath `
3946
--runtime "osx-$Platform" `
4047
--self-contained true `
4148
--configuration Release `
4249
-p:PublishSingleFile=false `
43-
--output $outputPath
50+
--output $tempBuildPath
51+
52+
# Create .app bundle structure
53+
$appBundlePath = Join-Path -Path $outputPath -ChildPath "PicView.app"
54+
$contentsPath = Join-Path -Path $appBundlePath -ChildPath "Contents"
55+
$macOSPath = Join-Path -Path $contentsPath -ChildPath "MacOS"
56+
$resourcesPath = Join-Path -Path $contentsPath -ChildPath "Resources"
57+
58+
# Create directory structure
59+
New-Item -ItemType Directory -Force -Path $macOSPath
60+
New-Item -ItemType Directory -Force -Path $resourcesPath
61+
62+
# Create Info.plist
63+
$infoPlistContent = @"
64+
<?xml version="1.0" encoding="UTF-8"?>
65+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
66+
<plist version="1.0">
67+
<dict>
68+
<key>CFBundleName</key>
69+
<string>PicView</string>
70+
<key>CFBundleDisplayName</key>
71+
<string>PicView</string>
72+
<key>CFBundleIdentifier</key>
73+
<string>com.ruben2776.picview</string>
74+
<key>CFBundleVersion</key>
75+
<string>${appVersion}</string>
76+
<key>CFBundlePackageType</key>
77+
<string>APPL</string>
78+
<key>CFBundleSignature</key>
79+
<string>picview.org</string>
80+
<key>CFBundleExecutable</key>
81+
<string>PicView.Avalonia.MacOS</string>
82+
<key>CFBundleIconFile</key>
83+
<string>AppIcon.icns</string>
84+
<key>CFBundleShortVersionString</key>
85+
<string>${appVersion}</string>
86+
<key>LSMinimumSystemVersion</key>
87+
<string>10.15</string>
88+
<key>NSHighResolutionCapable</key>
89+
<true/>
90+
</dict>
91+
</plist>
92+
"@
93+
94+
# Save Info.plist
95+
$infoPlistPath = Join-Path -Path $contentsPath -ChildPath "Info.plist"
96+
$infoPlistContent | Out-File -FilePath $infoPlistPath -Encoding UTF8
4497

45-
# Remove the PDB file
46-
$pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
47-
if (Test-Path $pdbPath) {
48-
Remove-Item -Path $pdbPath -Force
98+
# Copy build output to MacOS directory
99+
Copy-Item -Path "$tempBuildPath/*" -Destination $macOSPath -Recurse
100+
101+
# Copy icon if it exists (you'll need to create this)
102+
$iconSource = Join-Path -Path $PSScriptRoot -ChildPath "../src/PicView.Avalonia.MacOS/Assets/AppIcon.icns"
103+
if (Test-Path $iconSource) {
104+
Copy-Item -Path $iconSource -Destination $resourcesPath
49105
}
50106

51-
# Remove unintended space
52-
if (Test-Path $outputPath) {
53-
$newPath = $outputPath.Replace(" ","")
54-
if ($outputPath -ne $newPath) {
55-
Rename-Item -Path $outputPath -NewName $newPath -Force
56-
}
107+
# Remove PDB files
108+
Get-ChildItem -Path $macOSPath -Filter "*.pdb" -Recurse | Remove-Item -Force
109+
110+
# Remove temporary build directory
111+
Remove-Item -Path $tempBuildPath -Recurse -Force
112+
113+
# Set executable permissions on the main binary
114+
if ($IsLinux -or $IsMacOS) {
115+
$mainBinary = Join-Path -Path $macOSPath -ChildPath "PicView.Avalonia.MacOS"
116+
chmod +x $mainBinary
57117
}

src/PicView.Avalonia.MacOS/PicView.Avalonia.MacOS.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<Copyright>© Ruben Hyldgaard Negendahl</Copyright>
2121
<ImplicitUsings>enable</ImplicitUsings>
2222
<Product>PicView</Product>
23-
<ApplicationIcon>icon.ico</ApplicationIcon>
2423
</PropertyGroup>
2524
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
2625
<DebugType>none</DebugType>

src/PicView.Avalonia.MacOS/Theme/Controls/Window.axaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2-
<Design.PreviewWith>
3-
<Window />
4-
</Design.PreviewWith>
2+
53
<ControlTheme TargetType="Window" x:Key="{x:Type Window}">
64
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
75
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" />

src/PicView.Avalonia.MacOS/Views/MacMainWindow.axaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,17 @@
99
SizeChanged="Control_OnSizeChanged"
1010
SizeToContent="{CompiledBinding SizeToContent}"
1111
Title="{CompiledBinding WindowTitle}"
12-
mc:Ignorable="d"
1312
x:Class="PicView.Avalonia.MacOS.Views.MacMainWindow"
1413
x:DataType="viewModels:MainViewModel"
1514
xmlns="https://github.com/avaloniaui"
1615
xmlns:converters1="clr-namespace:PicView.Avalonia.Converters;assembly=PicView.Avalonia"
17-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
18-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1916
xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels;assembly=PicView.Avalonia"
2017
xmlns:views="clr-namespace:PicView.Avalonia.Views;assembly=PicView.Avalonia"
2118
xmlns:views1="clr-namespace:PicView.Avalonia.MacOS.Views"
22-
xmlns:vm="using:PicView.Avalonia.ViewModels"
2319
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2420
<Window.Resources>
2521
<converters1:SortFilesByToBoolConverter x:Key="EnumToBoolConverter" />
2622
</Window.Resources>
27-
<Design.DataContext>
28-
<vm:MainViewModel />
29-
</Design.DataContext>
3023
<NativeMenu.Menu>
3124
<NativeMenu>
3225
<NativeMenuItem Header="{CompiledBinding File}">
-26.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)