-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
844a77e
commit a65ced9
Showing
5 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {exec} from 'child_process' | ||
|
||
export async function execPromise(script: string) { | ||
await new Promise<string>((resolve, reject) => { | ||
console.log(`Will run exec promise: ${script}`) | ||
exec(script, (error, stdout, stderr) => { | ||
if (error) { | ||
console.log(`Error in sudo promise: ${error}`, stdout, stderr) | ||
reject(`Error: ${error.message}`) | ||
} else { | ||
console.log('Sudo promise success', { | ||
stdout | ||
}) | ||
resolve(stdout.toString()) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {spawn} from 'child_process' | ||
import {dialog} from 'electron' | ||
import fs from 'fs' | ||
import Main from '..' | ||
import {installQZTray} from './install' | ||
|
||
const isMac = process.platform === 'darwin' | ||
|
||
let isOpening = false | ||
|
||
export async function openQZTray(): Promise<{success: boolean; message: string}> { | ||
if (isOpening) { | ||
return { | ||
success: false, | ||
message: 'Ya se está abriendo' | ||
} | ||
} | ||
|
||
isOpening = true | ||
|
||
try { | ||
const path = { | ||
mac: '/Applications/QZ Tray.app/Contents/MacOS/QZ Tray', | ||
win: `${process.env.PROGRAMFILES}\\QZ Tray\\qz-tray-console.exe` | ||
}[isMac ? 'mac' : 'win'] | ||
|
||
// file exists | ||
if (!fs.existsSync(path)) { | ||
const choice = dialog.showMessageBoxSync(Main.mainWindow, { | ||
type: 'question', | ||
buttons: ['Yes', 'No'], | ||
title: 'Instalar QZ Tray', | ||
message: 'No se encontró QZ Tray, ¿Quieres instalarlo?' | ||
}) | ||
if (choice === 0) { | ||
installQZTray() | ||
} | ||
isOpening = false | ||
return { | ||
success: false, | ||
message: 'No se encontró QZ Tray' | ||
} | ||
} | ||
|
||
const script = { | ||
mac: '"/Applications/QZ Tray.app/Contents/MacOS/QZ Tray"', | ||
win: `"%PROGRAMFILES%\\QZ Tray\\qz-tray.exe"` | ||
}[isMac ? 'mac' : 'win'] | ||
|
||
const subprocess = spawn(script, [], { | ||
detached: true, | ||
stdio: 'ignore', | ||
shell: true | ||
}) | ||
|
||
subprocess.unref() | ||
|
||
isOpening = false | ||
return { | ||
success: true, | ||
message: 'Se abrió con éxito' | ||
} | ||
} catch (error) { | ||
isOpening = false | ||
return { | ||
success: false, | ||
message: error.message | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters