diff --git a/src/common/constants.ts b/src/common/constants.ts index a9362e2d..8671a547 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -1,7 +1,7 @@ import { is } from 'electron-util' +export const GITHUB_LINK = 'http://github.com/Kiyozz/papyrus-compiler-app' +export const GITHUB_ISSUES_NEW = `${GITHUB_LINK}/issues/new` export const DEFAULT_COMPILER_PATH = `Papyrus Compiler${ is.linux || is.macos ? '/' : '\\' }PapyrusCompiler.exe` -export const GITHUB_LINK = 'http://github.com/Kiyozz/papyrus-compiler-app' -export const GITHUB_ISSUES_NEW = `${GITHUB_LINK}/issues/new` diff --git a/src/common/storeCheck.ts b/src/common/storeCheck.ts index 89e03aa3..22ab806e 100644 --- a/src/common/storeCheck.ts +++ b/src/common/storeCheck.ts @@ -2,6 +2,8 @@ import { AppStore } from '@pca/common/store' import { Config } from '@pca/common/interfaces/Config' import is from '@sindresorhus/is' import { groupValidator } from './validators/groupValidator' +import { join } from '../main/services/path' +import { DEFAULT_COMPILER_PATH } from '@pca/common/constants' function checkMo2(appStore: AppStore, defaultConfig: Config) { const mo2 = appStore.get('mo2') @@ -94,7 +96,7 @@ function checkOutput(appStore: AppStore, defaultConfig: Config) { } } -function checkCompilerPath(appStore: AppStore, defaultConfig: Config) { +function checkCompilerPath(appStore: AppStore) { const compilerPath = appStore.get('compilerPath') const gamePath = appStore.get('gamePath') @@ -102,9 +104,7 @@ function checkCompilerPath(appStore: AppStore, defaultConfig: Config) { is.nullOrUndefined(compilerPath) || (is.string(compilerPath) && is.emptyString(compilerPath.trim())) ) { - if (is.emptyString(gamePath)) { - appStore.set('compilerPath', defaultConfig.compilerPath) - } + appStore.set('compilerPath', join(gamePath, DEFAULT_COMPILER_PATH)) } } @@ -123,7 +123,7 @@ export function storeCheck(appStore: AppStore, defaultConfig: Config) { checkGameType(appStore, defaultConfig) checkGamePath(appStore) checkFlag(appStore) - checkCompilerPath(appStore, defaultConfig) + checkCompilerPath(appStore) checkOutput(appStore, defaultConfig) checkGroups(appStore, defaultConfig) checkNotSupportedKeys(appStore, defaultConfig) diff --git a/src/main/event-handlers/ConfigUpdateHandler.ts b/src/main/event-handlers/ConfigUpdateHandler.ts index 99d330d3..399b724d 100644 --- a/src/main/event-handlers/ConfigUpdateHandler.ts +++ b/src/main/event-handlers/ConfigUpdateHandler.ts @@ -3,10 +3,8 @@ import deepmerge from 'deepmerge' import { appStore } from '@pca/common/store' import { Config } from '@pca/common/interfaces/Config' import { PartialDeep } from '@pca/common/interfaces/PartialDeep' -import * as CONSTANTS from '@pca/common/constants' import { EventHandler } from '../EventHandler' import { Logger } from '../Logger' -import { join } from '../services/path' const logger = new Logger('ConfigUpdateHandler') @@ -18,30 +16,24 @@ interface ConfigUpdateHandlerParams { export class ConfigUpdateHandler implements EventHandler { listen(args?: ConfigUpdateHandlerParams): Config { - logger.info('Updating the configuration') + logger.info('updating the configuration') if (is.undefined(args)) { - throw new TypeError('Cannot update the configuration without arguments') + throw new TypeError('cannot update the configuration without arguments') } ;(Object.entries(args.config) as [keyof Config, unknown][]).forEach( ([key, value]) => { - logger.debug('Updating key', key, 'with value', value) + logger.debug('updating key', key, 'with value', value) if (!appStore.has(key)) { return } - if (key === 'gamePath' && is.string(value)) { - appStore.set('gamePath', value) - appStore.set( - 'compilerPath', - join(value, CONSTANTS.DEFAULT_COMPILER_PATH) - ) - } + this.handleGamePath(key, value) if (args.override) { - logger.debug('Total overwrite of the previous value') + logger.debug('total overwrite of the previous value') appStore.set(key, value) } else { @@ -64,4 +56,10 @@ export class ConfigUpdateHandler return appStore.store } + + private handleGamePath(key: keyof Config, value: unknown) { + if (key === 'gamePath' && is.string(value)) { + appStore.set('gamePath', value) + } + } } diff --git a/src/main/event-handlers/ScriptCompileHandler.ts b/src/main/event-handlers/ScriptCompileHandler.ts index fb58ad98..10439061 100644 --- a/src/main/event-handlers/ScriptCompileHandler.ts +++ b/src/main/event-handlers/ScriptCompileHandler.ts @@ -2,6 +2,8 @@ import is from '@sindresorhus/is' import { EventHandler } from '../EventHandler' import { compileScript } from '../services/compileScript' import { Logger } from '../Logger' +import { storeCheck } from '@pca/common/storeCheck' +import { appStore, defaultConfig } from '@pca/common/store' export class ScriptCompileHandler implements EventHandler { private readonly log = new Logger('ScriptCompileHandler') @@ -13,6 +15,8 @@ export class ScriptCompileHandler implements EventHandler { this.log.info('Started compilation for script:', script) + storeCheck(appStore, defaultConfig) + const result = await compileScript(script) this.log.info(`Script ${script} successfully compiled.`, result) diff --git a/src/renderer/components/folder-text-field/folder-text-field.module.scss b/src/renderer/components/folder-text-field/folder-text-field.module.scss index 9b566c91..e1e7d0b4 100644 --- a/src/renderer/components/folder-text-field/folder-text-field.module.scss +++ b/src/renderer/components/folder-text-field/folder-text-field.module.scss @@ -1,5 +1,5 @@ -.textField { - display: flex; +.textField input { + font-size: 0.8rem; } .icon { diff --git a/src/renderer/components/folder-text-field/folder-text-field.tsx b/src/renderer/components/folder-text-field/folder-text-field.tsx index d8ace007..56e5f3f1 100644 --- a/src/renderer/components/folder-text-field/folder-text-field.tsx +++ b/src/renderer/components/folder-text-field/folder-text-field.tsx @@ -2,6 +2,7 @@ import InputAdornment from '@material-ui/core/InputAdornment' import TextField from '@material-ui/core/TextField' import FolderIcon from '@material-ui/icons/Folder' import FolderOpenIcon from '@material-ui/icons/FolderOpen' +import cx from 'classnames' import React, { useCallback, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' @@ -10,6 +11,7 @@ import apiFactory from '../../redux/api/api-factory' import classes from './folder-text-field.module.scss' export interface Props { + className?: string error?: boolean label?: string defaultValue: string @@ -20,7 +22,8 @@ const FolderTextField: React.FC = ({ error = false, label, defaultValue, - onChange + onChange, + className = '' }) => { const { t } = useTranslation() const [value, setValue] = useState(defaultValue) @@ -66,7 +69,7 @@ const FolderTextField: React.FC = ({ ) => void onChangeGameFolder: (value: string) => void + onChangeCompilerPath: (value: string) => void onClickRefreshInstallation: (e: React.MouseEvent) => void } -const SettingsGame: React.FC = ({ +export function SettingsGame({ onChangeGameFolder, onClickRadio, + onChangeCompilerPath, onClickRefreshInstallation -}) => { +}: Props) { const { t } = useTranslation() const { - config: { gameType, gamePath } + config: { gameType, gamePath, compilerPath } } = usePageContext() const { installationIsBad } = useSettings() const exe = getExecutable(gameType) @@ -81,8 +83,13 @@ const SettingsGame: React.FC = ({ + + ) } - -export default SettingsGame diff --git a/src/renderer/pages/settings-page/settings-page.module.scss b/src/renderer/pages/settings-page/settings-page.module.scss index 3c9cc3e4..7b635f27 100644 --- a/src/renderer/pages/settings-page/settings-page.module.scss +++ b/src/renderer/pages/settings-page/settings-page.module.scss @@ -22,3 +22,7 @@ .listHeaderRightText { margin-left: auto; } + +div.gap { + margin-top: 10px; +} diff --git a/src/renderer/pages/settings-page/settings-page.tsx b/src/renderer/pages/settings-page/settings-page.tsx index 01e9d8db..7970b354 100644 --- a/src/renderer/pages/settings-page/settings-page.tsx +++ b/src/renderer/pages/settings-page/settings-page.tsx @@ -9,7 +9,7 @@ import { usePageContext } from '../../components/page/page-context' import actions from '../../redux/actions' import { useAction, useStoreSelector } from '../../redux/use-store-selector' import SettingsContextProvider from './settings-context' -import SettingsGame from './settings-game' +import { SettingsGame } from './settings-game' import SettingsMo2 from './settings-mo2' import classes from './settings-page.module.scss' import { debounce } from 'lodash-es' @@ -35,25 +35,28 @@ const SettingsPage: React.FC = () => { actions.settingsPage.detectBadInstallation.start ) const setGame = useCallback( - (game: GameType) => debouncedUpdateConfig({ gameType: game }), - [debouncedUpdateConfig] + (game: GameType) => updateConfig({ gameType: game }), + [updateConfig] ) const setGameFolder = useCallback( (path: string) => debouncedUpdateConfig({ gamePath: path }), [debouncedUpdateConfig] ) - const setMo2 = useCallback( - (useMo2Updated: boolean) => - debouncedUpdateConfig({ mo2: { use: useMo2Updated } }), + const setCompilerPath = useCallback( + (path: string) => debouncedUpdateConfig({ compilerPath: path }), [debouncedUpdateConfig] ) + const setMo2 = useCallback( + (useMo2Updated: boolean) => updateConfig({ mo2: { use: useMo2Updated } }), + [updateConfig] + ) const setMo2Instance = useCallback( (instance?: string) => debouncedUpdateConfig({ mo2: { instance } }), [debouncedUpdateConfig] ) const setDisableMo2 = useCallback( - () => debouncedUpdateConfig({ mo2: { use: false, instance: undefined } }), - [debouncedUpdateConfig] + () => updateConfig({ mo2: { use: false, instance: undefined } }), + [updateConfig] ) const setEmptyDetectedSourcesFolders = useAction( actions.settingsPage.mo2.detectSources.empty @@ -103,6 +106,13 @@ const SettingsPage: React.FC = () => { [setGameFolder] ) + const onChangeCompilerPath = useCallback( + (value: string) => { + setCompilerPath(value) + }, + [setCompilerPath] + ) + const onChangeMo2Instance = useCallback( (value: string) => { if (value === '') { @@ -176,6 +186,7 @@ const SettingsPage: React.FC = () => { onClickRadio={onClickRadio} onChangeGameFolder={onChangeGameFolder} onClickRefreshInstallation={onClickRefreshInstallation} + onChangeCompilerPath={onChangeCompilerPath} />