mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-22 09:05:49 +05:30
refactor: dynamically generate msghost manifest for flatpak
This commit is contained in:
@@ -24,6 +24,11 @@
|
|||||||
"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-config-read",
|
||||||
|
"fs:allow-config-read-recursive",
|
||||||
|
"fs:allow-config-write",
|
||||||
|
"fs:allow-config-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",
|
||||||
|
|||||||
@@ -64,11 +64,6 @@
|
|||||||
"name": "powershell",
|
"name": "powershell",
|
||||||
"cmd": "powershell",
|
"cmd": "powershell",
|
||||||
"args": true
|
"args": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cp",
|
|
||||||
"cmd": "cp",
|
|
||||||
"args": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -119,11 +114,6 @@
|
|||||||
"name": "deno",
|
"name": "deno",
|
||||||
"cmd": "deno",
|
"cmd": "deno",
|
||||||
"args": true
|
"args": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "cp",
|
|
||||||
"cmd": "cp",
|
|
||||||
"args": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { useKvPairs } from "@/helpers/use-kvpairs";
|
|||||||
import { useSettingsPageStatesStore } from "@/services/store";
|
import { useSettingsPageStatesStore } from "@/services/store";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { useLogger } from "@/helpers/use-logger";
|
import { useLogger } from "@/helpers/use-logger";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
|
||||||
|
|
||||||
interface FileMap {
|
interface FileMap {
|
||||||
source: string;
|
source: string;
|
||||||
@@ -34,38 +33,45 @@ export function useLinuxRegisterer() {
|
|||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
const resourceDirPath = isFlatpak ? '/app/lib/neodlp' : await resourceDir();
|
const resourceDirPath = isFlatpak ? '/app/lib/neodlp' : await resourceDir();
|
||||||
const homeDirPath = await homeDir();
|
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"]
|
||||||
|
};
|
||||||
|
|
||||||
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) {
|
||||||
|
await fs.writeTextFile('/app/lib/neodlp/chrome.json', JSON.stringify(flatpakChromeManifestContent, null, 2));
|
||||||
|
await fs.writeTextFile('/app/lib/neodlp/firefox.json', JSON.stringify(flatpakFirefoxManifestContent, null, 2));
|
||||||
|
|
||||||
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 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 output = await command.execute();
|
const dirExists = await fs.exists(destinationDir);
|
||||||
if (output.code === 0) {
|
if (dirExists) {
|
||||||
|
await fs.copyFile(sourcePath, destinationPath);
|
||||||
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}`);
|
||||||
} else {
|
} else {
|
||||||
console.error(`Failed to copy file ${file.source} to ${destinationPath}:`, output.stderr);
|
await fs.mkdir(destinationDir, { recursive: true })
|
||||||
LOG.error("LINUX REGISTERER", `Failed to copy file ${file.source} to ${destinationPath}: ${output.stderr}`);
|
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}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user