Skip to content

Commit

Permalink
Merge pull request #505 from axonops/for-ticket-470
Browse files Browse the repository at this point in the history
Attempt to reduce the number of auth requests. #470
  • Loading branch information
millerjp authored Oct 16, 2024
2 parents f67a9de + d43185f commit 6571ae1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 20 deletions.
48 changes: 42 additions & 6 deletions custom_node_modules/main/pty.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 36 additions & 14 deletions main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ global.FS = require('fs-extra')
*/
global.Path = require('path')

/**
* Node.js OS module
* Used for operating system-related utilities and properties
*/
global.OS = require('os')

/**
* Import extra modules needed in the main thread
*
Expand Down Expand Up @@ -792,24 +798,40 @@ App.on('second-instance', () => {

// Request to get the public key from the keys generator tool
IPCMain.on('public-key:get', (_, id) => {
// Define the bin folder path
// let binFolder = Path.join((extraResourcesPath != null ? Path.join(extraResourcesPath, 'main') : Path.join(__dirname)), 'bin')
let binFolder = Path.join((extraResourcesPath != null ? Path.join(__dirname, '..', '..', 'main') : Path.join(__dirname)), 'bin', 'keys_generator')
let runKeysGenerator = () => {
// Define the bin folder path
// let binFolder = Path.join((extraResourcesPath != null ? Path.join(extraResourcesPath, 'main') : Path.join(__dirname)), 'bin')
let binFolder = Path.join((extraResourcesPath != null ? Path.join(__dirname, '..', '..', 'main') : Path.join(__dirname)), 'bin', 'keys_generator')

// Switch to the single-file mode
try {
if (!FS.lstatSync(binFolder).isDirectory())
binFolder = Path.join(binFolder, '..')
} catch (e) {}
// Switch to the single-file mode
try {
if (!FS.lstatSync(binFolder).isDirectory())
binFolder = Path.join(binFolder, '..')
} catch (e) {}

// Run the keys generator tool
let binCall = `./keys_generator`

// Run the keys generator tool
let binCall = `./keys_generator`
// If the host is Windows
binCall = (process.platform == 'win32') ? `keys_generator.exe` : binCall

// If the host is Windows
binCall = (process.platform == 'win32') ? `keys_generator.exe` : binCall
// Execute the command, get the public key, and send it to the renderer thread
Terminal.run(`cd "${binFolder}" && ${binCall}`, (err, publicKey, stderr) => views.main.webContents.send(`public-key:${id}`, (err || stderr) ? '' : publicKey))
}

try {
if (OS.platform() != 'darwin') {
runKeysGenerator()
throw 0
}

Modules.Pty.runKeysGenerator((publicKey) => {
if (publicKey != null)
return views.main.webContents.send(`public-key:${id}`, publicKey)

// Execute the command, get the public key, and send it to the renderer thread
Terminal.run(`cd "${binFolder}" && ${binCall}`, (err, publicKey, stderr) => views.main.webContents.send(`public-key:${id}`, (err || stderr) ? '' : publicKey))
runKeysGenerator()
})
} catch (e) {}
})

/**
Expand Down

0 comments on commit 6571ae1

Please sign in to comment.