🚨 Format code

This commit is contained in:
2025-09-24 21:44:42 +08:00
parent 1462d8a753
commit f5bfff80b7
76 changed files with 839 additions and 863 deletions

View File

@@ -1,105 +1,105 @@
import {defineStore} from 'pinia'
import {computed, readonly, ref} from 'vue'
import type {GitBackupConfig} from '@/../bindings/voidraft/internal/models'
import {BackupService} from '@/../bindings/voidraft/internal/services'
import {useConfigStore} from '@/stores/configStore'
import {defineStore} from 'pinia';
import {computed, readonly, ref} from 'vue';
import type {GitBackupConfig} from '@/../bindings/voidraft/internal/models';
import {BackupService} from '@/../bindings/voidraft/internal/services';
import {useConfigStore} from '@/stores/configStore';
/**
* Minimalist Backup Store
*/
export const useBackupStore = defineStore('backup', () => {
// Core state
const config = ref<GitBackupConfig | null>(null)
const isPushing = ref(false)
const error = ref<string | null>(null)
const isInitialized = ref(false)
const config = ref<GitBackupConfig | null>(null);
const isPushing = ref(false);
const error = ref<string | null>(null);
const isInitialized = ref(false);
// Backup result states
const pushSuccess = ref(false)
const pushError = ref(false)
const pushSuccess = ref(false);
const pushError = ref(false);
// Timers for auto-hiding status icons and error messages
let pushStatusTimer: number | null = null
let errorTimer: number | null = null
let pushStatusTimer: number | null = null;
let errorTimer: number | null = null;
// 获取configStore
const configStore = useConfigStore()
const configStore = useConfigStore();
// Computed properties
const isEnabled = computed(() => configStore.config.backup.enabled)
const isConfigured = computed(() => configStore.config.backup.repo_url)
const isEnabled = computed(() => configStore.config.backup.enabled);
const isConfigured = computed(() => configStore.config.backup.repo_url);
// 清除状态显示
const clearPushStatus = () => {
if (pushStatusTimer !== null) {
window.clearTimeout(pushStatusTimer)
pushStatusTimer = null
window.clearTimeout(pushStatusTimer);
pushStatusTimer = null;
}
pushSuccess.value = false
pushError.value = false
}
pushSuccess.value = false;
pushError.value = false;
};
// 清除错误信息和错误图标
const clearError = () => {
if (errorTimer !== null) {
window.clearTimeout(errorTimer)
errorTimer = null
window.clearTimeout(errorTimer);
errorTimer = null;
}
error.value = null
pushError.value = false
}
error.value = null;
pushError.value = false;
};
// 设置错误信息和错误图标并自动清除
const setErrorWithAutoHide = (errorMessage: string, hideAfter: number = 3000) => {
clearError()
clearPushStatus()
error.value = errorMessage
pushError.value = true
clearError();
clearPushStatus();
error.value = errorMessage;
pushError.value = true;
errorTimer = window.setTimeout(() => {
error.value = null
pushError.value = false
errorTimer = null
}, hideAfter)
}
error.value = null;
pushError.value = false;
errorTimer = null;
}, hideAfter);
};
// Push to remote repository
const pushToRemote = async () => {
if (isPushing.value || !isConfigured.value) return
if (isPushing.value || !isConfigured.value) return;
isPushing.value = true
clearError() // 清除之前的错误信息
clearPushStatus()
isPushing.value = true;
clearError(); // 清除之前的错误信息
clearPushStatus();
try {
await BackupService.PushToRemote()
await BackupService.PushToRemote();
// 显示成功状态并设置3秒后自动消失
pushSuccess.value = true
pushSuccess.value = true;
pushStatusTimer = window.setTimeout(() => {
pushSuccess.value = false
pushStatusTimer = null
}, 3000)
pushSuccess.value = false;
pushStatusTimer = null;
}, 3000);
} catch (err: any) {
setErrorWithAutoHide(err?.message || 'Backup operation failed')
setErrorWithAutoHide(err?.message || 'Backup operation failed');
} finally {
isPushing.value = false
isPushing.value = false;
}
}
};
// 初始化备份服务
const initialize = async () => {
if (!isEnabled.value) return
if (!isEnabled.value) return;
// 避免重复初始化
if (isInitialized.value) return
if (isInitialized.value) return;
clearError() // 清除之前的错误信息
clearError(); // 清除之前的错误信息
try {
await BackupService.Initialize()
isInitialized.value = true
await BackupService.Initialize();
isInitialized.value = true;
} catch (err: any) {
setErrorWithAutoHide(err?.message || 'Failed to initialize backup service')
setErrorWithAutoHide(err?.message || 'Failed to initialize backup service');
}
}
};
return {
@@ -119,5 +119,5 @@ export const useBackupStore = defineStore('backup', () => {
pushToRemote,
initialize,
clearError
}
})
};
});

View File

@@ -43,7 +43,7 @@ const getBrowserLanguage = (): SupportedLocaleType => {
};
export const useConfigStore = defineStore('config', () => {
const {locale, t} = useI18n();
const {locale} = useI18n();
// 响应式状态
const state = reactive({
@@ -193,7 +193,7 @@ export const useConfigStore = defineStore('config', () => {
state.isLoading = true;
try {
await ConfigService.ResetConfig()
await ConfigService.ResetConfig();
const appConfig = await ConfigService.GetConfig();
if (appConfig) {
state.config = JSON.parse(JSON.stringify(appConfig)) as AppConfig;
@@ -230,7 +230,7 @@ export const useConfigStore = defineStore('config', () => {
// 同步前端语言设置
const frontendLocale = ConfigUtils.backendLanguageToFrontend(state.config.appearance.language);
locale.value = frontendLocale as any;
} catch (error) {
} catch (_error) {
const browserLang = getBrowserLanguage();
locale.value = browserLang as any;
}

View File

@@ -133,7 +133,7 @@ export const useDocumentStore = defineStore('document', () => {
};
// 更新文档元数据
const updateDocumentMetadata = async (docId: number, title: string, newPath?: string): Promise<boolean> => {
const updateDocumentMetadata = async (docId: number, title: string): Promise<boolean> => {
try {
await DocumentService.UpdateDocumentTitle(docId, title);

View File

@@ -1,40 +1,40 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { Extension, ExtensionID } from '@/../bindings/voidraft/internal/models/models'
import { ExtensionService } from '@/../bindings/voidraft/internal/services'
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
import { Extension, ExtensionID } from '@/../bindings/voidraft/internal/models/models';
import { ExtensionService } from '@/../bindings/voidraft/internal/services';
export const useExtensionStore = defineStore('extension', () => {
// 扩展配置数据
const extensions = ref<Extension[]>([])
const extensions = ref<Extension[]>([]);
// 获取启用的扩展
const enabledExtensions = computed(() =>
extensions.value.filter(ext => ext.enabled)
)
);
// 获取启用的扩展ID列表
const enabledExtensionIds = computed(() =>
enabledExtensions.value.map(ext => ext.id)
)
);
/**
* 从后端加载扩展配置
*/
const loadExtensions = async (): Promise<void> => {
try {
extensions.value = await ExtensionService.GetAllExtensions()
extensions.value = await ExtensionService.GetAllExtensions();
} catch (err) {
console.error('[ExtensionStore] Failed to load extensions:', err)
console.error('[ExtensionStore] Failed to load extensions:', err);
}
}
};
/**
* 获取扩展配置
*/
const getExtensionConfig = (id: ExtensionID): any => {
const extension = extensions.value.find(ext => ext.id === id)
return extension?.config ?? {}
}
const extension = extensions.value.find(ext => ext.id === id);
return extension?.config ?? {};
};
return {
// 状态
@@ -45,5 +45,5 @@ export const useExtensionStore = defineStore('extension', () => {
// 方法
loadExtensions,
getExtensionConfig,
}
})
};
});

View File

@@ -1,72 +1,68 @@
import {defineStore} from 'pinia'
import {computed, ref} from 'vue'
import {ExtensionID, KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models'
import {GetAllKeyBindings} from '@/../bindings/voidraft/internal/services/keybindingservice'
import {defineStore} from 'pinia';
import {computed, ref} from 'vue';
import {ExtensionID, KeyBinding, KeyBindingCommand} from '@/../bindings/voidraft/internal/models/models';
import {GetAllKeyBindings} from '@/../bindings/voidraft/internal/services/keybindingservice';
export const useKeybindingStore = defineStore('keybinding', () => {
// 快捷键配置数据
const keyBindings = ref<KeyBinding[]>([])
const keyBindings = ref<KeyBinding[]>([]);
// 获取启用的快捷键
const enabledKeyBindings = computed(() =>
keyBindings.value.filter(kb => kb.enabled)
)
);
// 按扩展分组的快捷键
const keyBindingsByExtension = computed(() => {
const groups = new Map<ExtensionID, KeyBinding[]>()
const groups = new Map<ExtensionID, KeyBinding[]>();
for (const binding of keyBindings.value) {
if (!groups.has(binding.extension)) {
groups.set(binding.extension, [])
groups.set(binding.extension, []);
}
groups.get(binding.extension)!.push(binding)
groups.get(binding.extension)!.push(binding);
}
return groups
})
return groups;
});
// 获取指定扩展的快捷键
const getKeyBindingsByExtension = computed(() =>
(extension: ExtensionID) =>
keyBindings.value.filter(kb => kb.extension === extension)
)
);
// 按命令获取快捷键
const getKeyBindingByCommand = computed(() =>
(command: KeyBindingCommand) =>
keyBindings.value.find(kb => kb.command === command)
)
);
/**
* 从后端加载快捷键配置
*/
const loadKeyBindings = async (): Promise<void> => {
try {
keyBindings.value = await GetAllKeyBindings()
} catch (err) {
throw err
}
}
keyBindings.value = await GetAllKeyBindings();
};
/**
* 检查是否存在指定命令的快捷键
*/
const hasCommand = (command: KeyBindingCommand): boolean => {
return keyBindings.value.some(kb => kb.command === command && kb.enabled)
}
return keyBindings.value.some(kb => kb.command === command && kb.enabled);
};
/**
* 获取扩展相关的所有扩展ID
*/
const getAllExtensionIds = computed(() => {
const extensionIds = new Set<ExtensionID>()
const extensionIds = new Set<ExtensionID>();
for (const binding of keyBindings.value) {
extensionIds.add(binding.extension)
extensionIds.add(binding.extension);
}
return Array.from(extensionIds)
})
return Array.from(extensionIds);
});
return {
// 状态
@@ -82,5 +78,5 @@ export const useKeybindingStore = defineStore('keybinding', () => {
// 方法
loadKeyBindings,
hasCommand,
}
})
};
});

View File

@@ -43,7 +43,7 @@ export const useSystemStore = defineStore('system', () => {
try {
environment.value = await runtime.System.Environment();
} catch (err) {
} catch (_err) {
environment.value = null;
} finally {
isLoading.value = false;

View File

@@ -153,7 +153,7 @@ export const useTranslationStore = defineStore('translation', () => {
defaultTargetLang.value = validatedLang;
}
}
} catch (err) {
} catch (_err) {
error.value = 'no available translators';
}
};

View File

@@ -1,116 +1,116 @@
import {defineStore} from 'pinia'
import {computed, ref} from 'vue'
import {CheckForUpdates, ApplyUpdate, RestartApplication} from '@/../bindings/voidraft/internal/services/selfupdateservice'
import {SelfUpdateResult} from '@/../bindings/voidraft/internal/services/models'
import {useConfigStore} from './configStore'
import * as runtime from "@wailsio/runtime"
import {defineStore} from 'pinia';
import {computed, ref} from 'vue';
import {CheckForUpdates, ApplyUpdate, RestartApplication} from '@/../bindings/voidraft/internal/services/selfupdateservice';
import {SelfUpdateResult} from '@/../bindings/voidraft/internal/services/models';
import {useConfigStore} from './configStore';
import * as runtime from "@wailsio/runtime";
export const useUpdateStore = defineStore('update', () => {
// 状态
const isChecking = ref(false)
const isUpdating = ref(false)
const updateResult = ref<SelfUpdateResult | null>(null)
const hasCheckedOnStartup = ref(false)
const updateSuccess = ref(false)
const errorMessage = ref('')
const isChecking = ref(false);
const isUpdating = ref(false);
const updateResult = ref<SelfUpdateResult | null>(null);
const hasCheckedOnStartup = ref(false);
const updateSuccess = ref(false);
const errorMessage = ref('');
// 计算属性
const hasUpdate = computed(() => updateResult.value?.hasUpdate || false)
const hasUpdate = computed(() => updateResult.value?.hasUpdate || false);
// 检查更新
const checkForUpdates = async (): Promise<boolean> => {
if (isChecking.value) return false
if (isChecking.value) return false;
// 重置错误信息
errorMessage.value = ''
isChecking.value = true
errorMessage.value = '';
isChecking.value = true;
try {
const result = await CheckForUpdates()
const result = await CheckForUpdates();
if (result) {
updateResult.value = result
updateResult.value = result;
if (result.error) {
errorMessage.value = result.error
return false
errorMessage.value = result.error;
return false;
}
return true
return true;
}
return false
return false;
} catch (error) {
errorMessage.value = error instanceof Error ? error.message : 'Network error'
return false
errorMessage.value = error instanceof Error ? error.message : 'Network error';
return false;
} finally {
isChecking.value = false
isChecking.value = false;
}
}
};
// 应用更新
const applyUpdate = async (): Promise<boolean> => {
if (isUpdating.value) return false
if (isUpdating.value) return false;
// 重置错误信息
errorMessage.value = ''
isUpdating.value = true
errorMessage.value = '';
isUpdating.value = true;
try {
const result = await ApplyUpdate()
const result = await ApplyUpdate();
if (result) {
updateResult.value = result
updateResult.value = result;
if (result.error) {
errorMessage.value = result.error
return false
errorMessage.value = result.error;
return false;
}
if (result.updateApplied) {
updateSuccess.value = true
return true
updateSuccess.value = true;
return true;
}
}
return false
return false;
} catch (error) {
errorMessage.value = error instanceof Error ? error.message : 'Update failed'
return false
errorMessage.value = error instanceof Error ? error.message : 'Update failed';
return false;
} finally {
isUpdating.value = false
isUpdating.value = false;
}
}
};
// 重启应用
const restartApplication = async (): Promise<boolean> => {
try {
await RestartApplication()
return true
await RestartApplication();
return true;
} catch (error) {
errorMessage.value = error instanceof Error ? error.message : 'Restart failed'
return false
errorMessage.value = error instanceof Error ? error.message : 'Restart failed';
return false;
}
}
};
// 启动时检查更新
const checkOnStartup = async () => {
if (hasCheckedOnStartup.value) return
const configStore = useConfigStore()
if (hasCheckedOnStartup.value) return;
const configStore = useConfigStore();
if (configStore.config.updates.autoUpdate) {
await checkForUpdates()
await checkForUpdates();
}
hasCheckedOnStartup.value = true
}
hasCheckedOnStartup.value = true;
};
// 打开发布页面
const openReleaseURL = async () => {
if (updateResult.value?.assetURL) {
await runtime.Browser.OpenURL(updateResult.value.assetURL)
await runtime.Browser.OpenURL(updateResult.value.assetURL);
}
}
};
// 重置状态
const reset = () => {
updateResult.value = null
isChecking.value = false
isUpdating.value = false
updateSuccess.value = false
errorMessage.value = ''
}
updateResult.value = null;
isChecking.value = false;
isUpdating.value = false;
updateSuccess.value = false;
errorMessage.value = '';
};
return {
// 状态
@@ -131,5 +131,5 @@ export const useUpdateStore = defineStore('update', () => {
checkOnStartup,
openReleaseURL,
reset
}
})
};
});