diff --git a/core/src/node/log.ts b/core/src/node/log.ts index 8a5155d8d..6f2c2f80f 100644 --- a/core/src/node/log.ts +++ b/core/src/node/log.ts @@ -2,38 +2,36 @@ import fs from 'fs' import util from 'util' import { getAppLogPath, getServerLogPath } from './utils' -export const log = function (message: string) { - const appLogPath = getAppLogPath() +export const log = (message: string) => { + const path = getAppLogPath() if (!message.startsWith('[')) { message = `[APP]::${message}` } message = `${new Date().toISOString()} ${message}` - if (fs.existsSync(appLogPath)) { - var log_file = fs.createWriteStream(appLogPath, { - flags: 'a', - }) - log_file.write(util.format(message) + '\n') - log_file.close() - console.debug(message) - } + writeLog(message, path) } -export const logServer = function (message: string) { - const serverLogPath = getServerLogPath() +export const logServer = (message: string) => { + const path = getServerLogPath() if (!message.startsWith('[')) { message = `[SERVER]::${message}` } message = `${new Date().toISOString()} ${message}` + writeLog(message, path) +} - if (fs.existsSync(serverLogPath)) { - var log_file = fs.createWriteStream(serverLogPath, { +const writeLog = (message: string, logPath: string) => { + if (!fs.existsSync(logPath)) { + fs.writeFileSync(logPath, message) + } else { + const logFile = fs.createWriteStream(logPath, { flags: 'a', }) - log_file.write(util.format(message) + '\n') - log_file.close() + logFile.write(util.format(message) + '\n') + logFile.close() console.debug(message) } } diff --git a/web/hooks/useVaultDirectory.ts b/web/hooks/useVaultDirectory.ts index 3aa7383c9..9d7adf2ab 100644 --- a/web/hooks/useVaultDirectory.ts +++ b/web/hooks/useVaultDirectory.ts @@ -1,32 +1,15 @@ -import { useEffect } from 'react' +import { useEffect, useState } from 'react' import { fs, AppConfiguration } from '@janhq/core' -import { atom, useAtom } from 'jotai' - -import { useMainViewState } from './useMainViewState' - -const isSameDirectoryAtom = atom(false) -const isDirectoryConfirmAtom = atom(false) -const isErrorSetNewDestAtom = atom(false) -const currentPathAtom = atom('') -const newDestinationPathAtom = atom('') - export const SUCCESS_SET_NEW_DESTINATION = 'successSetNewDestination' export function useVaultDirectory() { - const [isSameDirectory, setIsSameDirectory] = useAtom(isSameDirectoryAtom) - const { setMainViewState } = useMainViewState() - const [isDirectoryConfirm, setIsDirectoryConfirm] = useAtom( - isDirectoryConfirmAtom - ) - const [isErrorSetNewDest, setIsErrorSetNewDest] = useAtom( - isErrorSetNewDestAtom - ) - const [currentPath, setCurrentPath] = useAtom(currentPathAtom) - const [newDestinationPath, setNewDestinationPath] = useAtom( - newDestinationPathAtom - ) + const [isSameDirectory, setIsSameDirectory] = useState(false) + const [isDirectoryConfirm, setIsDirectoryConfirm] = useState(false) + const [isErrorSetNewDest, setIsErrorSetNewDest] = useState(false) + const [currentPath, setCurrentPath] = useState('') + const [newDestinationPath, setNewDestinationPath] = useState('') useEffect(() => { window.core?.api @@ -34,7 +17,6 @@ export function useVaultDirectory() { ?.then((appConfig: AppConfiguration) => { setCurrentPath(appConfig.data_folder) }) - // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const setNewDestination = async () => {