Skip to content

Commit

Permalink
在数据库缺失时弹出提醒 (#52)
Browse files Browse the repository at this point in the history
* 在数据库缺失时弹出提醒

* Update
  • Loading branch information
Richasy authored Jul 8, 2024
1 parent aa23429 commit 9cb7670
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const en = defineConfig({
{ text: 'Installation', link: '/en/install' },
{ text: 'Supported services', link: '/en/services' },
{ text: 'Work directory & Data sync', link: '/en/work-directory' },
{ text: 'FAQ', link: './faq' },
{ text: 'V1 data migration', link: '/en/v1-migration' },
{ text: 'Privacy Policy', link: '/en/privacy' }
]
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/zh.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const zh = defineConfig({
{ text: '安装应用', link: '/install' },
{ text: '支持的服务', link: '/services' },
{ text: '工作目录与数据同步', link: '/work-directory' },
{ text: '常见问题', link: './faq' },
{ text: 'V1 数据迁移', link: '/v1-migration' },
{ text: '隐私策略', link: '/privacy' }
]
Expand Down
15 changes: 15 additions & 0 deletions docs/en/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# FAQ

## I can't configure the service (the service setup page is blank)

When the app initializes, it attempts to copy the blank database file in the app to the working directory, but in a few rare cases, there may be an issue where the copy fails.

If the necessary database is not copied to the working directory, you will observe that the app is unable to configure various AI services, resulting in a blank page for the relevant service on the settings page.

In this case, you need to manually download the database file and copy it to the working directory.

The specific steps are as follows:

1. Download [database.zip](https://github.com/Richasy/Rodel.Agent/releases/download/empty-db/database.zip) to your local machine.
2. Extract the database file (with the `.db` extension) from the zip file to your working directory.
3. Restart the application.
15 changes: 15 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 常见问题

## 我无法配置服务(服务设置页面空白)

应用在初始化工作目录时会尝试把应用内的空白数据库文件复制到工作目录中,但是在少数未知情况下,会出现无法复制的情况。

一旦必要的数据库没有复制到工作目录,你就会观察到应用无法配置各种 AI 服务,表现为设置页面的相关服务页面会显示一片空白。

这需要你手动下载数据库文件,然后复制到工作目录。

具体操作步骤如下:

1. 下载 [database.zip](https://github.com/Richasy/Rodel.Agent/releases/download/empty-db/database.zip) 到本地。
2. 将其中的数据库文件(后缀为 `.db`)解压到您的工作目录中。
3. 重启应用程序。
36 changes: 36 additions & 0 deletions src/Desktop/RodelAgent.UI/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using Microsoft.UI.Xaml.Media.Animation;
using RodelAgent.Interfaces;
using RodelAgent.UI.Models.Constants;
using RodelAgent.UI.Toolkits;
using RodelAgent.UI.ViewModels.Pages;
using Windows.System;

namespace RodelAgent.UI.Pages;

Expand All @@ -13,6 +15,7 @@ namespace RodelAgent.UI.Pages;
public sealed partial class SettingsPage : SettingsPageBase
{
private SettingSectionType? _previousSection;
private bool _isDatabaseVerified;

/// <summary>
/// Initializes a new instance of the <see cref="SettingsPage"/> class.
Expand All @@ -27,6 +30,10 @@ public SettingsPage()
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
=> SaveSettings();

/// <inheritdoc/>
protected override async void OnPageLoaded()
=> await VerifyDatabaseAsync();

/// <inheritdoc/>
protected override void OnPageUnloaded()
=> SaveSettings();
Expand Down Expand Up @@ -68,6 +75,35 @@ private void OnSettingSectionChanged(SelectorBar sender, SelectorBarSelectionCha
SectionFrame.Navigate(pageType, default, new SlideNavigationTransitionInfo { Effect = animationType });
}
}

private async Task VerifyDatabaseAsync()
{
if (_isDatabaseVerified)
{
return;
}

var workDir = SettingsToolkit.ReadLocalSetting(SettingNames.WorkingDirectory, string.Empty);
_isDatabaseVerified = File.Exists(Path.Combine(workDir, "secret.db"));
if (!_isDatabaseVerified)
{
var dialog = new ContentDialog
{
Title = ResourceToolkit.GetLocalizedString(StringNames.DatabaseMissed),
Content = ResourceToolkit.GetLocalizedString(StringNames.DatabaseMissedDescription),
PrimaryButtonText = ResourceToolkit.GetLocalizedString(StringNames.Solution),
CloseButtonText = ResourceToolkit.GetLocalizedString(StringNames.Cancel),
DefaultButton = ContentDialogButton.Primary,
XamlRoot = XamlRoot,
};

var result = await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
await Launcher.LaunchUriAsync(new Uri("https://agent.richasy.net/faq"));
}
}
}
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@
<data name="DashScope" xml:space="preserve">
<value>Dash Scope</value>
</data>
<data name="DatabaseMissed" xml:space="preserve">
<value>Database Missing</value>
</data>
<data name="DatabaseMissedDescription" xml:space="preserve">
<value>It appears that there was a problem during database initialization. The necessary database was not detected in your working directory. Please click the button below to see how to fix this problem.</value>
</data>
<data name="Delete" xml:space="preserve">
<value>Delete</value>
</data>
Expand Down Expand Up @@ -967,6 +973,9 @@ You can manually adjust the limit, and the application will capture the specifie
<data name="SmartRename" xml:space="preserve">
<value>Smart rename</value>
</data>
<data name="Solution" xml:space="preserve">
<value>Solution</value>
</data>
<data name="SourceLanguage" xml:space="preserve">
<value>Source language</value>
</data>
Expand Down
9 changes: 9 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@
<data name="DashScope" xml:space="preserve">
<value>阿里灵积</value>
</data>
<data name="DatabaseMissed" xml:space="preserve">
<value>数据库缺失</value>
</data>
<data name="DatabaseMissedDescription" xml:space="preserve">
<value>看上去在数据库初始化的过程中出现了问题,未在你的工作目录中检测到必须的数据库。请点击下方的按钮查看如何修复这个问题</value>
</data>
<data name="Delete" xml:space="preserve">
<value>删除</value>
</data>
Expand Down Expand Up @@ -967,6 +973,9 @@
<data name="SmartRename" xml:space="preserve">
<value>智能重命名</value>
</data>
<data name="Solution" xml:space="preserve">
<value>解决方案</value>
</data>
<data name="SourceLanguage" xml:space="preserve">
<value>源语言</value>
</data>
Expand Down

0 comments on commit 9cb7670

Please sign in to comment.