Skip to content

Commit

Permalink
Added check for new updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoroney committed Jan 24, 2025
1 parent 57c2232 commit 09e0a1d
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 50 deletions.
4 changes: 2 additions & 2 deletions AutoSubs-App/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "autosubs"
version = "2.0.0"
description = "A Tauri App"
authors = ["you"]
description = "Automatic Custom Subtitles"
authors = ["Tom Moroney"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 3 additions & 0 deletions AutoSubs-App/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
},
{
"url": "http://localhost:*"
},
{
"url": "https://api.github.com/repos/tmoroney/auto-subs/releases/latest"
}
],
"deny": [
Expand Down
31 changes: 21 additions & 10 deletions AutoSubs-App/src-tauri/resources/AutoSubs V2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ if os_name == "Windows" then
int ShellExecuteA(void* hwnd, const char* lpOperation, const char* lpFile, const char* lpParameters, const char* lpDirectory, int nShowCmd);
]]

-- Get the storage path for the files used by the script
storage_path = os.getenv("APPDATA") .. "/Blackmagic Design/DaVinci Resolve/Support/Fusion/Scripts/Utility/AutoSubs/"

-- Get path to the main AutoSubs app and modules
local install_path = assert(read_file(storage_path .. "install_path.txt"))
install_path = string.gsub(install_path, "\\", "/")
main_app = install_path .. "/AutoSubs.exe"
modules_path = install_path .. "/resources/modules/"
local install_path = assert(os.getenv("AUTOSUBS_INSTALL_PATH"), "Environment variable AUTOSUBS_INSTALL_PATH not set")
-- Convert the install path to a wide-character string (handle Unicode characters)
install_path = to_wide_string(install_path)
main_app = install_path .. "\\AutoSubs.exe"
storage_path = install_path .. "\\resources\\AutoSubs\\"
modules_path = install_path .. "\\resources\\modules\\"

-- Windows commands to open and close main app
command_open = 'start "" "' .. main_app .. '"'
Expand Down Expand Up @@ -459,12 +458,24 @@ function AddSubtitles(filePath, trackIndex, templateName, textFormat, removePunc
end

local timeline = project:GetCurrentTimeline()
local markInOut = timeline:GetMarkInOut()
local timelineStart = timeline:GetStartFrame()
local timelineEnd = timeline:GetEndFrame()

local markIn = data["mark_in"] or (markInOut.audio["in"] and markInOut.audio["in"] + timelineStart) or timelineStart
local markOut = data["mark_out"] or (markInOut.audio["out"] and markInOut.audio["out"] + timelineStart) or timelineEnd
local markIn = data["mark_in"]
local markOut = data["mark_out"]

if not markIn or not markOut then
local success, err = pcall(function()
local markInOut = timeline:GetMarkInOut()
markIn = (markInOut.audio["in"] and markInOut.audio["in"] + timelineStart) or timelineStart
markOut = (markInOut.audio["out"] and markInOut.audio["out"] + timelineStart) or timelineEnd
end)

if not success then
markIn = timelineStart
markOut = timelineEnd
end
end

if trackIndex == "0" or trackIndex == "" or not CheckTrackEmpty(trackIndex, markIn, markOut) then
trackIndex = timeline:GetTrackCount("video") + 1
Expand Down
2 changes: 1 addition & 1 deletion AutoSubs-App/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2.0.0",
"productName": "AutoSubs",
"version": "2.0.0",
"version": "2.1.7",
"identifier": "com.autosubs.app",
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
7 changes: 3 additions & 4 deletions AutoSubs-App/src-tauri/windows/hooks.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
CopyFiles "$INSTDIR\resources\AutoSubs V2.lua" "$APPDATA\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Utility"
CopyFiles "$INSTDIR\resources\AutoSubs" "$APPDATA\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Utility"

; Write the installation path to a simple text file
FileOpen $0 "$APPDATA\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Utility\AutoSubs\install_path.txt" w
FileWrite $0 $INSTDIR
FileClose $0
; Set the installation path as an environment variable
WriteRegStr HKCU "Environment" "AUTOSUBS_INSTALL_PATH" "$INSTDIR"
System::Call 'Kernel32::SendMessageTimeoutA(i 0xFFFF, i ${WM_SETTINGCHANGE}, i 0, t "Environment", i 0, i 5000, *i .r0)'
!macroend
88 changes: 77 additions & 11 deletions AutoSubs-App/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@/components/ui/tooltip";
import { Button } from "@/components/ui/button";
import { ModeToggle } from "@/components/mode-toggle";
import { Search, LifeBuoy, HeartHandshake, Github, Speech, ChevronRight, House } from "lucide-react";
import { Search, LifeBuoy, HeartHandshake, Github, Speech, ChevronRight, House, Download } from "lucide-react";
// import { Paintbrush, SwatchBook } from "lucide-react";
import {
Dialog,
Expand All @@ -28,6 +28,7 @@ import {
} from "@/components/ui/dialog"
import { ScrollArea } from "@/components/ui/scroll-area";
import { useGlobal } from "@/GlobalContext";
import { platform } from '@tauri-apps/plugin-os';

const pathNames = {
"/": "Generate Subtitles",
Expand Down Expand Up @@ -66,6 +67,7 @@ const tutorialSections = [
];

function App() {

return (
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<Router>
Expand All @@ -89,13 +91,29 @@ function App() {

function NavigationHeader() {

const { checkForUpdates } = useGlobal();
const [updateInfo, setUpdateInfo] = useState<string[]>([]);
const [updateDialogOpen, setUpdateDialogOpen] = useState(false);

useEffect(() => {
async function fetchUpdateInfo() {
let info = await checkForUpdates();
if (info != null) {
let changes = info.split('\r\n').map(change => change.split("- ")[1]);
setUpdateInfo(changes);
}
}
fetchUpdateInfo();
}, []);

const location = useLocation();
const currentPath = location.pathname;

return (
<>
<header className="sticky top-0 z-10 flex min-h-[57px] items-center gap-1 border-b bg-background px-4">
<h1 className="text-xl font-semibold">{pathNames[currentPath as keyof typeof pathNames]}</h1>

<a href="https://www.buymeacoffee.com/tmoroney" target="_blank" rel="noopener noreferrer" className="ml-auto">
<Button
variant="link"
Expand All @@ -106,16 +124,27 @@ function NavigationHeader() {
Support AutoSubs
</Button>
</a>
<a href="https://github.com/tmoroney/auto-subs" target="_blank" rel="noopener noreferrer">
{updateInfo.length > 0 ? (
<Button
variant="outline"
size="sm"
className="gap-1.5 text-sm hidden sm:flex"
>
<Github className="size-4" />
GitHub
onClick={() => setUpdateDialogOpen(true)}>
<Download className="size-4" />
New Update Available
</Button>
</a>
) : (
<a href="https://github.com/tmoroney/auto-subs" target="_blank" rel="noopener noreferrer">
<Button
variant="outline"
size="sm"
className="gap-1.5 text-sm hidden sm:flex"
>
<Github className="size-4" />
GitHub
</Button>
</a>
)}
{/* <div className="min-w-[190px]">
<Select onValueChange={(value) => setTrack(value)} >
<SelectTrigger>
Expand All @@ -134,6 +163,43 @@ function NavigationHeader() {
</Select>
</div> */}
</header>

<Dialog open={updateDialogOpen} onOpenChange={setUpdateDialogOpen}>
<DialogContent className="sm:max-w-[430px] md:max-w-[550px]">
<DialogHeader>
<DialogTitle>New Update Available</DialogTitle>
<DialogDescription>Here are the changes in the latest update</DialogDescription>
</DialogHeader>
<ScrollArea className="mt-2 max-h-[60vh] pr-4">
<div className="space-y-6">
{updateInfo.map((changeInfo, index) => (
<section key={index} className="space-y-3">
<h2 className="text-md font-medium flex items-center">
<span className="inline-flex items-center justify-center w-6 h-6 mr-2 text-sm font-bold text-white bg-primary rounded-full">
{index + 1}
</span>
{changeInfo}
</h2>
</section>
))}
</div>
</ScrollArea>
<DialogFooter className="pt-4">
<a href={platform() == "windows" ? "https://github.com/tmoroney/auto-subs/releases/latest/download/AutoSubs-Win-setup.exe" : "https://github.com/tmoroney/auto-subs/releases/latest/download/AutoSubs-Mac-ARM.pkg"} target="_blank" rel="noopener noreferrer">
<Button
variant="default"
className="gap-1.5 text-sm hidden sm:flex"
>
<Download className="size-4" />
Download Update
</Button>
</a>
<DialogClose asChild>
<Button variant="outline">Close</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}
Expand Down Expand Up @@ -446,12 +512,12 @@ function NavigationAside() {
<DialogDescription>
Report any bugs on{' '}
<a
href="https://discord.com/invite/TBFUfGWegm"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline"
href="https://discord.com/invite/TBFUfGWegm"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline"
>
Discord{' '}
Discord{' '}
</a>
or create an issue on {' '}
<a
Expand Down
26 changes: 25 additions & 1 deletion AutoSubs-App/src/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Child, Command } from '@tauri-apps/plugin-shell';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { exit } from '@tauri-apps/plugin-process';
import { platform } from '@tauri-apps/plugin-os';
import { getVersion } from '@tauri-apps/api/app';

const DEFAULT_SETTINGS = {
inputTrack: "0",
Expand Down Expand Up @@ -80,6 +81,7 @@ interface GlobalContextProps {
runSteps: (useCachedAudio: boolean) => Promise<void>;
resetSettings: () => void;
setProgress: (newProgress: number) => void;
checkForUpdates: () => Promise<string | null>;

speakers: Speaker[];
topSpeaker: TopSpeaker;
Expand Down Expand Up @@ -329,6 +331,27 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
}
}

async function checkForUpdates() {
try {
// fetch latest release from GitHub
const response = await fetch('https://api.github.com/repos/tmoroney/auto-subs/releases/latest');
const data = await response.json();

const latestVersion = data.tag_name.replace('V', '');

// compare with current version
const currentVersion = await getVersion();

if (latestVersion !== currentVersion) {
return data.body;
}
return null;
} catch (error) {
console.error("Failed to check for updates:", error);
return null;
}
}

async function runSteps(useCachedAudio: boolean) {
// To-do: Add ability to re-run specific step - not only cached audio
setIsLoading(true);
Expand Down Expand Up @@ -805,7 +828,8 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
importSubtitles,
jumpToTime,
resetSettings,
setProgress
setProgress,
checkForUpdates
}}
>
{children}
Expand Down
50 changes: 29 additions & 21 deletions AutoSubs-App/src/pages/home-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export function HomePage() {
onClick: () => {
const newStatus = !enabledSteps.textFormat;
setEnabledSteps({ ...enabledSteps, textFormat: newStatus });
toast((newStatus ? "Enabled": "Disabled") + " Text Formatting", {
toast((newStatus ? "Enabled" : "Disabled") + " Text Formatting", {
description: newStatus ? "Removed from processing steps." : "Added to processing steps.",
});
},
Expand Down Expand Up @@ -679,26 +679,34 @@ export function HomePage() {
<CommandList className="max-h-[220px]">
<CommandEmpty>No language found.</CommandEmpty>
<CommandGroup>
{languages.map((language) => (
<CommandItem
value={language.label}
key={language.value}
onSelect={() => {
setLanguage(language.value)
setOpenLanguages(false)
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
language.value === currentLanguage
? "opacity-100"
: "opacity-0"
)}
/>
{language.label}
</CommandItem>
))}
{languages
.slice() // Create a shallow copy of the languages array
.sort((a, b) => {
// Keep the first language at the top and sort the rest alphabetically
if (a === languages[0]) return -1;
if (b === languages[0]) return 1;
return a.label.localeCompare(b.label);
})
.map((language) => (
<CommandItem
value={language.label}
key={language.value}
onSelect={() => {
setLanguage(language.value);
setOpenLanguages(false);
}}
>
<Check
className={cn(
"mr-2 h-4 w-4",
language.value === currentLanguage
? "opacity-100"
: "opacity-0"
)}
/>
{language.label}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
Expand Down

0 comments on commit 09e0a1d

Please sign in to comment.