mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-02 20:11:08 -08:00
feat: start wiki upon workspace creation and on startup
This commit is contained in:
parent
f3cfa6b819
commit
d67cf2df45
6 changed files with 74 additions and 29 deletions
|
|
@ -1,3 +1,5 @@
|
|||
const { ICON_PATH } = require('../constants/paths');
|
||||
const { TIDDLYWIKI_FOLDER_NAME } = require('../constants/file-names');
|
||||
|
||||
module.exports.getIconPath = () => ICON_PATH;
|
||||
module.exports.getDefaultTiddlywikiFolderName = () => TIDDLYWIKI_FOLDER_NAME;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
const path = require('path');
|
||||
const $tw = require('tiddlywiki/boot/boot.js').TiddlyWiki();
|
||||
const { TIDDLYWIKI_FOLDER_PATH } = require('../constants/paths');
|
||||
|
||||
const tiddlyWikiPort = 5112;
|
||||
const userName = 'LinOnetwoTest';
|
||||
|
||||
module.exports = function startNodeJSWiki() {
|
||||
module.exports = function startNodeJSWiki(homePath) {
|
||||
if ($tw.wiki) {
|
||||
console.error('Wiki has already started');
|
||||
return;
|
||||
}
|
||||
if (!homePath || typeof homePath !== 'string' || !path.isAbsolute(homePath)) {
|
||||
console.error(
|
||||
`valie absolute homePath not provided to startNodeJSWiki(homePath), received ${homePath} which is invalid.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
process.env.TIDDLYWIKI_PLUGIN_PATH = `${TIDDLYWIKI_FOLDER_PATH}/plugins`;
|
||||
process.env.TIDDLYWIKI_THEME_PATH = `${TIDDLYWIKI_FOLDER_PATH}/themes`;
|
||||
process.env.TIDDLYWIKI_PLUGIN_PATH = path.resolve(homePath, 'plugins');
|
||||
process.env.TIDDLYWIKI_THEME_PATH = path.resolve(homePath, 'themes');
|
||||
// add tiddly filesystem back https://github.com/Jermolene/TiddlyWiki5/issues/4484#issuecomment-596779416
|
||||
$tw.boot.argv = [
|
||||
'+plugins/tiddlywiki/filesystem',
|
||||
'+plugins/tiddlywiki/tiddlyweb',
|
||||
TIDDLYWIKI_FOLDER_PATH,
|
||||
homePath,
|
||||
'--listen',
|
||||
`anon-username=${userName}`,
|
||||
`port=${tiddlyWikiPort}`,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const path = require('path');
|
|||
const fsExtra = require('fs-extra');
|
||||
const { ElectronBlocker } = require('@cliqz/adblocker-electron');
|
||||
|
||||
const startNodeJSWiki = require('./start-nodejs-wiki')
|
||||
const { getPreferences } = require('./preferences');
|
||||
const {
|
||||
getWorkspace,
|
||||
|
|
@ -118,6 +119,9 @@ const addView = (browserWindow, workspace) => {
|
|||
|
||||
// configure session, proxy & ad blocker
|
||||
const partitionId = shareWorkspaceBrowsingData ? 'persist:shared' : `persist:${workspace.id}`;
|
||||
// start wiki on startup
|
||||
const wikiPath = workspace.name;
|
||||
startNodeJSWiki(wikiPath);
|
||||
// session
|
||||
const ses = session.fromPartition(partitionId);
|
||||
// proxy
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const { BrowserView, Notification, app, dialog, ipcMain, nativeTheme, shell } =
|
|||
|
||||
const createWiki = require('../libs/create-wiki');
|
||||
const startNodeJSWiki = require('../libs/start-nodejs-wiki');
|
||||
const { getIconPath } = require('../libs/get-constants') ;
|
||||
const { getIconPath, getDefaultTiddlywikiFolderName } = require('../libs/get-constants');
|
||||
|
||||
const { getPreference, getPreferences, resetPreferences, setPreference } = require('../libs/preferences');
|
||||
|
||||
|
|
@ -58,16 +58,19 @@ const loadListeners = () => {
|
|||
ipcMain.on('copy-wiki-template', async (event, newFolderPath) => {
|
||||
try {
|
||||
const createdWikiPath = await createWiki(newFolderPath);
|
||||
event.reply('copy-wiki-template-result', `Wiki 已成功创建到 ${createdWikiPath}`);
|
||||
event.reply('copy-wiki-template-result', `Wiki 已成功创建到 ${createdWikiPath}/${getDefaultTiddlywikiFolderName()}`);
|
||||
} catch (error) {
|
||||
event.reply('copy-wiki-template-result', String(error));
|
||||
}
|
||||
});
|
||||
ipcMain.on('request-start-tiddlywiki', () => {
|
||||
startNodeJSWiki();
|
||||
ipcMain.on('request-start-tiddlywiki', (wikiPath) => {
|
||||
startNodeJSWiki(wikiPath);
|
||||
});
|
||||
ipcMain.on('get-icon-path', (event) => {
|
||||
event.returnValue = getIconPath();
|
||||
ipcMain.on('get-constant', (event, name) => {
|
||||
event.returnValue = {
|
||||
getIconPath,
|
||||
getDefaultTiddlywikiFolderName,
|
||||
}[name]();
|
||||
});
|
||||
|
||||
ipcMain.on('request-open-in-browser', (e, url) => {
|
||||
|
|
@ -239,6 +242,8 @@ const loadListeners = () => {
|
|||
});
|
||||
|
||||
ipcMain.on('request-create-workspace', (e, name, homeUrl, picture, transparentBackground) => {
|
||||
const wikiPath = name;
|
||||
startNodeJSWiki(wikiPath);
|
||||
createWorkspaceView(name, homeUrl, picture, transparentBackground);
|
||||
createMenu();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from 'styled-components';
|
||||
import is from 'styled-is';
|
||||
|
|
@ -13,7 +13,7 @@ import GithubIcon from '@material-ui/icons/GitHub';
|
|||
import connectComponent from '../../helpers/connect-component';
|
||||
import { updateForm, save } from '../../state/dialog-add-workspace/actions';
|
||||
|
||||
import { requestCopyWikiTemplate, getIconPath } from '../../senders';
|
||||
import { requestCopyWikiTemplate, getIconPath, getDefaultTiddlywikiFolderName } from '../../senders';
|
||||
|
||||
const Container = styled.main`
|
||||
height: 100vh;
|
||||
|
|
@ -55,10 +55,15 @@ const CloseButton = styled(Button)`
|
|||
`;
|
||||
|
||||
function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave }) {
|
||||
const [folderLocation, folderLocationSetter] = useState('');
|
||||
const [parentFolderLocation, parentFolderLocationSetter] = useState('');
|
||||
const [wikiFolderLocation, wikiFolderLocationSetter] = useState('');
|
||||
useEffect(() => {
|
||||
wikiFolderLocationSetter(`${parentFolderLocation}/${getDefaultTiddlywikiFolderName()}`);
|
||||
}, [parentFolderLocation]);
|
||||
const messageHasError = wikiCreationMessage.startsWith('Error: ');
|
||||
const message = wikiCreationMessage.replace('Error: ', '');
|
||||
const succeed = !messageHasError && wikiCreationMessage.length > 0;
|
||||
const workspaceFormData = { name: wikiFolderLocation, homeUrl: 'http://localhost:5112/', picturePath: getIconPath() };
|
||||
return (
|
||||
<Container>
|
||||
<Description elevation={0} square>
|
||||
|
|
@ -78,12 +83,12 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave }) {
|
|||
})
|
||||
.then(({ canceled, filePaths }) => {
|
||||
if (!canceled && filePaths.length > 0) {
|
||||
folderLocationSetter(filePaths[0]);
|
||||
parentFolderLocationSetter(filePaths[0]);
|
||||
}
|
||||
});
|
||||
}}
|
||||
variant="contained"
|
||||
color={folderLocation ? 'default' : 'primary'}
|
||||
color={parentFolderLocation ? 'default' : 'primary'}
|
||||
disableElevation
|
||||
endIcon={<FolderIcon />}
|
||||
>
|
||||
|
|
@ -95,18 +100,28 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave }) {
|
|||
error={messageHasError}
|
||||
helperText={message}
|
||||
fullWidth
|
||||
onChange={(event) => folderLocationSetter(event.target.value)}
|
||||
onChange={(event) => parentFolderLocationSetter(event.target.value)}
|
||||
label="知识库的父文件夹"
|
||||
value={folderLocation}
|
||||
value={parentFolderLocation}
|
||||
disabled={succeed}
|
||||
/>
|
||||
{parentFolderLocation && !succeed && (
|
||||
<div>
|
||||
<Typography variant="body1" display="inline">
|
||||
WIKI将被创建到
|
||||
</Typography>
|
||||
<Typography variant="body2" noWrap display="inline-block" align="left" style={{ direction: 'rtl' }}>
|
||||
{wikiFolderLocation}
|
||||
</Typography>
|
||||
</div>
|
||||
)}
|
||||
<CreatorButton
|
||||
variant="contained"
|
||||
color="primary"
|
||||
disabled={folderLocation.length === 0 || succeed}
|
||||
disabled={parentFolderLocation.length === 0 || succeed}
|
||||
onClick={() => {
|
||||
requestCopyWikiTemplate(folderLocation);
|
||||
onUpdateForm({ name: folderLocation, homeUrl: 'http://localhost:5112', picturePath: getIconPath() });
|
||||
requestCopyWikiTemplate(parentFolderLocation);
|
||||
onUpdateForm(workspaceFormData);
|
||||
}}
|
||||
>
|
||||
创建知识库
|
||||
|
|
@ -122,8 +137,15 @@ function AddWorkspace({ wikiCreationMessage, onUpdateForm, onSave }) {
|
|||
</SyncToGithubButton>
|
||||
</SyncContainer>
|
||||
|
||||
<CloseButton variant="contained" color="secondary" onClick={() => onSave()}>
|
||||
完成
|
||||
<CloseButton
|
||||
variant="contained"
|
||||
color="secondary"
|
||||
onClick={() => {
|
||||
onUpdateForm(workspaceFormData);
|
||||
onSave();
|
||||
}}
|
||||
>
|
||||
启动WIKI
|
||||
</CloseButton>
|
||||
</Container>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const { ipcRenderer } = window.require('electron');
|
||||
|
||||
export const requestCopyWikiTemplate = (newFolderPath) => ipcRenderer.send('copy-wiki-template', newFolderPath);
|
||||
export const requestStartTiddlyWiki = (url) => ipcRenderer.send('request-start-tiddlywiki', url);
|
||||
export const requestStartTiddlyWiki = (wikiPath) => ipcRenderer.send('request-start-tiddlywiki', wikiPath);
|
||||
export const requestOpenInBrowser = (url) => ipcRenderer.send('request-open-in-browser', url);
|
||||
export const requestShowMessageBox = (message, type) => ipcRenderer.send('request-show-message-box', message, type);
|
||||
export const requestLoadUrl = (url, id) => ipcRenderer.send('request-load-url', url, id);
|
||||
|
|
@ -40,13 +40,15 @@ export const requestShowRequireRestartDialog = () => ipcRenderer.send('request-s
|
|||
// System Preferences
|
||||
export const getSystemPreference = (name) => ipcRenderer.sendSync('get-system-preference', name);
|
||||
export const getSystemPreferences = () => ipcRenderer.sendSync('get-system-preferences');
|
||||
export const requestSetSystemPreference = (name, value) => ipcRenderer.send('request-set-system-preference', name, value);
|
||||
export const requestSetSystemPreference = (name, value) =>
|
||||
ipcRenderer.send('request-set-system-preference', name, value);
|
||||
|
||||
// Workspace
|
||||
export const getWorkspace = (id) => 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, homeUrl, picture, transparentBackground) => ipcRenderer.send('request-create-workspace', name, homeUrl, picture, transparentBackground);
|
||||
export const requestCreateWorkspace = (name, homeUrl, picture, transparentBackground) =>
|
||||
ipcRenderer.send('request-create-workspace', name, 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');
|
||||
|
|
@ -55,10 +57,13 @@ export const requestRemoveWorkspacePicture = (id) => ipcRenderer.send('request-r
|
|||
export const requestSetActiveWorkspace = (id) => ipcRenderer.send('request-set-active-workspace', id);
|
||||
export const requestSetWorkspace = (id, opts) => ipcRenderer.send('request-set-workspace', id, opts);
|
||||
export const requestSetWorkspaces = (workspaces) => ipcRenderer.send('request-set-workspaces', workspaces);
|
||||
export const requestSetWorkspacePicture = (id, picturePath) => ipcRenderer.send('request-set-workspace-picture', id, picturePath);
|
||||
export const requestSetWorkspacePicture = (id, picturePath) =>
|
||||
ipcRenderer.send('request-set-workspace-picture', id, picturePath);
|
||||
export const requestWakeUpWorkspace = (id) => ipcRenderer.send('request-wake-up-workspace', id);
|
||||
|
||||
export const getIconPath = () => ipcRenderer.sendSync('get-icon-path');
|
||||
export const getIconPath = () => ipcRenderer.sendSync('get-constant', 'getIconPath');
|
||||
export const getDefaultTiddlywikiFolderName = () =>
|
||||
ipcRenderer.sendSync('get-constant', 'getDefaultTiddlywikiFolderName');
|
||||
|
||||
// Workspace Meta
|
||||
export const getWorkspaceMeta = (id) => ipcRenderer.sendSync('get-workspace-meta', id);
|
||||
|
|
@ -69,7 +74,8 @@ export const requestFindInPage = (text, forward) => ipcRenderer.send('request-fi
|
|||
export const requestStopFindInPage = (close) => ipcRenderer.send('request-stop-find-in-page', close);
|
||||
|
||||
// Auth
|
||||
export const requestValidateAuthIdentity = (windowId, username, password) => ipcRenderer.send('request-validate-auth-identity', windowId, username, password);
|
||||
export const requestValidateAuthIdentity = (windowId, username, password) =>
|
||||
ipcRenderer.send('request-validate-auth-identity', windowId, username, password);
|
||||
|
||||
// Native Theme
|
||||
export const getShouldUseDarkColors = () => ipcRenderer.sendSync('get-should-use-dark-colors');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue