From f0e31cd15e8d9b7abeb18b1470bacb0e2fa26d7a Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Thu, 26 Feb 2026 14:42:50 +0530 Subject: [PATCH] refactor: do echo without cp --- src/helpers/use-linux-registerer.ts | 42 +++++++++++++++-------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/helpers/use-linux-registerer.ts b/src/helpers/use-linux-registerer.ts index dc8dcfc..07eb611 100644 --- a/src/helpers/use-linux-registerer.ts +++ b/src/helpers/use-linux-registerer.ts @@ -45,9 +45,9 @@ export function useLinuxRegisterer() { ]; const filesToCopyFlatpak: FileMap[] = [ - { source: 'chrome.json', destination: '.config/google-chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/google-chrome/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent, null, 2) }, - { source: 'chrome.json', destination: '.config/chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/chromium/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent, null, 2) }, - { source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/', content: JSON.stringify(flatpakFirefoxManifestContent, null, 2) }, + { source: 'chrome.json', destination: '.config/google-chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/google-chrome/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, + { source: 'chrome.json', destination: '.config/chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/chromium/NativeMessagingHosts/', content: JSON.stringify(flatpakChromeManifestContent) }, + { source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/', content: JSON.stringify(flatpakFirefoxManifestContent) }, ]; LOG.info("LINUX REGISTERER", `Is Flatpak: ${isFlatpak}, Resource dir: ${resourceDirPath}, Home dir: ${homeDirPath}`); @@ -57,26 +57,28 @@ export function useLinuxRegisterer() { const sourcePath = await join(resourceDirPath, file.source); const destinationPath = await join(homeDirPath, file.destination); const copyCommand = Command.create('cp', [sourcePath, destinationPath]); + const writeCommand = Command.create('echo', [file.content || '', '>', destinationPath]); - const copyOutput = await copyCommand.execute(); - if (copyOutput.code === 0) { - console.log(`File ${file.source} copied successfully to ${destinationPath}`); - LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`); - if (file.content) { - LOG.info("LINUX REGISTERER", `Writing content to ${destinationPath}: ${file.content}`); - const writeCommand = Command.create('echo', [file.content, '>', destinationPath]); - const writeOutput = await writeCommand.execute(); - if (writeOutput.code === 0) { - console.log(`Content written successfully to ${destinationPath}`); - LOG.info("LINUX REGISTERER", `Content written successfully to ${destinationPath}`); - } else { - console.error(`Failed to write content to ${destinationPath}:`, writeOutput.stderr); - LOG.error("LINUX REGISTERER", `Failed to write content to ${destinationPath}: ${writeOutput.stderr}`); - } + if (file.content) { + const writeOutput = await writeCommand.execute(); + if (writeOutput.code === 0) { + console.log(`File ${file.destination} created successfully at ${destinationPath}`); + LOG.info("LINUX REGISTERER", `File ${file.destination} created successfully at ${destinationPath}`); + } else { + console.error(`Failed to create file ${file.destination} at ${destinationPath}:`, writeOutput.stderr); + LOG.error("LINUX REGISTERER", `Failed to create file ${file.destination} at ${destinationPath}: ${writeOutput.stderr}`); + return { success: false, message: 'Failed to register' }; } } else { - console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, copyOutput.stderr); - LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${copyOutput.stderr}`); + const copyOutput = await copyCommand.execute(); + if (copyOutput.code === 0) { + console.log(`File ${file.source} copied successfully to ${destinationPath}`); + LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`); + } else { + console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, copyOutput.stderr); + LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${copyOutput.stderr}`); + return { success: false, message: 'Failed to register' }; + } } } } else {