Skip to content

Commit

Permalink
check if has print manager first
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslopezj committed Jul 20, 2023
1 parent 8ac06b5 commit ddbe0be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions app/App/print/restartPrintManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,39 @@ import {exec} from 'child_process'
import tcpPortUsed from 'tcp-port-used'

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
const isMac = process.platform === 'darwin'

export function fileExists(): Promise<boolean> {
return new Promise(resolve => {
if (isMac) {
// check if file exists in mac
exec('ls "/Applications/JSPrintManager5.app"', error => {
console.log('error', error)
if (error) {
resolve(false)
} else {
resolve(true)
}
})
} else {
exec(
'dir "C:\\Program Files (x86)\\Neodynamic\\jspm for Windows\\v5.0\\jspm5.exe"',
error => {
if (error) {
resolve(false)
} else {
resolve(true)
}
}
)
}
})
}

export async function restartPrintManager(): Promise<{success: boolean; message: string}> {
try {
if (!(await fileExists())) return {success: false, message: 'noPrintManager'}

let processes = [...(await find('name', 'jspm')), ...(await find('port', 25443))]
// uniq by pid
processes = processes.filter(
Expand All @@ -24,12 +54,11 @@ export async function restartPrintManager(): Promise<{success: boolean; message:
await tcpPortUsed.waitUntilFree(25443, 500, 30000)
await sleep(20000)
} catch (error) {
messages.push(`No se pudo cerrar el proceso ${proc.pid}`)
messages.push(`No se pudo cerrar el proceso ${proc.pid}. ${error.message}`)
}
}

// open the same app again
const isMac = process.platform === 'darwin'
if (isMac) {
exec('open -a "/Applications/JSPrintManager5.app"')
messages.push(`Se abrió la aplicación JSPrintManager5.app`)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "justo-crisp",
"version": "0.4.2",
"version": "0.4.4",
"license": "MIT",
"description": "Crisp POS",
"author": "nicolaslopezj",
Expand Down

0 comments on commit ddbe0be

Please sign in to comment.