Skip to content

Commit

Permalink
Update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
author committed Oct 14, 2021
1 parent 919f402 commit 211727e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 64 deletions.
22 changes: 8 additions & 14 deletions src/Controls/samples/Maui.Controls.Sample.Mac/Info.plist
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>vstool</string>
<string>Maui.Controls.Sample.Mac</string>
<key>CFBundleIdentifier</key>
<string>com.microsoft.vstool</string>
<string>com.companyname.Maui-Controls-Sample-Mac</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<string>10.14</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -21,19 +21,13 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<string>Microsoft</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>CFBundleDisplayName</key>
<string>vstool</string>
<key>LSUIElement</key>
<true/>
<key>LSEnvironment</key>
<dict>
<key>MONO_ENV_OPTIONS</key>
<string>--debug</string>
</dict>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>

</dict>
</plist>
Expand Up @@ -5,27 +5,13 @@
<TargetFramework>net6.0-macos</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SupportedOSPlatformVersion>11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion>10.14</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<EnableCodeSigning>false</EnableCodeSigning>
<UseSGen>false</UseSGen>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<EnableCodeSigning>false</EnableCodeSigning>
<UseSGen>false</UseSGen>
</PropertyGroup>
<ItemGroup Condition=" '$(UseMaui)' != 'true' ">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
</ItemGroup>

<ItemGroup Condition=" '$(UseMaui)' != 'true' ">
<ProjectReference Include="..\..\..\Core\src\Core-net6.csproj" />
<ProjectReference Include="..\..\..\Controls\src\Xaml\Controls.Xaml-net6.csproj" />
<ProjectReference Include="..\..\..\Controls\src\Core\Controls.Core-net6.csproj" />
<ProjectReference Include="..\..\..\BlazorWebView\src\Maui\Microsoft.AspNetCore.Components.WebView.Maui.csproj" />
<ProjectReference Include="..\..\..\Compatibility\Core\src\Compatibility-net6.csproj" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions src/Controls/samples/Maui.Controls.Sample.Macos/App.cs
@@ -0,0 +1,16 @@
using Foundation;
using AppKit;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Macos
{
public class App: Application
{
public App()
{
MainPage = new Page();
}
}
}
29 changes: 15 additions & 14 deletions src/Controls/samples/Maui.Controls.Sample.Macos/AppDelegate.cs
@@ -1,24 +1,25 @@
using AppKit;
using Foundation;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Hosting;

namespace Maui.Controls.Sample.Macos
{
[Register("AppDelegate")]
public class AppDelegate : NSApplicationDelegate
public class AppDelegate : MauiUIApplicationDelegate
{
public AppDelegate()
{
}
public AppDelegate()
{
}

public override void DidFinishLaunching(NSNotification notification)
{
// Insert code here to initialize your application
}

public override void WillTerminate(NSNotification notification)
{
// Insert code here to tear down your application
}
}
protected override MauiApp CreateMauiApp()
{
var appBuilder = MauiApp.CreateBuilder();
appBuilder.UseMauiApp<App>();
return appBuilder.Build();
}
}
}

1 change: 1 addition & 0 deletions src/Controls/samples/Maui.Controls.Sample.Macos/Main.cs
Expand Up @@ -7,6 +7,7 @@ static class MainClass
static void Main(string[] args)
{
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
}
}
Expand Down
Expand Up @@ -23,4 +23,31 @@
<EnableCodeSigning>false</EnableCodeSigning>
<UseSGen>false</UseSGen>
</PropertyGroup>

<ItemGroup Condition=" '$(UseMaui)' != 'true' ">
<ProjectReference Include="..\..\..\Core\src\Core-net6.csproj">
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Controls\src\Xaml\Controls.Xaml-net6.csproj">
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Controls\src\Core\Controls.Core-net6.csproj">
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Compatibility\Core\src\Compatibility-net6.csproj">
<Private>True</Private>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" PrivateAssets="all" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsConfigurationPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHostingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsHostingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
<PackageReference Include="Microsoft.Maui.Graphics" Version="$(MicrosoftMauiGraphicsVersion)" />
</ItemGroup>

</Project>
35 changes: 14 additions & 21 deletions src/Core/src/Platform/Mac/MauiUIApplicationDelegate.cs
Expand Up @@ -11,6 +11,7 @@ public abstract class MauiUIApplicationDelegate : NSApplicationDelegate, INSAppl
{
MauiContext _applicationContext = null!;
WeakReference<IWindow>? _virtualWindow = null;
NSDictionary launchOptions = new NSDictionary();

internal IWindow? VirtualWindow
{
Expand All @@ -31,6 +32,17 @@ protected MauiUIApplicationDelegate()


public override void WillFinishLaunching(NSNotification notification)
{
var mauiApp = CreateMauiApp();

Services = mauiApp.Services;

_applicationContext = new MauiContext(Services, this);

Services?.InvokeLifecycleEvents<MacLifecycle.WillFinishLaunching>(del => del(NSApplication.SharedApplication, launchOptions));
}

public override void DidFinishLaunching(NSNotification notification)
{
Application = Services.GetRequiredService<IApplication>();

Expand All @@ -42,11 +54,8 @@ public override void WillFinishLaunching(NSNotification notification)

Window.MakeKeyAndOrderFront(Window);

//Services?.InvokeLifecycleEvents<MacLifecycle.FinishedLaunching>(del => del(application, launchOptions));

// return true;

base.WillFinishLaunching(notification);
Services?.InvokeLifecycleEvents<MacLifecycle.FinishedLaunching>(del => del(NSApplication.SharedApplication, launchOptions));
base.DidFinishLaunching(notification);
}

NSWindow CreateNativeWindow()
Expand Down Expand Up @@ -77,22 +86,6 @@ public override void OpenUrls(NSApplication application, NSUrl[] urls)
//return wasHandled || base.OpenUrl(application, url, options);
}

public override void DidFinishLaunching(NSNotification notification)
{
Application = Services.GetRequiredService<IApplication>();

this.SetApplicationHandler(Application, _applicationContext);

var uiWindow = CreateNativeWindow();

Window = uiWindow;

Window.MakeKeyAndOrderFront(Window);

//Services?.InvokeLifecycleEvents<iOSLifecycle.FinishedLaunching>(del => del(application, launchOptions));
base.DidFinishLaunching(notification);
}

//public override void PerformActionForShortcutItem(NSApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler)
//{
// Services?.InvokeLifecycleEvents<iOSLifecycle.PerformActionForShortcutItem>(del => del(application, shortcutItem, completionHandler));
Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/Platform/MauiContext.cs
Expand Up @@ -28,6 +28,12 @@ public MauiContext(IServiceProvider services, UIKit.UIApplicationDelegate applic
{
AddSpecific(application);
}
#elif __MACOS__
public MauiContext(IServiceProvider services, AppKit.NSApplicationDelegate application, IMauiContext? parent = null)
: this(services, parent)
{
AddSpecific(application);
}
#elif WINDOWS
public MauiContext(IServiceProvider services, UI.Xaml.Application application, IMauiContext? parent = null)
: this(services, parent)
Expand Down

0 comments on commit 211727e

Please sign in to comment.