Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lang/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// 导入国际化JSON文件
// 导入国际化JSON文件(合并模式)
import langJSON from './index.json'
(function () {
// 定义翻译函数
Expand Down Expand Up @@ -43,7 +43,7 @@
globalThis.$t = globalThis.$t || $t;
// 将简单翻译函数挂载到globalThis对象上
globalThis.$$t = $$t;
// 定义从JSON文件中获取指定键的语言对象的方法
// 定义从JSON文件中获取指定键的语言对象的方法(合并模式)
globalThis._getJSONKey = function (key, insertJSONObj = undefined) {
// 获取JSON对象
const JSONObj = insertJSONObj;
Expand Down
8 changes: 8 additions & 0 deletions lang/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2318,5 +2318,13 @@
"ru": "",
"en": "",
"fr": ""
},
"9j0b1b6g": {
"zh-cn": "\n<br />\n\n# MilkUp\n\n<br />\n\n> 这是一段测试文字\n\n<br />\n\n***\n\n<br />\n\n* item1\n* item2\n* item3\n\n代码:\n\n```JavaScript\nconst text = \"Hello Word!\"\nconsole.log(text)\n```\n\n<br />\n\n| 1 | 2 | 3 |\n| :- | :- | :- |\n| 1 | 2 | 3 |\n| 1 | 2 | 3 |\n\n\n",
"ja": "",
"ko": "",
"ru": "",
"en": "",
"fr": ""
}
}
3 changes: 2 additions & 1 deletion src/hooks/useContent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { computed, ref, watch } from 'vue'
import { changeSaveStatus } from '@/renderer/services'
import useTab from './useTab'

const contentInfo = {
Expand All @@ -20,7 +21,7 @@ watch(isModified, (newValue) => {
// 只有在有内容时才通知主进程保存状态
// 如果 markdown 为空且 originalContent 也为空,说明是新建文档,不需要通知
if (contentInfo.markdown.value || contentInfo.originalContent.value) {
window.electronAPI.changeSaveStatus(!newValue) // 通知主进程保存状态, 修改后(isModified==true) isSaved 为 false
changeSaveStatus(!newValue) // 通知主进程保存状态, 修改后(isModified==true) isSaved 为 false
}
}, { immediate: true })

Expand Down
15 changes: 8 additions & 7 deletions src/hooks/useContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nextTick, ref, watch } from 'vue'
import { closeDiscard, on as onIpc } from '@/renderer/services'
import emitter from '../renderer/events'
import useContent from './useContent'
import useFile from './useFile'
Expand Down Expand Up @@ -70,7 +71,7 @@ export function useContext() {

if (unsavedTabs.length === 0) {
// 没有未保存的tab,直接关闭
window.electronAPI.closeDiscard()
closeDiscard()
return
}

Expand Down Expand Up @@ -101,21 +102,21 @@ export function useContext() {
}

// 所有tab都处理完成,关闭应用
window.electronAPI.closeDiscard()
closeDiscard()
}

// 监听关闭确认事件
window.electronAPI.on('close:confirm', async () => {
onIpc('close:confirm', async () => {
await handleAppCloseConfirm()
})

// 监听保存触发事件
window.electronAPI.on('trigger-save', async () => {
onIpc('trigger-save', async () => {
await onSave()
})

// 监听自定义主题保存事件
window.electronAPI.on('custom-theme-saved', (theme) => {
onIpc('custom-theme-saved', (theme) => {
// 重新获取主题列表以包含新保存的主题
const { setTheme } = useTheme()
setTheme(theme.name)
Expand Down Expand Up @@ -181,7 +182,7 @@ export function useContext() {
// 保存成功
if (isLastTab) {
// 如果是最后一个tab,关闭应用
window.electronAPI.closeDiscard()
closeDiscard()
} else {
// 否则关闭tab
close(tabId)
Expand All @@ -199,7 +200,7 @@ export function useContext() {

if (isLastTab) {
// 如果是最后一个tab,关闭应用
window.electronAPI.closeDiscard()
closeDiscard()
} else {
// 否则关闭tab
close(tabId)
Expand Down
30 changes: 16 additions & 14 deletions src/hooks/useFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Tab } from '@/types/tab'
import { nextTick, onUnmounted } from 'vue'
import { processImagePaths } from '@/plugins/imagePathPlugin'
import emitter from '@/renderer/events'
import { getIsReadOnly, getPathForFile, on as onIpc, onOpenFileAtLaunch, openFile, readFileByPath, removeListener, saveFileAs } from '@/renderer/services'
import useContent from './useContent'
import useTab from './useTab'
import useTitle from './useTitle'
Expand All @@ -27,7 +28,7 @@ const {

async function onOpen(result?: { filePath: string, content: string } | null) {
if (!result) {
result = await window.electronAPI.openFile()
result = await openFile()
}
if (result) {
filePath.value = result.filePath
Expand All @@ -47,11 +48,11 @@ async function onOpen(result?: { filePath: string, content: string } | null) {
markdown.value = tab.content
originalContent.value = result.content
tab.isModified = false
tab.readOnly = await window.electronAPI.getIsReadOnly(result.filePath)
tab.readOnly = await getIsReadOnly(result.filePath)
} else {
// 创建新tab
const tab = await createTabFromFile(result.filePath, result.content)
tab.readOnly = await window.electronAPI.getIsReadOnly(result.filePath)
tab.readOnly = await getIsReadOnly(result.filePath)
// 更新当前内容状态
markdown.value = tab.content
originalContent.value = result.content
Expand Down Expand Up @@ -82,7 +83,7 @@ async function onSaveAs() {
// 先更新当前tab的内容
updateCurrentTabContent(markdown.value)

const result = await window.electronAPI.saveFileAs(markdown.value)
const result = await saveFileAs(markdown.value)
if (result) {
// 更新当前tab的文件路径
if (currentTab.value) {
Expand All @@ -105,10 +106,10 @@ function registerMenuEventsOnce() {
return
hasRegistered = true

window.electronAPI?.onOpenFileAtLaunch?.(async ({ filePath: launchFilePath, content }) => {
onOpenFileAtLaunch?.(async ({ filePath: launchFilePath, content }) => {
// 创建新tab
const tab = await createTabFromFile(launchFilePath, content)
tab.readOnly = await window.electronAPI.getIsReadOnly(launchFilePath)
tab.readOnly = await getIsReadOnly(launchFilePath)

// 更新当前内容状态
markdown.value = tab.content
Expand All @@ -121,8 +122,8 @@ function registerMenuEventsOnce() {
})
})

window.electronAPI.on?.('menu-open', onOpen)
window.electronAPI.on?.('menu-save', onSave)
onIpc('menu-open', onOpen)
onIpc('menu-save', onSave)

// 拖拽打开 Markdown 文件
const handleDragOver = (event: DragEvent) => {
Expand Down Expand Up @@ -186,9 +187,10 @@ function registerMenuEventsOnce() {

try {
// 使用 webUtils.getPathForFile 方法
const pathResult = window.electronAPI.getPathForFile(mdFile)
const pathResult = getPathForFile(mdFile)
fullPath = pathResult || null
} catch (error) {
console.error('获取文件完整路径失败:', error)
}

if (!fullPath) {
Expand All @@ -199,7 +201,7 @@ function registerMenuEventsOnce() {
}

if (fullPath) {
const result = await window.electronAPI.readFileByPath(fullPath)
const result = await readFileByPath(fullPath)
if (result) {
if (userChoice === 'overwrite') {
// 覆盖更新当前tab的文件信息
Expand All @@ -210,11 +212,11 @@ function registerMenuEventsOnce() {
markdown.value = processedContent
filePath.value = result.filePath
originalContent.value = result.content
currentTab.value!.readOnly = await window.electronAPI.getIsReadOnly(result.filePath)
currentTab.value!.readOnly = await getIsReadOnly(result.filePath)
} else {
// 创建新tab
const tab = await createTabFromFile(result.filePath, result.content)
tab.readOnly = await window.electronAPI.getIsReadOnly(result.filePath)
tab.readOnly = await getIsReadOnly(result.filePath)
// 更新当前内容
markdown.value = tab.content
filePath.value = result.filePath
Expand Down Expand Up @@ -297,8 +299,8 @@ emitter.on('tab:switch', tabSwitch)

export default function useFile() {
onUnmounted(() => {
window.electronAPI?.removeListener?.('menu-open', onOpen)
window.electronAPI?.removeListener?.('menu-save', onSave)
removeListener('menu-open', onOpen)
removeListener('menu-save', onSave)
})
return {
onOpen,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useFont.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Font, FontConfig, FontList, FontSizeConfig, FontSizeType, FontType } from '@/types/font'
import { computed, ref } from 'vue'
import { fontCssVariables, fontSizeCssVariables, fontSizeOptions } from '@/config/fonts'
import { getSystemFonts } from '@/renderer/services'
import { useConfig } from './useConfig'

// 系统字体列表
Expand All @@ -18,7 +19,7 @@ const currentFontSize = computed(() => getConf('font').size)
async function init() {
// 获取系统字体列表
try {
const systemFonts = await window.electronAPI.getSystemFonts()
const systemFonts = await getSystemFonts()
// Font 对象数组
fontList.value = systemFonts.map((fontName) => {
const name = fontName.replace(/^['"]|['"]$/g, '')
Expand Down
21 changes: 11 additions & 10 deletions src/hooks/useTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import autotoast from 'autotoast.js'
import { computed, nextTick, ref, watch } from 'vue'
import { processImagePaths, setCurrentMarkdownFilePath } from '@/plugins/imagePathPlugin'
import emitter from '@/renderer/events'
import { closeDiscard, getIsReadOnly, on as onIpc, onOpenFileAtLaunch, readFileByPath, saveFile, watchFiles } from '@/renderer/services'
import { createInertiaScroll } from '@/utils/inertiaScroll'
import { randomUUID } from '@/utils/tool'
import { isShowOutline } from './useOutline'
Expand All @@ -28,7 +29,7 @@ const defaultTab: Tab = {
}
tabs.value.push(defaultTab)
activeTabId.value = defaultTab.id
window.electronAPI?.onOpenFileAtLaunch((_payload) => {
onOpenFileAtLaunch((_payload) => {
if (tabs.value.length === 1 && tabs.value[0].id === defaultTabUUid && !tabs.value[0].isModified) {
tabs.value = []
}
Expand Down Expand Up @@ -142,7 +143,7 @@ async function saveCurrentTab(): Promise<boolean> {
return false

try {
const saved = await window.electronAPI.saveFile(currentTab.filePath, currentTab.content)
const saved = await saveFile(currentTab.filePath, currentTab.content)
if (saved) {
currentTab.filePath = saved
currentTab.name = getFileName(saved) // 更新标签名称
Expand Down Expand Up @@ -170,7 +171,7 @@ async function createTabFromFile(filePath: string, content: string): Promise<Tab
originalContent: content,
isModified: false,
scrollRatio: 0,
readOnly: await window.electronAPI?.getIsReadOnly(filePath) || false,
readOnly: await getIsReadOnly(filePath) || false,
}

return add(tab)
Expand All @@ -188,7 +189,7 @@ async function openFile(filePath: string): Promise<Tab | null> {
}

// 读取文件内容
const result = await window.electronAPI.readFileByPath(filePath)
const result = await readFileByPath(filePath)
if (result) {
// 如果当前有且只有一个默认未命名且未修改的tab,则复用该tab
if (
Expand All @@ -207,7 +208,7 @@ async function openFile(filePath: string): Promise<Tab | null> {
} else {
// 创建新tab
const newTab = await createTabFromFile(result.filePath, result.content)
newTab.readOnly = await window.electronAPI?.getIsReadOnly(filePath) || false
newTab.readOnly = await getIsReadOnly(filePath) || false
// 切换新tab
switchToTab(newTab.id)

Expand Down Expand Up @@ -377,7 +378,7 @@ function closeWithConfirm(id: string) {
// 如果没有未保存内容
if (isLastTab) {
// 如果是最后一个tab,直接关闭应用
window.electronAPI.closeDiscard()
closeDiscard()
} else {
// 否则直接关闭tab
close(id)
Expand Down Expand Up @@ -446,21 +447,21 @@ watch(
// 通知ipc
console.log('通知ipc', newFilePaths)

window.electronAPI.watchFiles(newFilePaths)
watchFiles(newFilePaths)
},
{
immediate: true,
},
)

// 文件变动回调事件
window.electronAPI.on?.('file:changed', async (paths) => {
onIpc('file:changed', async (paths) => {
const tab = tabs.value.find(tab => tab.filePath === paths)
if (!tab)
return

if (!tab.isModified) {
const result = await window.electronAPI.readFileByPath(paths)
const result = await readFileByPath(paths)
if (!result)
return
// 处理图片路径
Expand Down Expand Up @@ -489,7 +490,7 @@ window.electronAPI.on?.('file:changed', async (paths) => {
}

// 读取新文件内容
const result = await window.electronAPI.readFileByPath(paths)
const result = await readFileByPath(paths)
if (!result)
return

Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Theme, ThemeName } from '@/types/theme'
import autotoast from 'autotoast.js'
import { getCurrentInstance, onMounted, onUnmounted, ref, toRaw } from 'vue'
import { cssVarsDesMap, themeNameMap } from '@/config/theme'
import { openThemeEditor } from '@/renderer/services'
import { isThemeObject } from '@/types/theme'
import themeManager from '@/utils/themeManager'
import { randomUUID } from '@/utils/tool'
Expand Down Expand Up @@ -248,7 +249,7 @@ function addTempTheme(themeName?: ThemeName) {
// 存储到 localStorage
setEditingThemeToStorage(themeName)

window.electronAPI.openThemeEditor()
openThemeEditor()
} else {
// 新增主题:基于当前主题创建新主题
const themeList = themes.value.length ? themes.value : getThemes()
Expand Down Expand Up @@ -288,7 +289,7 @@ function addTempTheme(themeName?: ThemeName) {
}
}

window.electronAPI.openThemeEditor()
openThemeEditor()
}

// 删除本地主题
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useTitle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { computed, ref } from 'vue'
import { setTitle } from '@/renderer/services'
import useContent from './useContent'

const { filePath, isModified } = useContent()
Expand All @@ -13,7 +14,7 @@ const fileName = computed(() => {
function updateTitle() {
const name = (fileName.value || 'Untitled')
const prefix = isModified.value ? '*' : ''
window.electronAPI.setTitle(`${prefix}${name}`)
setTitle(`${prefix}${name}`)
title.value = `${prefix}${name}`
}

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useUpdateDialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import autotoast from 'autotoast.js'
import { ref } from 'vue'
import { openExternal } from '@/renderer/services'

export function useUpdateDialog() {
const isDialogVisible = ref(false)
Expand All @@ -25,7 +26,7 @@ export function useUpdateDialog() {
return
}
// 打开浏览器下载页面
window.electronAPI.openExternal(downloadUrl)
openExternal(downloadUrl)
hideDialog()
}
function handleLater() {
Expand Down
Loading