refactor: merge context paths

This commit is contained in:
tiddlygit-test 2021-05-04 20:01:53 +08:00
parent fdb478dfaf
commit c9a34b8a8f
11 changed files with 29 additions and 34 deletions

1
.nvmrc Normal file
View file

@ -0,0 +1 @@
v14.16.0

View file

@ -95,6 +95,15 @@ cd TiddlyGit-Desktop
# or GitKraken to clone this repo, # or GitKraken to clone this repo,
# and open it in your favorite code editor and terminal app # and open it in your favorite code editor and terminal app
# switch to the nodejs version same as electron used version, other wise you may get
# Error: The module '/Users/linonetwo/Desktop/repo/TiddlyGit-Desktop/node_modules/opencv4nodejs-prebuilt/build/Release/opencv4nodejs.node'
# was compiled against a different Node.js version using
# NODE_MODULE_VERSION 88. This version of Node.js requires
# NODE_MODULE_VERSION 93. Please try re-compiling or re-installing
# the module (for instance, using `npm rebuild` or `npm install`).
# See https://github.com/justadudewhohacks/opencv4nodejs/issues/401#issuecomment-463434713 if you still have problem rebuild opencv for @nut-tree/nut-js
nvm use
# install the dependencies # install the dependencies
npm i npm i

View file

@ -1,14 +1,13 @@
/* eslint-disable unicorn/filename-case */
import { After, Before, Status } from '@cucumber/cucumber'; import { After, Before, Status } from '@cucumber/cucumber';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { temporarySettingPath, mockWikiPath } from './constants'; import { SETTINGS_FOLDER, DEFAULT_WIKI_FOLDER } from '../../src/constants/paths';
import { TiddlyGitWorld } from './world'; import { TiddlyGitWorld } from './world';
Before(async function () { Before(async function () {
// clear setting folder // clear setting folder
await fs.remove(temporarySettingPath); await fs.remove(SETTINGS_FOLDER);
await fs.remove(mockWikiPath); await fs.remove(DEFAULT_WIKI_FOLDER);
}); });
After(async function (this: TiddlyGitWorld, testCase) { After(async function (this: TiddlyGitWorld, testCase) {

View file

@ -1,7 +0,0 @@
import path from 'path';
import { sourcePath } from '../../src/constants/paths';
import { developmentSettingFolderName, developmentWikiFolderName } from '../../src/constants/fileNames';
export const temporarySettingPath = path.resolve(sourcePath, '..', developmentSettingFolderName);
export const mockWikiPath = path.resolve(sourcePath, '..', developmentWikiFolderName);

View file

@ -1,9 +0,0 @@
import { app } from 'electron';
import path from 'path';
import { isDevelopmentOrTest } from './environment';
import { developmentSettingFolderName } from './fileNames';
import { sourcePath } from './paths';
export const SETTINGS_FOLDER = isDevelopmentOrTest
? path.resolve(sourcePath, '..', developmentSettingFolderName)
: path.resolve(app.getPath('userData'), 'settings');

View file

@ -1,7 +1,7 @@
import path from 'path'; import path from 'path';
import os from 'os'; import os from 'os';
import { isDevelopmentOrTest } from './environment'; import { isDevelopmentOrTest } from './environment';
import { developmentWikiFolderName, localizationFolderName } from './fileNames'; import { developmentSettingFolderName, developmentWikiFolderName, localizationFolderName } from './fileNames';
const isMac = process.platform === 'darwin'; const isMac = process.platform === 'darwin';
@ -9,7 +9,6 @@ const isMac = process.platform === 'darwin';
export const sourcePath = path.resolve(__dirname, '..'); export const sourcePath = path.resolve(__dirname, '..');
export const buildResourcePath = path.resolve(sourcePath, '..', 'build-resources'); export const buildResourcePath = path.resolve(sourcePath, '..', 'build-resources');
export const REACT_PATH = MAIN_WINDOW_WEBPACK_ENTRY;
// .app/Contents/Resources/wiki/ // .app/Contents/Resources/wiki/
export const TIDDLYWIKI_TEMPLATE_FOLDER_PATH = isDevelopmentOrTest export const TIDDLYWIKI_TEMPLATE_FOLDER_PATH = isDevelopmentOrTest
? path.resolve(sourcePath, '..', 'template', 'wiki') ? path.resolve(sourcePath, '..', 'template', 'wiki')
@ -27,4 +26,8 @@ export const LOG_FOLDER = isDevelopmentOrTest
export const LOCALIZATION_FOLDER = isDevelopmentOrTest export const LOCALIZATION_FOLDER = isDevelopmentOrTest
? path.resolve(sourcePath, '..', localizationFolderName) ? path.resolve(sourcePath, '..', localizationFolderName)
: path.resolve(process.resourcesPath, localizationFolderName); : path.resolve(process.resourcesPath, localizationFolderName);
export const DEFAULT_WIKI_FOLDER = isDevelopmentOrTest ? path.resolve(sourcePath, '..', developmentWikiFolderName) : DESKTOP_PATH; export const DEFAULT_WIKI_FOLDER = isDevelopmentOrTest ? path.resolve(os.tmpdir(), developmentWikiFolderName) : DESKTOP_PATH;
export const SETTINGS_FOLDER = isDevelopmentOrTest
? path.resolve(sourcePath, '..', developmentSettingFolderName)
: // eslint-disable-next-line @typescript-eslint/no-var-requires
path.resolve(require('electron').app.getPath('userData'), 'settings');

View file

@ -24,7 +24,7 @@ import { IPreferenceService } from './services/preferences/interface';
import { IWikiService } from './services/wiki/interface'; import { IWikiService } from './services/wiki/interface';
import { IWindowService } from './services/windows/interface'; import { IWindowService } from './services/windows/interface';
import { IWorkspaceViewService } from './services/workspacesView/interface'; import { IWorkspaceViewService } from './services/workspacesView/interface';
import { SETTINGS_FOLDER } from '@/constants/electronPaths'; import { SETTINGS_FOLDER } from '@/constants/paths';
const gotTheLock = app.requestSingleInstanceLock(); const gotTheLock = app.requestSingleInstanceLock();

View file

@ -6,10 +6,10 @@ import { windowName } from './browserViewMetaData';
const CHECK_LOADED_INTERVAL = 500; const CHECK_LOADED_INTERVAL = 500;
let CHROME_ERROR_PATH: string | undefined; let CHROME_ERROR_PATH: string | undefined;
let LOGIN_REDIRECT_PATH: string | undefined; let LOGIN_REDIRECT_PATH: string | undefined;
let REACT_PATH: string | undefined; let MAIN_WINDOW_WEBPACK_ENTRY: string | undefined;
async function refresh(): Promise<void> { async function refresh(): Promise<void> {
if (CHROME_ERROR_PATH === undefined || REACT_PATH === undefined || LOGIN_REDIRECT_PATH === undefined) { if (CHROME_ERROR_PATH === undefined || MAIN_WINDOW_WEBPACK_ENTRY === undefined || LOGIN_REDIRECT_PATH === undefined) {
await Promise.all([ await Promise.all([
context.get('CHROME_ERROR_PATH').then((pathName) => { context.get('CHROME_ERROR_PATH').then((pathName) => {
CHROME_ERROR_PATH = pathName; CHROME_ERROR_PATH = pathName;
@ -17,15 +17,15 @@ async function refresh(): Promise<void> {
context.get('LOGIN_REDIRECT_PATH').then((pathName) => { context.get('LOGIN_REDIRECT_PATH').then((pathName) => {
LOGIN_REDIRECT_PATH = pathName; LOGIN_REDIRECT_PATH = pathName;
}), }),
context.get('REACT_PATH').then((pathName) => { context.get('MAIN_WINDOW_WEBPACK_ENTRY').then((pathName) => {
REACT_PATH = pathName; MAIN_WINDOW_WEBPACK_ENTRY = pathName;
}), }),
]); ]);
setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL);
return; return;
} }
if (window.location.href === CHROME_ERROR_PATH || window.location.href.startsWith(LOGIN_REDIRECT_PATH)) { if (window.location.href === CHROME_ERROR_PATH || window.location.href.startsWith(LOGIN_REDIRECT_PATH)) {
await windowService.loadURL(windowName, REACT_PATH); await windowService.loadURL(windowName, MAIN_WINDOW_WEBPACK_ENTRY);
} else { } else {
setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL);
} }

View file

@ -7,11 +7,10 @@ import { injectable } from 'inversify';
import { IContextService, IContext, IPaths, IConstants } from './interface'; import { IContextService, IContext, IPaths, IConstants } from './interface';
import * as paths from '@/constants/paths'; import * as paths from '@/constants/paths';
import * as electronPaths from '@/constants/electronPaths';
@injectable() @injectable()
export class ContextService implements IContextService { export class ContextService implements IContextService {
private readonly pathConstants: IPaths = { ...paths, ...electronPaths }; private readonly pathConstants: IPaths = { ...paths, MAIN_WINDOW_WEBPACK_ENTRY: MAIN_WINDOW_WEBPACK_ENTRY };
private readonly constants: IConstants = { private readonly constants: IConstants = {
isDevelopment: isElectronDevelopment, isDevelopment: isElectronDevelopment,
platform: process.platform, platform: process.platform,

View file

@ -2,7 +2,7 @@ import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common';
import { ContextChannel } from '@/constants/channels'; import { ContextChannel } from '@/constants/channels';
export interface IPaths { export interface IPaths {
REACT_PATH: string; MAIN_WINDOW_WEBPACK_ENTRY: string;
TIDDLYWIKI_TEMPLATE_FOLDER_PATH: string; TIDDLYWIKI_TEMPLATE_FOLDER_PATH: string;
TIDDLERS_PATH: string; TIDDLERS_PATH: string;
ICON_PATH: string; ICON_PATH: string;

View file

@ -4,7 +4,7 @@ import windowStateKeeper from 'electron-window-state';
import { menubar, Menubar } from 'menubar'; import { menubar, Menubar } from 'menubar';
import path from 'path'; import path from 'path';
import { REACT_PATH, buildResourcePath } from '@/constants/paths'; import { buildResourcePath } from '@/constants/paths';
import { WindowNames } from './WindowProperties'; import { WindowNames } from './WindowProperties';
import { isDevelopmentOrTest, isTest } from '@/constants/environment'; import { isDevelopmentOrTest, isTest } from '@/constants/environment';
@ -25,7 +25,7 @@ export default async function handleAttachToMenuBar(): Promise<Menubar> {
tray.setImage(iconPath); tray.setImage(iconPath);
const menuBar = menubar({ const menuBar = menubar({
index: REACT_PATH, index: MAIN_WINDOW_WEBPACK_ENTRY,
tray, tray,
preloadWindow: true, preloadWindow: true,
tooltip: 'TiddlyGit', tooltip: 'TiddlyGit',