mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-03 04:21:05 -08:00
feat: allow remove workspace folder
This commit is contained in:
parent
c11e8d2488
commit
1dcdc06dff
7 changed files with 31 additions and 15 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue