diff --git a/public/libs/create-wiki.js b/public/libs/create-wiki.js index f0378a7a..7698eac0 100644 --- a/public/libs/create-wiki.js +++ b/public/libs/create-wiki.js @@ -42,4 +42,12 @@ async function createSubWiki(newFolderPath, folderName, mainWikiToLink) { } } -module.exports = { createWiki, createSubWiki }; +async function removeWiki(wikiPath, mainWikiToUnLink) { + if (mainWikiToUnLink) { + const subWikiName = path.basename(wikiPath); + await fs.remove(path.join(wikiPath, TIDDLERS_PATH, subWikiName)); + } + await fs.remove(wikiPath); +} + +module.exports = { createWiki, createSubWiki, removeWiki }; diff --git a/public/libs/workspaces-views.js b/public/libs/workspaces-views.js index 0e271ee8..0ba51058 100644 --- a/public/libs/workspaces-views.js +++ b/public/libs/workspaces-views.js @@ -25,8 +25,8 @@ const { const mainWindow = require('../windows/main'); -const createWorkspaceView = (name, isSubWiki, port, homeUrl, gitUrl, picture, transparentBackground) => { - const newWorkspace = createWorkspace(name, isSubWiki, port, homeUrl, gitUrl, transparentBackground); +const createWorkspaceView = (name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, picture, transparentBackground) => { + const newWorkspace = createWorkspace(name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, transparentBackground); setActiveWorkspace(newWorkspace.id); addView(mainWindow.get(), getWorkspace(newWorkspace.id)); diff --git a/public/libs/workspaces.js b/public/libs/workspaces.js index a9572044..ef2544b7 100644 --- a/public/libs/workspaces.js +++ b/public/libs/workspaces.js @@ -172,7 +172,7 @@ const removeWorkspace = (id) => { settings.delete(`workspaces.${v}.${id}`); }; -const createWorkspace = (name, isSubWiki, port, homeUrl, gitUrl, transparentBackground) => { +const createWorkspace = (name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, transparentBackground) => { const newId = uuidv1(); // find largest order @@ -188,6 +188,7 @@ const createWorkspace = (name, isSubWiki, port, homeUrl, gitUrl, transparentBack active: false, hibernated: false, isSubWiki, + mainWikiToLink, port, homeUrl, gitUrl, diff --git a/public/listeners/index.js b/public/listeners/index.js index 44179ae7..ea824d16 100755 --- a/public/listeners/index.js +++ b/public/listeners/index.js @@ -3,7 +3,7 @@ const { BrowserView, Notification, app, dialog, ipcMain, nativeTheme, shell } = const { autoUpdater } = require('electron-updater'); const { initWikiGit } = require('../libs/git'); -const { createWiki, createSubWiki } = require('../libs/create-wiki'); +const { createWiki, createSubWiki, removeWiki } = require('../libs/create-wiki'); const startNodeJSWiki = require('../libs/wiki/start-nodejs-wiki'); const { ICON_PATH, REACT_PATH, DESKTOP_PATH } = require('../constants/paths'); @@ -86,9 +86,6 @@ const loadListeners = () => { try { await initWikiGit(wikiFolderPath, githubRepoUrl, userInfo); } catch (error) { - const fs = require('fs') - console.error(Object.keys(error)); - fs.writeFileSync('/Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/aaa.txt', JSON.stringify(error.data), 'utf-8') return String(error); } }); @@ -265,8 +262,8 @@ const loadListeners = () => { e.returnValue = workspaces; }); - ipcMain.on('request-create-workspace', (e, name, isSubWiki, port, homeUrl, gitUrl, picture, transparentBackground) => { - createWorkspaceView(name, isSubWiki, port, homeUrl, gitUrl, picture, transparentBackground); + ipcMain.on('request-create-workspace', (e, name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, picture, transparentBackground) => { + createWorkspaceView(name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, picture, transparentBackground); createMenu(); }); @@ -315,8 +312,8 @@ const loadListeners = () => { dialog .showMessageBox(mainWindow.get(), { type: 'question', - buttons: ['Remove Workspace', 'Cancel'], - message: 'Are you sure? All browsing data of this workspace will be wiped. This action cannot be undone.', + buttons: ['仅移除工作区', '移除工作区并删除Wiki文件夹','取消'], + message: '你确定要移除这个工作区吗?移除工作区会删除本应用中的工作区,但不会删除硬盘上的文件夹。如果你选择一并删除Wiki文件夹,则所有内容都会被被删除。', cancelId: 1, }) .then(({ response }) => { @@ -324,8 +321,15 @@ const loadListeners = () => { removeWorkspaceView(id); createMenu(); } + // eslint-disable-next-line promise/always-return + if (response === 1) { + const workspace = getWorkspace(id) + removeWorkspaceView(id); + removeWiki(workspace.name, workspace.isSubWiki && workspace.mainWikiToLink) + createMenu(); + } }) - .catch(console.log); // eslint-disable-line + .catch(console.log); }); ipcMain.on('request-set-workspace', (e, id, opts) => { diff --git a/src/components/dialog-add-workspace/done-button.js b/src/components/dialog-add-workspace/done-button.js index 03e5f76e..772f6c7f 100644 --- a/src/components/dialog-add-workspace/done-button.js +++ b/src/components/dialog-add-workspace/done-button.js @@ -51,6 +51,7 @@ function DoneButton({ const workspaceFormData = { name: wikiFolderLocation, isSubWiki: !isCreateMainWorkspace, + mainWikiToLink, port: wikiPort, homeUrl: `http://localhost:${wikiPort}/`, gitUrl: githubWikiUrl, // don't need .git suffix diff --git a/src/senders/index.js b/src/senders/index.js index ad9c8952..66301c7d 100644 --- a/src/senders/index.js +++ b/src/senders/index.js @@ -62,8 +62,8 @@ export const countWorkspace = () => ipcRenderer.sendSync('count-workspace'); export const getWorkspace = (id: string) => ipcRenderer.sendSync('get-workspace', id); export const getWorkspaces = () => ipcRenderer.sendSync('get-workspaces'); export const requestClearBrowsingData = () => ipcRenderer.send('request-clear-browsing-data'); -export const requestCreateWorkspace = (name, isSubWiki, port, homeUrl, gitUrl, picture, transparentBackground) => - ipcRenderer.send('request-create-workspace', name, isSubWiki, port, homeUrl, picture, transparentBackground); +export const requestCreateWorkspace = (name, isSubWiki, mainWikiToLink, port, homeUrl, gitUrl, picture, transparentBackground) => + ipcRenderer.send('request-create-workspace', name, isSubWiki, mainWikiToLink, port, homeUrl, picture, transparentBackground); export const requestHibernateWorkspace = id => ipcRenderer.send('request-hibernate-workspace', id); export const requestOpenUrlInWorkspace = (url, id) => ipcRenderer.send('request-open-url-in-workspace', url, id); export const requestRealignActiveWorkspace = () => ipcRenderer.send('request-realign-active-workspace'); diff --git a/src/state/dialog-add-workspace/actions.js b/src/state/dialog-add-workspace/actions.js index c4e57a0d..fdb413da 100755 --- a/src/state/dialog-add-workspace/actions.js +++ b/src/state/dialog-add-workspace/actions.js @@ -43,6 +43,7 @@ export const saveCreatedWiki = () => (dispatch, getState) => { requestCreateWorkspace( form.name, form.isSubWiki, + form.mainWikiToLink, form.port, homeUrl, form.gitUrl, @@ -211,6 +212,7 @@ export const save = () => (dispatch, getState) => { requestCreateWorkspace( form.name, form.isSubWiki, + form.mainWikiToLink, form.port, homeUrl, form.gitUrl,