1
1
mirror of https://github.com/neosubhamoy/neodlp.git synced 2026-03-22 11:25:49 +05:30

3 Commits

3 changed files with 28 additions and 27 deletions

View File

@@ -24,6 +24,7 @@
"sql:allow-execute", "sql:allow-execute",
"fs:allow-app-write", "fs:allow-app-write",
"fs:allow-app-write-recursive", "fs:allow-app-write-recursive",
"fs:allow-write-text-file",
"updater:default", "updater:default",
"process:default", "process:default",
"clipboard-manager:allow-read-text", "clipboard-manager:allow-read-text",

View File

@@ -119,11 +119,6 @@
"name": "deno", "name": "deno",
"cmd": "deno", "cmd": "deno",
"args": true "args": true
},
{
"name": "cp",
"cmd": "cp",
"args": true
} }
] ]
} }

View File

@@ -10,6 +10,7 @@ interface FileMap {
source: string; source: string;
destination: string; destination: string;
dir: string; dir: string;
content?: string;
} }
export function useLinuxRegisterer() { export function useLinuxRegisterer() {
@@ -19,6 +20,24 @@ export function useLinuxRegisterer() {
const registerToLinux = async () => { const registerToLinux = async () => {
try { try {
const isFlatpak = await invoke<boolean>('is_flatpak');
const resourceDirPath = isFlatpak ? '/app/lib/neodlp' : await resourceDir();
const homeDirPath = await homeDir();
const flatpakChromeManifestContent = {
name: "com.neosubhamoy.neodlp",
description: "NeoDLP MsgHost",
path: `${homeDirPath}/.local/bin/neodlp-msghost`,
type: "stdio",
allowed_origins: ["chrome-extension://mehopeailfjmiloiiohgicphlcgpompf/"]
};
const flatpakFirefoxManifestContent = {
name: "com.neosubhamoy.neodlp",
description: "NeoDLP MsgHost",
path: `${homeDirPath}/.local/bin/neodlp-msghost`,
type: "stdio",
allowed_extension: ["neodlp@neosubhamoy.com"]
};
const filesToCopy: FileMap[] = [ const filesToCopy: FileMap[] = [
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' }, { source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
@@ -26,21 +45,16 @@ 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/' }, { 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/' }, { 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/' }, { source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/', content: JSON.stringify(flatpakFirefoxManifestContent, null, 2) },
]; ];
const isFlatpak = await invoke<boolean>('is_flatpak');
const resourceDirPath = isFlatpak ? '/app/lib/neodlp' : await resourceDir();
const homeDirPath = await homeDir();
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}`);
if (isFlatpak) { if (isFlatpak) {
for (const file of filesToCopyFlatpak) { for (const file of filesToCopyFlatpak) {
const sourcePath = await join(resourceDirPath, file.source); const sourcePath = await join(resourceDirPath, file.source);
// const destinationDir = await join(homeDirPath, file.dir);
const destinationPath = await join(homeDirPath, file.destination); const destinationPath = await join(homeDirPath, file.destination);
const command = Command.create('cp', [sourcePath, destinationPath]); const command = Command.create('cp', [sourcePath, destinationPath]);
@@ -48,24 +62,15 @@ export function useLinuxRegisterer() {
if (output.code === 0) { if (output.code === 0) {
console.log(`File ${file.source} copied successfully to ${destinationPath}`); console.log(`File ${file.source} copied successfully to ${destinationPath}`);
LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`); LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`);
if (file.content) {
await fs.writeTextFile(destinationPath, file.content);
console.log(`Content for ${file.source} written successfully to ${destinationPath}`);
LOG.info("LINUX REGISTERER", `Content for ${file.source} written successfully to ${destinationPath}`);
}
} else { } else {
console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, output.stderr); console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, output.stderr);
LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${output.stderr}`); LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${output.stderr}`);
} }
// const dirExists = await fs.exists(destinationDir);
// if (dirExists) {
// await fs.copyFile(sourcePath, destinationPath);
// console.log(`File ${file.source} copied successfully to ${destinationPath}`);
// LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`);
// } else {
// await fs.mkdir(destinationDir, { recursive: true })
// console.log(`Created dir ${destinationDir}`);
// LOG.info("LINUX REGISTERER", `Created dir ${destinationDir}`);
// await fs.copyFile(sourcePath, destinationPath);
// console.log(`File ${file.source} copied successfully to ${destinationPath}`);
// LOG.info("LINUX REGISTERER", `File ${file.source} copied successfully to ${destinationPath}`);
// }
} }
} else { } else {
for (const file of filesToCopy) { for (const file of filesToCopy) {