mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-22 09:05:49 +05:30
refactor: test flatpak host config copy
This commit is contained in:
@@ -3,6 +3,7 @@ import * as fs from "@tauri-apps/plugin-fs";
|
|||||||
import { useKvPairs } from "@/helpers/use-kvpairs";
|
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";
|
||||||
|
|
||||||
interface FileMap {
|
interface FileMap {
|
||||||
source: string;
|
source: string;
|
||||||
@@ -13,6 +14,7 @@ interface FileMap {
|
|||||||
export function useLinuxRegisterer() {
|
export function useLinuxRegisterer() {
|
||||||
const { saveKvPair } = useKvPairs();
|
const { saveKvPair } = useKvPairs();
|
||||||
const appVersion = useSettingsPageStatesStore(state => state.appVersion);
|
const appVersion = useSettingsPageStatesStore(state => state.appVersion);
|
||||||
|
const LOG = useLogger();
|
||||||
|
|
||||||
const registerToLinux = async () => {
|
const registerToLinux = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -22,15 +24,39 @@ export function useLinuxRegisterer() {
|
|||||||
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.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_http.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
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/chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: '.config/chromium/NativeMessagingHosts/' },
|
||||||
|
{ source: 'firefox.json', destination: '.mozilla/native-messaging-hosts/com.neosubhamoy.neodlp.json', dir: '.mozilla/native-messaging-hosts/' },
|
||||||
|
];
|
||||||
|
|
||||||
const isFlatpak = await invoke<boolean>('is_flatpak');
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
const resourceDirPath = await resourceDir();
|
const resourceDirPath = isFlatpak ? '/app/lib/neodlp' : await resourceDir();
|
||||||
const homeDirPath = await homeDir();
|
const homeDirPath = await homeDir();
|
||||||
|
|
||||||
if (isFlatpak) {
|
LOG.info("LINUX REGISTERER", `Is Flatpak: ${isFlatpak}, Resource dir: ${resourceDirPath}, Home dir: ${homeDirPath}`);
|
||||||
saveKvPair('linux_registered_version', appVersion);
|
|
||||||
return { success: true, message: 'Registered successfully' }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isFlatpak) {
|
||||||
|
for (const file of filesToCopyFlatpak) {
|
||||||
|
const sourcePath = await join(resourceDirPath, file.source);
|
||||||
|
const destinationDir = await join(homeDirPath, file.dir);
|
||||||
|
const destinationPath = await join(homeDirPath, file.destination);
|
||||||
|
|
||||||
|
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 {
|
||||||
for (const file of filesToCopy) {
|
for (const file of filesToCopy) {
|
||||||
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);
|
||||||
@@ -40,17 +66,22 @@ export function useLinuxRegisterer() {
|
|||||||
if (dirExists) {
|
if (dirExists) {
|
||||||
await fs.copyFile(sourcePath, destinationPath);
|
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}`);
|
||||||
} else {
|
} else {
|
||||||
await fs.mkdir(destinationDir, { recursive: true })
|
await fs.mkdir(destinationDir, { recursive: true })
|
||||||
console.log(`Created dir ${destinationDir}`);
|
console.log(`Created dir ${destinationDir}`);
|
||||||
|
LOG.info("LINUX REGISTERER", `Created dir ${destinationDir}`);
|
||||||
await fs.copyFile(sourcePath, destinationPath);
|
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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveKvPair('linux_registered_version', appVersion);
|
saveKvPair('linux_registered_version', appVersion);
|
||||||
return { success: true, message: 'Registered successfully' }
|
return { success: true, message: 'Registered successfully' }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error copying files:', error);
|
console.error('Error copying files:', error);
|
||||||
|
LOG.error("LINUX REGISTERER", `Error copying files: ${error}`);
|
||||||
return { success: false, message: 'Failed to register' }
|
return { success: false, message: 'Failed to register' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user