feat: 限制只能打开 md/txt 文件,新建文件仅保存为 md
- 打开对话框移除「所有文件」选项 - 保存对话框移除 .txt 选项 - 拖拽打开增加扩展名过滤 - 浏览器降级路径同步过滤
This commit is contained in:
@@ -90,8 +90,7 @@ async function showOpenDialog() {
|
|||||||
const result = await dialog.showOpenDialog(mainWindow, {
|
const result = await dialog.showOpenDialog(mainWindow, {
|
||||||
properties: ['openFile'],
|
properties: ['openFile'],
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'Markdown 文件', extensions: ['md', 'markdown', 'txt'] },
|
{ name: 'Markdown 文件', extensions: ['md', 'markdown', 'txt'] }
|
||||||
{ name: '所有文件', extensions: ['*'] }
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
if (!result.canceled && result.filePaths.length > 0) {
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
@@ -169,8 +168,7 @@ ipcMain.handle('file:save', async (event, { filePath, content }) => {
|
|||||||
} else {
|
} else {
|
||||||
const result = await dialog.showSaveDialog(mainWindow, {
|
const result = await dialog.showSaveDialog(mainWindow, {
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'Markdown 文件', extensions: ['md'] },
|
{ name: 'Markdown 文件', extensions: ['md'] }
|
||||||
{ name: '文本文件', extensions: ['txt'] }
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
@@ -192,8 +190,7 @@ ipcMain.handle('file:saveAs', async (event, { content }) => {
|
|||||||
try {
|
try {
|
||||||
const result = await dialog.showSaveDialog(mainWindow, {
|
const result = await dialog.showSaveDialog(mainWindow, {
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'Markdown 文件', extensions: ['md'] },
|
{ name: 'Markdown 文件', extensions: ['md'] }
|
||||||
{ name: '文本文件', extensions: ['txt'] }
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
|
|||||||
@@ -429,6 +429,8 @@
|
|||||||
input.multiple = true;
|
input.multiple = true;
|
||||||
input.onchange = (e) => {
|
input.onchange = (e) => {
|
||||||
Array.from(e.target.files).forEach(file => {
|
Array.from(e.target.files).forEach(file => {
|
||||||
|
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase();
|
||||||
|
if (!['.md', '.markdown', '.txt'].includes(ext)) return;
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (ev) => {
|
reader.onload = (ev) => {
|
||||||
createNewTab(file.name, ev.target.result);
|
createNewTab(file.name, ev.target.result);
|
||||||
@@ -584,8 +586,11 @@
|
|||||||
dropOverlay.classList.add('hidden');
|
dropOverlay.classList.add('hidden');
|
||||||
|
|
||||||
const files = e.dataTransfer.files;
|
const files = e.dataTransfer.files;
|
||||||
|
const allowedExts = ['.md', '.markdown', '.txt'];
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePath = file.path;
|
const filePath = file.path;
|
||||||
|
const ext = filePath ? filePath.substring(filePath.lastIndexOf('.')).toLowerCase() : '';
|
||||||
|
if (!allowedExts.includes(ext)) continue;
|
||||||
if (filePath && typeof window.electronAPI !== 'undefined') {
|
if (filePath && typeof window.electronAPI !== 'undefined') {
|
||||||
const result = await window.electronAPI.readFile(filePath);
|
const result = await window.electronAPI.readFile(filePath);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user