mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2026-03-22 09:05:49 +05:30
refactor: fallback using per-instance flatpak check
This commit is contained in:
@@ -29,7 +29,6 @@
|
|||||||
"targets": ["deb"],
|
"targets": ["deb"],
|
||||||
"createUpdaterArtifacts": true,
|
"createUpdaterArtifacts": true,
|
||||||
"licenseFile": "../LICENSE",
|
"licenseFile": "../LICENSE",
|
||||||
"category": "Utility",
|
|
||||||
"icon": [
|
"icon": [
|
||||||
"icons/32x32.png",
|
"icons/32x32.png",
|
||||||
"icons/128x128.png",
|
"icons/128x128.png",
|
||||||
|
|||||||
33
src/App.tsx
33
src/App.tsx
@@ -4,7 +4,7 @@ import { AppContext } from "@/providers/appContextProvider";
|
|||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { arch, exeExtension } from "@tauri-apps/plugin-os";
|
import { arch, exeExtension } from "@tauri-apps/plugin-os";
|
||||||
import { downloadDir, join, resourceDir, tempDir } from "@tauri-apps/api/path";
|
import { downloadDir, join, resourceDir, tempDir } from "@tauri-apps/api/path";
|
||||||
import { useBasePathsStore, useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useDownloadStatesStore, useEnvironmentStore, useKvPairsStatesStore, useSettingsPageStatesStore } from "@/services/store";
|
import { useBasePathsStore, useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useDownloadStatesStore, useKvPairsStatesStore, useSettingsPageStatesStore } from "@/services/store";
|
||||||
import { isObjEmpty} from "@/utils";
|
import { isObjEmpty} from "@/utils";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from "@tauri-apps/plugin-shell";
|
||||||
import { useUpdateDownloadStatus } from "@/services/mutations";
|
import { useUpdateDownloadStatus } from "@/services/mutations";
|
||||||
@@ -39,10 +39,6 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
const globalDownloadStates = useDownloadStatesStore((state) => state.downloadStates);
|
const globalDownloadStates = useDownloadStatesStore((state) => state.downloadStates);
|
||||||
const setDownloadStates = useDownloadStatesStore((state) => state.setDownloadStates);
|
const setDownloadStates = useDownloadStatesStore((state) => state.setDownloadStates);
|
||||||
const setPath = useBasePathsStore((state) => state.setPath);
|
const setPath = useBasePathsStore((state) => state.setPath);
|
||||||
const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
|
||||||
const setIsFlatpak = useEnvironmentStore((state) => state.setIsFlatpak);
|
|
||||||
const setIsAppimage = useEnvironmentStore((state) => state.setIsAppimage);
|
|
||||||
const setAppDirPath = useEnvironmentStore((state) => state.setAppDirPath);
|
|
||||||
|
|
||||||
const setIsUsingDefaultSettings = useSettingsPageStatesStore((state) => state.setIsUsingDefaultSettings);
|
const setIsUsingDefaultSettings = useSettingsPageStatesStore((state) => state.setIsUsingDefaultSettings);
|
||||||
const setSettingsKey = useSettingsPageStatesStore((state) => state.setSettingsKey);
|
const setSettingsKey = useSettingsPageStatesStore((state) => state.setSettingsKey);
|
||||||
@@ -126,26 +122,6 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
};
|
};
|
||||||
}, [stopPotServer]);
|
}, [stopPotServer]);
|
||||||
|
|
||||||
// Detect sandboxed environments
|
|
||||||
useEffect(() => {
|
|
||||||
const detectEnvironment = async () => {
|
|
||||||
try {
|
|
||||||
const flatpak = await invoke<boolean>('is_flatpak');
|
|
||||||
setIsFlatpak(flatpak);
|
|
||||||
const appimage = await invoke<string | null>('is_appimage');
|
|
||||||
if (appimage) {
|
|
||||||
setIsAppimage(true);
|
|
||||||
setAppDirPath(appimage);
|
|
||||||
} else {
|
|
||||||
setIsAppimage(false);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Failed to detect environment:', e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
detectEnvironment();
|
|
||||||
}, [setIsFlatpak, setIsAppimage, setAppDirPath]);
|
|
||||||
|
|
||||||
// Listen for websocket messages
|
// Listen for websocket messages
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = listen<WebSocketMessage>('websocket-message', (event) => {
|
const unlisten = listen<WebSocketMessage>('websocket-message', (event) => {
|
||||||
@@ -208,6 +184,7 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
try {
|
try {
|
||||||
const currentArch = arch();
|
const currentArch = arch();
|
||||||
const currentExeExtension = exeExtension();
|
const currentExeExtension = exeExtension();
|
||||||
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
const downloadDirPath = await downloadDir();
|
const downloadDirPath = await downloadDir();
|
||||||
const tempDirPath = await tempDir();
|
const tempDirPath = await tempDir();
|
||||||
const resourceDirPath = await resourceDir();
|
const resourceDirPath = await resourceDir();
|
||||||
@@ -232,7 +209,7 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
initPaths();
|
initPaths();
|
||||||
}, [DOWNLOAD_DIR, setPath, isFlatpak]);
|
}, [DOWNLOAD_DIR, setPath]);
|
||||||
|
|
||||||
// Fetch app version
|
// Fetch app version
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -294,6 +271,7 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
// Check for yt-dlp auto-update
|
// Check for yt-dlp auto-update
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const handleYtDlpAutoUpdate = async () => {
|
||||||
// Only run once when both settings and KV pairs are loaded
|
// Only run once when both settings and KV pairs are loaded
|
||||||
if (!isSettingsStatePropagated || !isKvPairsStatePropagated) {
|
if (!isSettingsStatePropagated || !isKvPairsStatePropagated) {
|
||||||
console.log("Skipping yt-dlp auto-update check, waiting for configs to load...");
|
console.log("Skipping yt-dlp auto-update check, waiting for configs to load...");
|
||||||
@@ -304,6 +282,7 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
console.log("Auto-update check already performed in this session, skipping");
|
console.log("Auto-update check already performed in this session, skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
if (isFlatpak) {
|
if (isFlatpak) {
|
||||||
console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
console.log("Flatpak detected! Skipping yt-dlp auto-update");
|
||||||
return;
|
return;
|
||||||
@@ -322,6 +301,8 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
} else {
|
} else {
|
||||||
console.log("Skipping yt-dlp auto-update, either disabled or recently updated.");
|
console.log("Skipping yt-dlp auto-update, either disabled or recently updated.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
handleYtDlpAutoUpdate()
|
||||||
}, [isSettingsStatePropagated, isKvPairsStatePropagated]);
|
}, [isSettingsStatePropagated, isKvPairsStatePropagated]);
|
||||||
|
|
||||||
// Check POT server status and auto-start if enabled
|
// Check POT server status and auto-start if enabled
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { join, resourceDir, homeDir } from "@tauri-apps/api/path";
|
import { join, resourceDir, homeDir } from "@tauri-apps/api/path";
|
||||||
import * as fs from "@tauri-apps/plugin-fs";
|
import * as fs from "@tauri-apps/plugin-fs";
|
||||||
import { useKvPairs } from "@/helpers/use-kvpairs";
|
import { useKvPairs } from "@/helpers/use-kvpairs";
|
||||||
import { useEnvironmentStore, useSettingsPageStatesStore } from "@/services/store";
|
import { useSettingsPageStatesStore } from "@/services/store";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from "@tauri-apps/plugin-shell";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
interface FileMap {
|
interface FileMap {
|
||||||
source: string;
|
source: string;
|
||||||
@@ -17,7 +18,7 @@ export function useLinuxRegisterer() {
|
|||||||
|
|
||||||
const registerToLinux = async () => {
|
const registerToLinux = async () => {
|
||||||
try {
|
try {
|
||||||
const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
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 = {
|
const flatpakChromeManifestContent = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEnvironmentStore, useSettingsPageStatesStore } from "@/services/store";
|
import { useSettingsPageStatesStore } from "@/services/store";
|
||||||
import { useKvPairs } from "@/helpers/use-kvpairs";
|
import { useKvPairs } from "@/helpers/use-kvpairs";
|
||||||
import { Command } from "@tauri-apps/plugin-shell";
|
import { Command } from "@tauri-apps/plugin-shell";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
@@ -17,7 +17,7 @@ export function useYtDlpUpdater() {
|
|||||||
|
|
||||||
const updateYtDlp = async () => {
|
const updateYtDlp = async () => {
|
||||||
const CURRENT_TIMESTAMP = Date.now();
|
const CURRENT_TIMESTAMP = Date.now();
|
||||||
const isFlatpak = useEnvironmentStore(state => state.isFlatpak);
|
const isFlatpak = await invoke<boolean>('is_flatpak');
|
||||||
setIsUpdatingYtDlp(true);
|
setIsUpdatingYtDlp(true);
|
||||||
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
LOG.info('NEODLP', 'Updating yt-dlp to latest version');
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BasePathsStore, CurrentVideoMetadataStore, DownloadActionStatesStore, DownloaderPageStatesStore, DownloadStatesStore, EnvironmentStore, KvPairsStatesStore, LibraryPageStatesStore, LogsStore, SettingsPageStatesStore } from '@/types/store';
|
import { BasePathsStore, CurrentVideoMetadataStore, DownloadActionStatesStore, DownloaderPageStatesStore, DownloadStatesStore, KvPairsStatesStore, LibraryPageStatesStore, LogsStore, SettingsPageStatesStore } from '@/types/store';
|
||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
export const useBasePathsStore = create<BasePathsStore>((set) => ({
|
export const useBasePathsStore = create<BasePathsStore>((set) => ({
|
||||||
@@ -352,12 +352,3 @@ export const useLogsStore = create<LogsStore>((set) => ({
|
|||||||
addLog: (log) => set((state) => ({ logs: [...state.logs, log] })),
|
addLog: (log) => set((state) => ({ logs: [...state.logs, log] })),
|
||||||
clearLogs: () => set(() => ({ logs: [] }))
|
clearLogs: () => set(() => ({ logs: [] }))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useEnvironmentStore = create<EnvironmentStore>((set) => ({
|
|
||||||
isFlatpak: false,
|
|
||||||
isAppimage: false,
|
|
||||||
appDirPath: null,
|
|
||||||
setIsFlatpak: (isFlatpak) => set(() => ({ isFlatpak })),
|
|
||||||
setIsAppimage: (isAppimage) => set(() => ({ isAppimage })),
|
|
||||||
setAppDirPath: (path) => set(() => ({ appDirPath: path }))
|
|
||||||
}));
|
|
||||||
|
|||||||
@@ -152,12 +152,3 @@ export interface LogsStore {
|
|||||||
addLog: (log: Log) => void;
|
addLog: (log: Log) => void;
|
||||||
clearLogs: () => void;
|
clearLogs: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EnvironmentStore {
|
|
||||||
isFlatpak: boolean;
|
|
||||||
isAppimage: boolean;
|
|
||||||
appDirPath: string | null;
|
|
||||||
setIsFlatpak: (isFlatpak: boolean) => void;
|
|
||||||
setIsAppimage: (isAppimage: boolean) => void;
|
|
||||||
setAppDirPath: (path: string) => void;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user