diff --git a/arm-build.iss b/arm-build.iss new file mode 100644 index 0000000..a4c7b02 --- /dev/null +++ b/arm-build.iss @@ -0,0 +1,70 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +#define MyAppName "ChatBox" +#define MyAppVersion "0.1.1" +#define MyAppPublisher "TokenAi" +#define MyAppURL "https://api.token-ai.cn" +#define MyAppExeName "ChatBox.Desktop.exe" +#define MyAppAssocName MyAppName + "" +#define MyAppAssocExt ".exe" +#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt + +[Setup] +; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. +; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) +AppId={{1E9A7D67-5468-469D-86AB-FFE07136EBD1} +AppName={#MyAppName} +AppVersion={#MyAppVersion} +;AppVerName={#MyAppName} {#MyAppVersion} +AppPublisher={#MyAppPublisher} +AppPublisherURL={#MyAppURL} +AppSupportURL={#MyAppURL} +AppUpdatesURL={#MyAppURL} +DefaultDirName={autopf}\{#MyAppName} +; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run +; on anything but x64 and Windows 11 on Arm. +ArchitecturesAllowed=x64compatible +; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the +; install be done in "64-bit mode" on x64 or Windows 11 on Arm, +; meaning it should use the native 64-bit Program Files directory and +; the 64-bit view of the registry. +ArchitecturesInstallIn64BitMode=x64compatible +ChangesAssociations=yes +DisableProgramGroupPage=yes +; Uncomment the following line to run in non administrative install mode (install for current user only.) +;PrivilegesRequired=lowest +PrivilegesRequiredOverridesAllowed=dialog +OutputDir=D:\GitHub\ChatBox\outpu +OutputBaseFilename=win-arm64 +SetupIconFile=D:\GitHub\ChatBox\favicon.ico +Compression=lzma +SolidCompression=yes +WizardStyle=modern + +[Languages] +Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl" + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked + +[Files] +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\i18n\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +; NOTE: Don't use "Flags: ignoreversion" on any shared system files + +[Registry] +Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue +Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey +Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0" +Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1""" +Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: "" + +[Icons] +Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" +Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon + +[Run] +Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent + diff --git a/build.iss b/build.iss index 0277c3f..4de27a6 100644 --- a/build.iss +++ b/build.iss @@ -1,19 +1,19 @@ ; Script generated by the Inno Setup Script Wizard. ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! -#define MyAppName "Chatbox" -#define MyAppVersion "1.0.1" -#define MyAppPublisher "Token" -#define MyAppURL "https://www.token-ai.cn" +#define MyAppName "ChatBox" +#define MyAppVersion "0.1.1" +#define MyAppPublisher "TokenAi" +#define MyAppURL "https://api.token-ai.cn" #define MyAppExeName "ChatBox.Desktop.exe" -#define MyAppAssocName MyAppName + ".exe" +#define MyAppAssocName MyAppName + "" #define MyAppAssocExt ".exe" #define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt [Setup] ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) -AppId={{F746F9FA-A30F-4762-80EA-24C025030A93} +AppId={{1E9A7D67-5468-469D-86AB-FFE07136EBD1} AppName={#MyAppName} AppVersion={#MyAppVersion} ;AppVerName={#MyAppName} {#MyAppVersion} @@ -35,23 +35,23 @@ DisableProgramGroupPage=yes ; Uncomment the following line to run in non administrative install mode (install for current user only.) ;PrivilegesRequired=lowest PrivilegesRequiredOverridesAllowed=dialog -OutputDir=D:\AI\ChatBox\output -OutputBaseFilename=Chatbox -SetupIconFile=D:\AI\Gitea\ChatBox\src\ChatBox.Desktop\logo.ico +OutputDir=D:\GitHub\ChatBox\outpu +OutputBaseFilename=win-64-framework +SetupIconFile=D:\GitHub\ChatBox\favicon.ico Compression=lzma SolidCompression=yes WizardStyle=modern [Languages] -Name: "english"; MessagesFile: "compiler:Default.isl" Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked [Files] -Source: "D:\AI\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion -Source: "D:\AI\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\i18n\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs ; NOTE: Don't use "Flags: ignoreversion" on any shared system files [Registry] diff --git a/src/ChatBox.Desktop/Program.cs b/src/ChatBox.Desktop/Program.cs index 9c1b4d2..c254264 100644 --- a/src/ChatBox.Desktop/Program.cs +++ b/src/ChatBox.Desktop/Program.cs @@ -11,6 +11,10 @@ public static void Main(string[] args) { try { + + HostApplication.Builder(); + + CrossPlatformCustomProtocolHelper.RegisterCustomProtocol(); var token = CrossPlatformCustomProtocolHelper.ParseCustomProtocolArgs(args); diff --git a/src/ChatBox.Logger/ChatBoxLogger.cs b/src/ChatBox.Logger/ChatBoxLogger.cs index ce4354f..4f6d797 100644 --- a/src/ChatBox.Logger/ChatBoxLogger.cs +++ b/src/ChatBox.Logger/ChatBoxLogger.cs @@ -2,43 +2,52 @@ namespace ChatBox.Logger { - public class ChatBoxLogger : ILogger - { - private readonly string _categoryName; - - public ChatBoxLogger(string categoryName) - { - _categoryName = categoryName; - } - - public IDisposable BeginScope(TState state) => null; - - public bool IsEnabled(LogLevel logLevel) => true; - - public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) - { - if (!IsEnabled(logLevel)) - return; - - var message = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logLevel}] {_categoryName}: {formatter(state, exception)}"; - if (exception != null) - { - message += $"\n{exception}"; - } - - File.AppendAllText(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "logs"), $"{DateTime.Now:yyyy-MM-dd}.log"), message + Environment.NewLine); - } - } - - public class ChatBoxLoggerProvider : ILoggerProvider - { - public ILogger CreateLogger(string categoryName) - { - return new ChatBoxLogger(categoryName); - } - - public void Dispose() - { - } - } + public class ChatBoxLogger : ILogger + { + private readonly string _categoryName; + + public ChatBoxLogger(string categoryName) + { + _categoryName = categoryName; + } + + public IDisposable BeginScope(TState state) => null; + + public bool IsEnabled(LogLevel logLevel) => true; + + public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) + { + if (!IsEnabled(logLevel)) + return; + + var message = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logLevel}] {_categoryName}: {formatter(state, exception)}"; + if (exception != null) + { + message += $"\n{exception}"; + } + + var info = new FileInfo(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "logs"), $"{DateTime.Now:yyyy-MM-dd}.log")); + + + if (info.Directory?.Exists == false) + { + info.Directory.Create(); + } + + + File.AppendAllText(info.FullName, message + Environment.NewLine); + } + } + + public class ChatBoxLoggerProvider : ILoggerProvider + { + public ILogger CreateLogger(string categoryName) + { + return new ChatBoxLogger(categoryName); + } + + public void Dispose() + { + } + } } diff --git a/src/ChatBox/App.axaml.cs b/src/ChatBox/App.axaml.cs index 727280e..dda49ef 100644 --- a/src/ChatBox/App.axaml.cs +++ b/src/ChatBox/App.axaml.cs @@ -1,15 +1,9 @@ -using System; using Avalonia; -using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Data.Core.Plugins; using Avalonia.Markup.Xaml; using Avalonia.Platform; -using ChatBox.Pages; -using ChatBox.ViewModels; using ChatBox.Views; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; namespace ChatBox; @@ -22,12 +16,10 @@ public override void Initialize() public override void OnFrameworkInitializationCompleted() { - var host = HostApplication.Builder(); - if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { BindingPlugins.DataValidators.RemoveAt(0); - desktop.MainWindow = host.Services.GetRequiredService(); + desktop.MainWindow = HostApplication.Services.GetRequiredService(); // εˆ›ε»Ίζ‰˜η›˜ var trayIcon = new TrayIcon(); @@ -49,7 +41,7 @@ public override void OnFrameworkInitializationCompleted() } else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) { - singleViewPlatform.MainView = host.Services.GetRequiredService(); + singleViewPlatform.MainView = HostApplication.Services.GetRequiredService(); } base.OnFrameworkInitializationCompleted();