feat: remove workspace if folder is removed

This commit is contained in:
Lin Onetwo 2020-07-11 20:52:42 +08:00
parent cccf5fed30
commit bf802b58ff
2 changed files with 23 additions and 10 deletions

View file

@ -137,7 +137,7 @@ const addView = (browserWindow, workspace) => {
});
}
if (!isSubWiki) { // if is main wiki
startNodeJSWiki(wikiPath, port, userName);
startNodeJSWiki(wikiPath, port, userName, workspace.id);
userInfo && watchWiki(wikiPath, githubUrl, userInfo, path.join(wikiPath, TIDDLERS_PATH));
} else { // if is private repo wiki
userInfo && watchWiki(wikiPath, githubUrl, userInfo);

View file

@ -5,7 +5,7 @@ const { dialog } = require('electron');
const { startWiki } = require('./wiki-worker-mamager');
const mainWindow = require('../../windows/main');
module.exports = function startNodeJSWiki(homePath, port, userName) {
module.exports = function startNodeJSWiki(homePath, port, userName, workspaceID) {
if (!homePath || typeof homePath !== 'string' || !path.isAbsolute(homePath)) {
const errorMessage = `需要传入正确的路径,而 ${homePath} 无法被 TiddlyWiki 识别。`;
console.error(errorMessage);
@ -19,15 +19,28 @@ module.exports = function startNodeJSWiki(homePath, port, userName) {
return;
}
if (!fs.pathExistsSync(homePath)) {
const errorMessage = `无法找到之前还在该处的工作区文件夹!本应存在于 ${homePath} 的文件夹可能被移走了!`;
const errorMessage = `无法找到之前还在该处的工作区文件夹!本应存在于 ${homePath} 的文件夹可能被移走了!是否移除工作区?`;
console.error(errorMessage);
dialog.showMessageBox(mainWindow.get(), {
title: '工作区文件夹被移走',
message: errorMessage,
buttons: ['OK'],
cancelId: 0,
defaultId: 0,
});
dialog
.showMessageBox(mainWindow.get(), {
title: '工作区文件夹被移走',
message: errorMessage,
buttons: ['移除工作区', '不管'],
cancelId: 1,
defaultId: 0,
})
.then(({ response }) => {
// eslint-disable-next-line promise/always-return
if (response === 0) {
// eslint-disable-next-line global-require
const { removeWorkspaceView } = require('../workspaces-views'); // prevent circular dependence
// eslint-disable-next-line global-require
const createMenu = require('../create-menu');
removeWorkspaceView(workspaceID);
createMenu();
}
})
.catch(console.log);
return;
}