1
1
mirror of https://github.com/neosubhamoy/pytubepp-helper.git synced 2026-02-04 11:22:22 +05:30

(feat): added initial update check and removed context menu in production

This commit is contained in:
2025-02-12 13:48:08 +05:30
Verified
parent c9dc388a10
commit f6686f7e37
7 changed files with 279 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
import React from "react"
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
@@ -8,9 +8,19 @@ import { WebSocketMessage } from "@/types";
import { sendStreamInfo } from "@/lib/utils";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import { check as checkAppUpdate } from "@tauri-apps/plugin-updater";
import { isPermissionGranted, requestPermission, sendNotification } from "@tauri-apps/plugin-notification";
function App({ children }: { children: React.ReactNode }) {
const appWindow = getCurrentWebviewWindow()
const [isAppUpdateChecked, setIsAppUpdateChecked] = useState(false);
// Prevent context menu in production
if (!import.meta.env.DEV) {
document.oncontextmenu = (event) => {
event.preventDefault()
}
}
useEffect(() => {
const handleCloseRequested = (event: any) => {
@@ -49,6 +59,32 @@ function App({ children }: { children: React.ReactNode }) {
};
}, []);
useEffect(() => {
const checkForUpdates = async () => {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
setIsAppUpdateChecked(true);
try {
const update = await checkAppUpdate();
if (update) {
console.log(`found update ${update.version} from ${update.date} with notes ${update.body}`);
if (permissionGranted) {
sendNotification({ title: 'Update Available', body: 'A new version of pytubepp-helper is available. Please update to the latest version.' });
}
}
} catch (error) {
console.error(error);
}
};
if (!isAppUpdateChecked) {
checkForUpdates();
}
}, [])
return (
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<TooltipProvider delayDuration={1000}>