初始版本
This commit is contained in:
@@ -101,7 +101,7 @@ namespace TodoList
|
||||
try
|
||||
{
|
||||
_settingsService = new SettingsService();
|
||||
_dataService = new FileDataService();
|
||||
_dataService = new SqliteDataService();
|
||||
_shortcutService = new GlobalShortcutService();
|
||||
|
||||
var mainViewModel = new MainViewModel(_dataService, _settingsService);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Basic configuration
|
||||
$ScriptPath = $PSScriptRoot
|
||||
$ProjectFile = (Get-ChildItem -Path $ScriptPath -Filter "*.csproj" -File)[0].FullName
|
||||
$SetupScript = Join-Path $ScriptPath "setup.iss"
|
||||
|
||||
# Read version from project file
|
||||
$currentVersion = "1.0.0"
|
||||
[xml]$csproj = Get-Content $ProjectFile
|
||||
if ($csproj.Project.PropertyGroup.Version) {
|
||||
$currentVersion = $csproj.Project.PropertyGroup.Version
|
||||
}
|
||||
|
||||
# Increment version
|
||||
$versionParts = $currentVersion.Split(".")
|
||||
$patch = [int]$versionParts[2] + 1
|
||||
$newVersion = $versionParts[0] + "." + $versionParts[1] + "." + $patch
|
||||
|
||||
# Update project version
|
||||
$content = Get-Content $ProjectFile -Raw
|
||||
$content = $content -replace "<Version>.*</Version>", "<Version>$newVersion</Version>"
|
||||
Set-Content $ProjectFile -Value $content
|
||||
|
||||
# Update setup script version
|
||||
if (Test-Path $SetupScript) {
|
||||
$issContent = Get-Content $SetupScript
|
||||
for ($i = 0; $i -lt $issContent.Count; $i++) {
|
||||
if ($issContent[$i] -like '#define MyAppVersion *') {
|
||||
$issContent[$i] = '#define MyAppVersion "' + $newVersion + '"'
|
||||
break
|
||||
}
|
||||
}
|
||||
Set-Content $SetupScript -Value $issContent
|
||||
}
|
||||
|
||||
# Build project
|
||||
dotnet publish $ProjectFile -c Release -r win-x64 --self-contained false -p:PublishSingleFile=true
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Build failed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Package
|
||||
$ISCC = "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe"
|
||||
if (Test-Path $ISCC) {
|
||||
& $ISCC $SetupScript
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "Setup package created successfully!" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Error "Packaging failed"
|
||||
}
|
||||
} else {
|
||||
Write-Error "Inno Setup compiler not found"
|
||||
}
|
||||
@@ -25,6 +25,7 @@ namespace TodoList.Models
|
||||
public partial class TodoItem : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
[property: SQLite.PrimaryKey]
|
||||
private string id = Guid.NewGuid().ToString();
|
||||
|
||||
[ObservableProperty]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using SQLite;
|
||||
using TodoList.Models;
|
||||
|
||||
namespace TodoList.Services
|
||||
{
|
||||
public class SqliteDataService : IDataService
|
||||
{
|
||||
private readonly SQLiteAsyncConnection _database;
|
||||
|
||||
public SqliteDataService()
|
||||
{
|
||||
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
var folder = Path.Combine(appData, "TodoListApp");
|
||||
Directory.CreateDirectory(folder);
|
||||
var databasePath = Path.Combine(folder, "TodoList.sqlite");
|
||||
|
||||
_database = new SQLiteAsyncConnection(databasePath);
|
||||
_database.CreateTableAsync<TodoItem>().Wait();
|
||||
}
|
||||
|
||||
public async Task<List<TodoItem>> LoadTasksAsync()
|
||||
{
|
||||
return await _database.Table<TodoItem>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SaveTaskAsync(TodoItem task)
|
||||
{
|
||||
await _database.InsertOrReplaceAsync(task);
|
||||
}
|
||||
|
||||
public async Task SaveAllAsync(List<TodoItem> tasks)
|
||||
{
|
||||
await _database.RunInTransactionAsync(tran =>
|
||||
{
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
tran.InsertOrReplace(task);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteTaskAsync(string id)
|
||||
{
|
||||
await _database.DeleteAsync<TodoItem>(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
<Version>1.0.18</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -19,3 +21,21 @@
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace TodoList.ViewModels
|
||||
[NotifyPropertyChangedFor(nameof(FullShortcut))]
|
||||
private string shortcutModifiers;
|
||||
|
||||
public string AppVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "1.0.0";
|
||||
|
||||
public string FullShortcut
|
||||
{
|
||||
get
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
xmlns:models="clr-namespace:TodoList.Models"
|
||||
xmlns:converters="clr-namespace:TodoList.Converters"
|
||||
mc:Ignorable="d"
|
||||
Title="待办事项" Height="600" Width="450"
|
||||
Title="{Binding AppVersion, StringFormat='待办事项 v{0}'}" Height="600" Width="450"
|
||||
Background="#F5F5F7"
|
||||
Icon="/icon.ico"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
WindowStartupLocation="CenterScreen"
|
||||
PreviewKeyDown="Window_PreviewKeyDown">
|
||||
|
||||
<Window.Resources>
|
||||
<ObjectDataProvider x:Key="PriorityEnum" MethodName="GetValues"
|
||||
|
||||
@@ -19,6 +19,25 @@ namespace TodoList.Views
|
||||
// Verify if app shuts down? No, ShutdownMode is Explicit.
|
||||
}
|
||||
|
||||
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
// If settings are open, close settings?
|
||||
// But user requirement is "Equals pressing X button", which usually means Close/Hide window.
|
||||
// However, if we want better UX:
|
||||
if (DataContext is MainViewModel vm && vm.IsSettingsOpen)
|
||||
{
|
||||
vm.IsSettingsOpen = false;
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Default behavior: Close (Hide) Window
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShortcutBox_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#define MyAppName "TodoList"
|
||||
#define MyAppVersion "1.0.18"
|
||||
#define MyAppPublisher "ShaoHua"
|
||||
#define MyAppURL "https://git.we965.cn/Tools/TodoList"
|
||||
#define MyAppExeName "TodoList.exe"
|
||||
|
||||
[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={{8B8A6E3F-1234-5678-9ABC-DEF012345678}
|
||||
AppName={#MyAppName}
|
||||
AppVersion={#MyAppVersion}
|
||||
;AppVerName={#MyAppName} {#MyAppVersion}
|
||||
AppPublisher={#MyAppPublisher}
|
||||
AppPublisherURL={#MyAppURL}
|
||||
AppSupportURL={#MyAppURL}
|
||||
AppUpdatesURL={#MyAppURL}
|
||||
DefaultDirName={autopf}\{#MyAppName}
|
||||
DisableProgramGroupPage=yes
|
||||
; Remove the following line to run in administrative install mode (install for all users.)
|
||||
PrivilegesRequired=lowest
|
||||
OutputDir=Output
|
||||
OutputBaseFilename={#MyAppName}_Setup_v{#MyAppVersion}
|
||||
SetupIconFile=icon.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: "bin\Release\net8.0-windows\win-x64\publish\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||
|
||||
[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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user