From c9a34b8a8f9bcc854c3470d88f9725756308feda Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Tue, 4 May 2021 20:01:53 +0800 Subject: [PATCH] refactor: merge context paths --- .nvmrc | 1 + README.md | 9 +++++++++ features/supports/after.ts | 7 +++---- features/supports/constants.ts | 7 ------- src/constants/electronPaths.ts | 9 --------- src/constants/paths.ts | 9 ++++++--- src/main.ts | 2 +- src/preload/common/authingPostMessage.ts | 10 +++++----- src/services/context/index.ts | 3 +-- src/services/context/interface.ts | 2 +- src/services/windows/handleAttachToMenuBar.ts | 4 ++-- 11 files changed, 29 insertions(+), 34 deletions(-) create mode 100644 .nvmrc delete mode 100644 features/supports/constants.ts delete mode 100644 src/constants/electronPaths.ts diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..158c0064 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v14.16.0 diff --git a/README.md b/README.md index 3366d83f..1fb35f4a 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,15 @@ cd TiddlyGit-Desktop # or GitKraken to clone this repo, # 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 npm i diff --git a/features/supports/after.ts b/features/supports/after.ts index acd2f965..069c653b 100644 --- a/features/supports/after.ts +++ b/features/supports/after.ts @@ -1,14 +1,13 @@ -/* eslint-disable unicorn/filename-case */ import { After, Before, Status } from '@cucumber/cucumber'; import fs from 'fs-extra'; -import { temporarySettingPath, mockWikiPath } from './constants'; +import { SETTINGS_FOLDER, DEFAULT_WIKI_FOLDER } from '../../src/constants/paths'; import { TiddlyGitWorld } from './world'; Before(async function () { // clear setting folder - await fs.remove(temporarySettingPath); - await fs.remove(mockWikiPath); + await fs.remove(SETTINGS_FOLDER); + await fs.remove(DEFAULT_WIKI_FOLDER); }); After(async function (this: TiddlyGitWorld, testCase) { diff --git a/features/supports/constants.ts b/features/supports/constants.ts deleted file mode 100644 index db7ebee9..00000000 --- a/features/supports/constants.ts +++ /dev/null @@ -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); diff --git a/src/constants/electronPaths.ts b/src/constants/electronPaths.ts deleted file mode 100644 index 49024095..00000000 --- a/src/constants/electronPaths.ts +++ /dev/null @@ -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'); diff --git a/src/constants/paths.ts b/src/constants/paths.ts index c4ddbf0f..69771d00 100644 --- a/src/constants/paths.ts +++ b/src/constants/paths.ts @@ -1,7 +1,7 @@ import path from 'path'; import os from 'os'; import { isDevelopmentOrTest } from './environment'; -import { developmentWikiFolderName, localizationFolderName } from './fileNames'; +import { developmentSettingFolderName, developmentWikiFolderName, localizationFolderName } from './fileNames'; const isMac = process.platform === 'darwin'; @@ -9,7 +9,6 @@ const isMac = process.platform === 'darwin'; export const sourcePath = path.resolve(__dirname, '..'); export const buildResourcePath = path.resolve(sourcePath, '..', 'build-resources'); -export const REACT_PATH = MAIN_WINDOW_WEBPACK_ENTRY; // .app/Contents/Resources/wiki/ export const TIDDLYWIKI_TEMPLATE_FOLDER_PATH = isDevelopmentOrTest ? path.resolve(sourcePath, '..', 'template', 'wiki') @@ -27,4 +26,8 @@ export const LOG_FOLDER = isDevelopmentOrTest export const LOCALIZATION_FOLDER = isDevelopmentOrTest ? path.resolve(sourcePath, '..', 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'); diff --git a/src/main.ts b/src/main.ts index 6315dbbe..7c422ea3 100755 --- a/src/main.ts +++ b/src/main.ts @@ -24,7 +24,7 @@ import { IPreferenceService } from './services/preferences/interface'; import { IWikiService } from './services/wiki/interface'; import { IWindowService } from './services/windows/interface'; import { IWorkspaceViewService } from './services/workspacesView/interface'; -import { SETTINGS_FOLDER } from '@/constants/electronPaths'; +import { SETTINGS_FOLDER } from '@/constants/paths'; const gotTheLock = app.requestSingleInstanceLock(); diff --git a/src/preload/common/authingPostMessage.ts b/src/preload/common/authingPostMessage.ts index 46a00eff..d39cf808 100644 --- a/src/preload/common/authingPostMessage.ts +++ b/src/preload/common/authingPostMessage.ts @@ -6,10 +6,10 @@ import { windowName } from './browserViewMetaData'; const CHECK_LOADED_INTERVAL = 500; let CHROME_ERROR_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 { - 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([ context.get('CHROME_ERROR_PATH').then((pathName) => { CHROME_ERROR_PATH = pathName; @@ -17,15 +17,15 @@ async function refresh(): Promise { context.get('LOGIN_REDIRECT_PATH').then((pathName) => { LOGIN_REDIRECT_PATH = pathName; }), - context.get('REACT_PATH').then((pathName) => { - REACT_PATH = pathName; + context.get('MAIN_WINDOW_WEBPACK_ENTRY').then((pathName) => { + MAIN_WINDOW_WEBPACK_ENTRY = pathName; }), ]); setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); return; } 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 { setTimeout(() => void refresh(), CHECK_LOADED_INTERVAL); } diff --git a/src/services/context/index.ts b/src/services/context/index.ts index 9096bfdf..4c951a23 100644 --- a/src/services/context/index.ts +++ b/src/services/context/index.ts @@ -7,11 +7,10 @@ import { injectable } from 'inversify'; import { IContextService, IContext, IPaths, IConstants } from './interface'; import * as paths from '@/constants/paths'; -import * as electronPaths from '@/constants/electronPaths'; @injectable() 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 = { isDevelopment: isElectronDevelopment, platform: process.platform, diff --git a/src/services/context/interface.ts b/src/services/context/interface.ts index 75444387..5410f50a 100644 --- a/src/services/context/interface.ts +++ b/src/services/context/interface.ts @@ -2,7 +2,7 @@ import { ProxyPropertyType } from '@/helpers/electron-ipc-proxy/common'; import { ContextChannel } from '@/constants/channels'; export interface IPaths { - REACT_PATH: string; + MAIN_WINDOW_WEBPACK_ENTRY: string; TIDDLYWIKI_TEMPLATE_FOLDER_PATH: string; TIDDLERS_PATH: string; ICON_PATH: string; diff --git a/src/services/windows/handleAttachToMenuBar.ts b/src/services/windows/handleAttachToMenuBar.ts index 1f835a32..9663b079 100644 --- a/src/services/windows/handleAttachToMenuBar.ts +++ b/src/services/windows/handleAttachToMenuBar.ts @@ -4,7 +4,7 @@ import windowStateKeeper from 'electron-window-state'; import { menubar, Menubar } from 'menubar'; import path from 'path'; -import { REACT_PATH, buildResourcePath } from '@/constants/paths'; +import { buildResourcePath } from '@/constants/paths'; import { WindowNames } from './WindowProperties'; import { isDevelopmentOrTest, isTest } from '@/constants/environment'; @@ -25,7 +25,7 @@ export default async function handleAttachToMenuBar(): Promise { tray.setImage(iconPath); const menuBar = menubar({ - index: REACT_PATH, + index: MAIN_WINDOW_WEBPACK_ENTRY, tray, preloadWindow: true, tooltip: 'TiddlyGit',