mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-22 09:05:49 +05:30
refactor: do echo without cp
This commit is contained in:
@@ -45,9 +45,9 @@ export function useLinuxRegisterer() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const filesToCopyFlatpak: FileMap[] = [
|
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/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, null, 2) },
|
{ 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, null, 2) },
|
{ 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}`);
|
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 sourcePath = await join(resourceDirPath, file.source);
|
||||||
const destinationPath = await join(homeDirPath, file.destination);
|
const destinationPath = await join(homeDirPath, file.destination);
|
||||||
const copyCommand = Command.create('cp', [sourcePath, destinationPath]);
|
const copyCommand = Command.create('cp', [sourcePath, destinationPath]);
|
||||||
|
const writeCommand = Command.create('echo', [file.content || '', '>', destinationPath]);
|
||||||
|
|
||||||
const copyOutput = await copyCommand.execute();
|
if (file.content) {
|
||||||
if (copyOutput.code === 0) {
|
const writeOutput = await writeCommand.execute();
|
||||||
console.log(`File ${file.source} copied successfully to ${destinationPath}`);
|
if (writeOutput.code === 0) {
|
||||||
LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`);
|
console.log(`File ${file.destination} created successfully at ${destinationPath}`);
|
||||||
if (file.content) {
|
LOG.info("LINUX REGISTERER", `File ${file.destination} created successfully at ${destinationPath}`);
|
||||||
LOG.info("LINUX REGISTERER", `Writing content to ${destinationPath}: ${file.content}`);
|
} else {
|
||||||
const writeCommand = Command.create('echo', [file.content, '>', destinationPath]);
|
console.error(`Failed to create file ${file.destination} at ${destinationPath}:`, writeOutput.stderr);
|
||||||
const writeOutput = await writeCommand.execute();
|
LOG.error("LINUX REGISTERER", `Failed to create file ${file.destination} at ${destinationPath}: ${writeOutput.stderr}`);
|
||||||
if (writeOutput.code === 0) {
|
return { success: false, message: 'Failed to register' };
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, copyOutput.stderr);
|
const copyOutput = await copyCommand.execute();
|
||||||
LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${copyOutput.stderr}`);
|
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 {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user