1
1
mirror of https://github.com/neosubhamoy/neodlp.git synced 2026-03-22 06:55:51 +05:30

refactor: do echo without cp

This commit is contained in:
2026-02-26 14:42:50 +05:30
Verified
parent f2bd8bd4df
commit f0e31cd15e

View File

@@ -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 {