(chore): initial MVP release v0.1.0

This commit is contained in:
2025-04-28 23:49:42 +05:30
commit c73022b1a2
200 changed files with 24562 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { check as checkAppUpdate, Update } from "@tauri-apps/plugin-updater";
import { relaunch as relaunchApp } from "@tauri-apps/plugin-process";
import { useSettingsPageStatesStore } from "@/services/store";
export default function useAppUpdater() {
const setIsCheckingAppUpdate = useSettingsPageStatesStore(state => state.setIsCheckingAppUpdate);
const setAppUpdate = useSettingsPageStatesStore(state => state.setAppUpdate);
const setIsUpdating = useSettingsPageStatesStore(state => state.setIsUpdatingApp);
const setDownloadProgress = useSettingsPageStatesStore(state => state.setAppUpdateDownloadProgress);
const checkForAppUpdate = async () => {
setIsCheckingAppUpdate(true);
try {
const update = await checkAppUpdate();
if (update) {
setAppUpdate(update);
console.log(`app update available v${update.version}`);
}
} catch (error) {
console.error(error);
} finally {
setIsCheckingAppUpdate(false);
}
}
const downloadAndInstallAppUpdate = async (update: Update) => {
setIsUpdating(true);
let downloaded = 0;
let contentLength: number | undefined = 0;
await update.downloadAndInstall((event) => {
switch (event.event) {
case 'Started':
contentLength = event.data.contentLength;
console.log(`started downloading ${event.data.contentLength} bytes`);
break;
case 'Progress':
downloaded += event.data.chunkLength;
setDownloadProgress(downloaded / (contentLength || 0));
console.log(`downloaded ${downloaded} from ${contentLength}`);
break;
case 'Finished':
console.log('download finished');
setIsUpdating(false);
break;
}
});
await relaunchApp();
}
return {
checkForAppUpdate,
downloadAndInstallAppUpdate
}
}

View File

@@ -0,0 +1,25 @@
import { useSaveKvPair } from "@/services/mutations";
import { useKvPairsStatesStore } from "@/services/store";
import { useQueryClient } from "@tanstack/react-query";
export function useKvPairs() {
const queryClient = useQueryClient();
const setKvPairsKey = useKvPairsStatesStore(state => state.setKvPairsKey);
const kvPairSaver = useSaveKvPair();
const saveKvPair = (key: string, value: unknown) => {
kvPairSaver.mutate({ key, value }, {
onSuccess: (data) => {
setKvPairsKey(key, value);
console.log("KvPairs key saved successfully:", data);
queryClient.invalidateQueries({ queryKey: ["kv-pairs"] });
},
onError: (error) => {
console.error(`Error saving kvpairs key: ${key}:`, error);
queryClient.invalidateQueries({ queryKey: ["kv-pairs"] });
}
});
};
return { saveKvPair };
}

View File

@@ -0,0 +1,47 @@
import { join, resourceDir, homeDir } from "@tauri-apps/api/path";
import * as fs from "@tauri-apps/plugin-fs";
import { useKvPairs } from "@/helpers/use-kvpairs";
import { useSettingsPageStatesStore } from "@/services/store";
export function useMacOsRegisterer() {
const { saveKvPair } = useKvPairs();
const appVersion = useSettingsPageStatesStore(state => state.appVersion);
const registerToMac = async () => {
try {
const filesToCopy = [
{ source: 'neodlp-autostart.plist', destination: 'Library/LaunchAgents/com.neosubhamoy.neodlp.plist', dir: 'Library/LaunchAgents/' },
{ source: 'neodlp-msghost.json', destination: 'Library/Application Support/Google/Chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Google/Chrome/NativeMessagingHosts/' },
{ source: 'neodlp-msghost.json', destination: 'Library/Application Support/Chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Chromium/NativeMessagingHosts/' },
{ source: 'neodlp-msghost-moz.json', destination: 'Library/Application Support/Mozilla/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Mozilla/NativeMessagingHosts/' },
];
const resourceDirPath = await resourceDir();
const homeDirPath = await homeDir();
for (const file of filesToCopy) {
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}`);
} else {
await fs.mkdir(destinationDir, { recursive: true })
console.log(`Created dir ${destinationDir}`);
await fs.copyFile(sourcePath, destinationPath);
console.log(`File ${file.source} copied successfully to ${destinationPath}`);
}
}
saveKvPair('macos_registered_version', appVersion);
return { success: true, message: 'Registered successfully' }
} catch (error) {
console.error('Error copying files:', error);
return { success: false, message: 'Failed to register' }
}
}
return { registerToMac };
}

View File

@@ -0,0 +1,68 @@
import { useToast } from "@/hooks/use-toast";
import { useResetSettings, useSaveSettingsKey } from "@/services/mutations";
import { useSettingsPageStatesStore } from "@/services/store";
import { useQueryClient } from "@tanstack/react-query";
import { invoke } from "@tauri-apps/api/core";
export function useSettings() {
const { toast } = useToast();
const queryClient = useQueryClient();
const setSettingsKey = useSettingsPageStatesStore(state => state.setSettingsKey);
const resetSettingsState = useSettingsPageStatesStore(state => state.resetSettings);
const settingsKeySaver = useSaveSettingsKey();
const settingsReseter = useResetSettings();
const saveSettingsKey = (key: string, value: unknown) => {
settingsKeySaver.mutate({ key, value }, {
onSuccess: (data) => {
setSettingsKey(key, value);
console.log("Settings key saved successfully:", data);
queryClient.invalidateQueries({ queryKey: ["settings"] });
},
onError: (error) => {
console.error("Error saving settings key:", error);
queryClient.invalidateQueries({ queryKey: ["settings"] });
toast({
title: "Failed to update settings",
description: `Failed to update ${key}`,
variant: "destructive",
});
}
});
};
const resetSettings = () => {
settingsReseter.mutate(undefined, {
onSuccess: async () => {
try {
await invoke("reset_config");
resetSettingsState();
console.log("Settings reset successfully");
queryClient.invalidateQueries({ queryKey: ["settings"] });
toast({
title: "Settings reset successfully",
description: "All settings have been reset to default.",
});
} catch (error) {
console.error("Error resetting settings:", error);
toast({
title: "Failed to reset settings",
description: "Failed to reset settings to default.",
variant: "destructive",
});
return;
}
},
onError: (error) => {
console.error("Error resetting settings:", error);
toast({
title: "Failed to reset settings",
description: "Failed to reset settings to default.",
variant: "destructive",
});
}
});
};
return { saveSettingsKey, resetSettings };
}

View File

@@ -0,0 +1,34 @@
import { useSettingsPageStatesStore } from "@/services/store";
import { useKvPairs } from "@/helpers/use-kvpairs";
import { Command } from "@tauri-apps/plugin-shell";
import { platform } from "@tauri-apps/plugin-os";
export function useYtDlpUpdater() {
const { saveKvPair } = useKvPairs();
const ytDlpUpdateChannel = useSettingsPageStatesStore(state => state.settings.ytdlp_update_channel);
const setIsUpdatingYtDlp = useSettingsPageStatesStore((state) => state.setIsUpdatingYtDlp);
const setYtDlpVersion = useSettingsPageStatesStore((state) => state.setYtDlpVersion);
const currentPlatform = platform();
const updateYtDlp = async () => {
const CURRENT_TIMESTAMP = Date.now();
setIsUpdatingYtDlp(true);
try {
const command = currentPlatform === 'linux' ? Command.create('pkexec', ['yt-dlp', '--update-to', ytDlpUpdateChannel]) : Command.sidecar('binaries/yt-dlp', ['--update-to', ytDlpUpdateChannel]);
const output = await command.execute();
if (output.code === 0) {
console.log("yt-dlp updated successfully:", output.stdout);
saveKvPair('ytdlp_update_last_check', CURRENT_TIMESTAMP);
setYtDlpVersion(null);
} else {
console.error("Failed to update yt-dlp:", output.stderr);
}
} catch (e) {
console.error('Failed to update yt-dlp:', e);
} finally {
setIsUpdatingYtDlp(false);
}
}
return { updateYtDlp };
}