Skip to content

Commit

Permalink
fix: app log not being printed (janhq#1790)
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Jan 25, 2024
1 parent 7ed523e commit b2ff76c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
30 changes: 14 additions & 16 deletions core/src/node/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
30 changes: 6 additions & 24 deletions web/hooks/useVaultDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
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
?.getAppConfigurations()
?.then((appConfig: AppConfiguration) => {
setCurrentPath(appConfig.data_folder)
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const setNewDestination = async () => {
Expand Down

0 comments on commit b2ff76c

Please sign in to comment.