refactor: move import electron related paths to other file

This commit is contained in:
tiddlygit-test 2021-05-04 13:09:17 +08:00
parent 7dcf983aed
commit 48904d3b5c
6 changed files with 16 additions and 10 deletions

View file

@ -49,6 +49,7 @@ module.exports = {
}, },
], ],
'unicorn/prefer-node-protocol': 'off', 'unicorn/prefer-node-protocol': 'off',
'unicorn/prefer-module': 'off',
'@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/method-signature-style': 'off', '@typescript-eslint/method-signature-style': 'off',
'unicorn/no-array-reduce': 'off', 'unicorn/no-array-reduce': 'off',

View file

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

View file

@ -0,0 +1,9 @@
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,13 +1,12 @@
import { app } from 'electron';
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 { developmentSettingFolderName, developmentWikiFolderName, localizationFolderName } from './fileNames'; import { developmentWikiFolderName, localizationFolderName } from './fileNames';
const isMac = process.platform === 'darwin'; const isMac = process.platform === 'darwin';
/** src folder */ /** src folder */
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; export const REACT_PATH = MAIN_WINDOW_WEBPACK_ENTRY;
@ -25,9 +24,6 @@ export const LOG_FOLDER = isDevelopmentOrTest
: isMac : isMac
? path.resolve(process.resourcesPath, '..', 'logs') ? path.resolve(process.resourcesPath, '..', 'logs')
: path.resolve(os.homedir(), '.tg-note', 'logs'); : path.resolve(os.homedir(), '.tg-note', 'logs');
export const SETTINGS_FOLDER = isDevelopmentOrTest
? path.resolve(sourcePath, '..', developmentSettingFolderName)
: path.resolve(app.getPath('userData'), 'settings');
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);

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/paths'; import { SETTINGS_FOLDER } from '@/constants/electronPaths';
const gotTheLock = app.requestSingleInstanceLock(); const gotTheLock = app.requestSingleInstanceLock();

View file

@ -7,10 +7,11 @@ 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; private readonly pathConstants: IPaths = { ...paths, ...electronPaths };
private readonly constants: IConstants = { private readonly constants: IConstants = {
isDevelopment: isElectronDevelopment, isDevelopment: isElectronDevelopment,
platform: process.platform, platform: process.platform,