Skip to content

Commit

Permalink
Merge pull request #3 from imxcstar/main
Browse files Browse the repository at this point in the history
新增ios支持,修改uri启动器和通知管理器的使用方法
  • Loading branch information
239573049 authored Dec 31, 2024
2 parents cefb125 + b0170ed commit d24be46
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 164 deletions.
7 changes: 7 additions & 0 deletions ChatBox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatBox.Logger", "src\ChatB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatBox.Desktop.Macos", "src\ChatBox.Desktop.Macos\ChatBox.Desktop.Macos.csproj", "{39B84C7C-FAB8-4066-B5C4-AFB7FD81031C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatBox.IOS", "src\ChatBox.IOS\ChatBox.IOS.csproj", "{0B3D5DA7-732D-4919-A755-E15633E5FB31}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,6 +43,10 @@ Global
{39B84C7C-FAB8-4066-B5C4-AFB7FD81031C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39B84C7C-FAB8-4066-B5C4-AFB7FD81031C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39B84C7C-FAB8-4066-B5C4-AFB7FD81031C}.Release|Any CPU.Build.0 = Release|Any CPU
{0B3D5DA7-732D-4919-A755-E15633E5FB31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B3D5DA7-732D-4919-A755-E15633E5FB31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B3D5DA7-732D-4919-A755-E15633E5FB31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B3D5DA7-732D-4919-A755-E15633E5FB31}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -51,6 +57,7 @@ Global
{908453E7-9DAC-42C1-8B41-5199ECB5E785} = {40D887DE-CAB8-452F-90FE-BB3CF2B2613C}
{14CDEB6A-DB37-4A22-B0AC-B5117EF57DDB} = {40D887DE-CAB8-452F-90FE-BB3CF2B2613C}
{39B84C7C-FAB8-4066-B5C4-AFB7FD81031C} = {40D887DE-CAB8-452F-90FE-BB3CF2B2613C}
{0B3D5DA7-732D-4919-A755-E15633E5FB31} = {40D887DE-CAB8-452F-90FE-BB3CF2B2613C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A2982A7-F084-41A2-ACD5-4C6DDA6F03C4}
Expand Down
4 changes: 2 additions & 2 deletions src/ChatBox.Desktop.Macos/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using ChatBox.Constant;
using ChatBox.Service;
using Foundation;
using Microsoft.Extensions.DependencyInjection;

namespace ChatBox.Desktop;

Expand All @@ -22,8 +23,7 @@ public override void OpenUrls(NSApplication application, NSUrl[] urls)
var token = CrossPlatformCustomProtocolHelper.ParseCustomProtocolArgs(urls.Select(u => u.AbsoluteString).Where(x=>!string.IsNullOrWhiteSpace(x)).ToArray()!);
if (!string.IsNullOrWhiteSpace(token))
{
var settingService = new SettingService();

var settingService = HostApplication.Services.GetRequiredService<SettingService>();
settingService.InitSetting(token);
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/ChatBox.IOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using Foundation;
using UIKit;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.iOS;
using ChatBox.Desktop;
using ChatBox.Service;
using Microsoft.Extensions.DependencyInjection;

namespace ChatBox.iOS;

// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public partial class AppDelegate : AvaloniaAppDelegate<App>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
{
public AppDelegate()
{
// 订阅 Activated 事件
((IAvaloniaAppDelegate)this).Activated += OnActivated;
}

private void OnActivated(object? sender, ActivatedEventArgs e)
{
// 检查是否是 URL 协议激活
if (e is ProtocolActivatedEventArgs protocolArgs)
{
var uri = protocolArgs.Uri.ToString();
var token = CrossPlatformCustomProtocolHelper.ParseCustomProtocolArgs([uri]);
if (!string.IsNullOrWhiteSpace(token))
{
var settingService = HostApplication.Services.GetRequiredService<SettingService>();
settingService.InitSetting(token);
}
}
}

protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
{
return base.CustomizeAppBuilder(builder)
.WithInterFont()
.LogToTrace();
}
}
28 changes: 28 additions & 0 deletions src/ChatBox.IOS/ChatBox.IOS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0-ios</TargetFramework>
<SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ChatBox\ChatBox.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia.iOS" Version="11.2.3" />
</ItemGroup>

<ItemGroup>
<BundleResource Include="..\ChatBox\i18n\ChatBoxMarkdown.zh-Hant.xml">
<Link>Resources\i18n\ChatBoxMarkdown.zh-Hant.xml</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</BundleResource>
<BundleResource Include="..\ChatBox\models.json">
<Link>Resources\models.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</BundleResource>
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/ChatBox.IOS/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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/>
</plist>
54 changes: 54 additions & 0 deletions src/ChatBox.IOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>CFBundleDisplayName</key>
<string>ChatBox</string>
<key>CFBundleIdentifier</key>
<string>com.aidotnet.chatbox</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MinimumOSVersion</key>
<string>13.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.aidotnet.chatbox</string>
<key>CFBundleURLSchemes</key>
<array>
<string>chatbox</string>
</array>
</dict>
</array>
</dict>
</plist>
16 changes: 16 additions & 0 deletions src/ChatBox.IOS/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using UIKit;

namespace ChatBox.iOS;

public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
HostApplication.Builder();
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
43 changes: 43 additions & 0 deletions src/ChatBox.IOS/Resources/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207" />
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1" />
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" />
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder" />
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480" />
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2022 " textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines"
minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21" />
<fontDescription key="fontDescription" type="system" pointSize="17" />
<color key="textColor" cocoaTouchSystemColor="darkTextColor" />
<nil key="highlightedColor" />
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ChatBox" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines"
minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43" />
<fontDescription key="fontDescription" type="boldSystem" pointSize="36" />
<color key="textColor" cocoaTouchSystemColor="darkTextColor" />
<nil key="highlightedColor" />
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC" />
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk" />
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l" />
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0" />
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9" />
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g" />
</constraints>
<nil key="simulatedStatusBarMetrics" />
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics" />
<point key="canvasLocation" x="548" y="455" />
</view>
</objects>
</document>
2 changes: 1 addition & 1 deletion src/ChatBox/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void OnFrameworkInitializationCompleted()
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = HostApplication.Services.GetRequiredService<MainWindow>();
singleViewPlatform.MainView = HostApplication.Services.GetRequiredService<MainView>();
}

base.OnFrameworkInitializationCompleted();
Expand Down
1 change: 1 addition & 0 deletions src/ChatBox/ChatBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<InterceptorsNamespaces>$(InterceptorsNamespaces);Dapper.AOT</InterceptorsNamespaces>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 4 additions & 10 deletions src/ChatBox/Controls/ChatInput.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public ChatInput()
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_notificationManager = new WindowNotificationManager(HostApplication.Services.GetService<MainWindow>())
{
Position = NotificationPosition.TopRight,
MaxItems = 4,
Margin = new Thickness(0, 0, 15, 40)
};
_notificationManager = HostApplication.Services.GetService<WindowNotificationManager>();
}


Expand Down Expand Up @@ -254,19 +249,18 @@ private async void DeleteButton_Click(object? sender, RoutedEventArgs e)

private async void OpenFile(object? sender, RoutedEventArgs e)
{
var _target = HostApplication.Services.GetService<MainWindow>();
var files = await _target.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
var files = await TopLevel.GetTopLevel(this).StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
{
Title = "请选择文件",
AllowMultiple = true,
FileTypeFilter = new[] { CodeAll, FilePickerFileTypes.TextPlain }
});

if (files.Count == 0)
{
return;
}

foreach (var file in files)
{
ViewModel.Files.Add(new FileModel()
Expand Down
10 changes: 2 additions & 8 deletions src/ChatBox/Controls/ChatRender.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);

_notificationManager = new WindowNotificationManager(HostApplication.Services.GetService<MainWindow>())
{
Position = NotificationPosition.TopRight,
MaxItems = 4,
Margin = new Thickness(0, 0, 15, 40)
};
_notificationManager = HostApplication.Services.GetService<WindowNotificationManager>();
}

private void DeleteButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -138,8 +133,7 @@ private Button CreateCopyButton(string codeContent)

copyButton.Click += (sender, e) =>
{
var window = HostApplication.Services.GetService<MainWindow>();
window.Clipboard?.SetTextAsync(codeContent);
TopLevel.GetTopLevel(HostApplication.Services.GetService<MainView>())!.Clipboard?.SetTextAsync(codeContent);
_notificationManager?.Show(new Notification(
"已复制",
"代码已复制到剪贴板",
Expand Down
7 changes: 1 addition & 6 deletions src/ChatBox/Controls/WorkspaceConversation.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ public WorkspaceConversation()
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_notificationManager = new WindowNotificationManager(HostApplication.Services.GetService<MainWindow>())
{
Position = NotificationPosition.TopRight,
MaxItems = 3,
Margin = new Thickness(0, 0, 15, 40)
};
_notificationManager = HostApplication.Services.GetService<WindowNotificationManager>();
}

protected override async void OnDataContextChanged(EventArgs e)
Expand Down
1 change: 1 addition & 0 deletions src/ChatBox/DataAccess/ChatMessageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ChatBox.DataAccess;

[DapperAot]
public class ChatMessageRepository(Lazy<DbContext> dbContext)
{
public async Task InsertAsync(ChatMessage message)
Expand Down
Loading

0 comments on commit d24be46

Please sign in to comment.