mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
refactor: merge context paths
This commit is contained in:
parent
fdb478dfaf
commit
c9a34b8a8f
11 changed files with 29 additions and 34 deletions
1
.nvmrc
Normal file
1
.nvmrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
v14.16.0
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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');
|
||||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<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([
|
||||
context.get('CHROME_ERROR_PATH').then((pathName) => {
|
||||
CHROME_ERROR_PATH = pathName;
|
||||
|
|
@ -17,15 +17,15 @@ async function refresh(): Promise<void> {
|
|||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Menubar> {
|
|||
tray.setImage(iconPath);
|
||||
|
||||
const menuBar = menubar({
|
||||
index: REACT_PATH,
|
||||
index: MAIN_WINDOW_WEBPACK_ENTRY,
|
||||
tray,
|
||||
preloadWindow: true,
|
||||
tooltip: 'TiddlyGit',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue