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

5 Commits

20 changed files with 87 additions and 148 deletions

View File

@@ -17,7 +17,7 @@ A Helper App for PytubePP Extension/Addon to Communicate with Pytube Post Proces
### 📎 Pre-Requirements ### 📎 Pre-Requirements
- [Python (>3.8)](https://www.python.org/downloads/) - [Python](https://www.python.org/downloads/) (>3.8)
- [FFmpeg](https://www.ffmpeg.org) - [FFmpeg](https://www.ffmpeg.org)
- [PytubePP](https://github.com/neosubhamoy/pytubepp) - [PytubePP](https://github.com/neosubhamoy/pytubepp)
* These requirements can be installed using PytubePP Helper (post installation) if [WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget) (for Windows users) / [Homebrew](https://brew.sh) (for MacOS users) is installed in your system * These requirements can be installed using PytubePP Helper (post installation) if [WinGet](https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget) (for Windows users) / [Homebrew](https://brew.sh) (for MacOS users) is installed in your system
@@ -37,13 +37,12 @@ A Helper App for PytubePP Extension/Addon to Communicate with Pytube Post Proces
2. Now open PytubePP Helper (from system tray not from start menu or shotcut) you will see (blue) 'install' buttons. First click on the install button on the right side of 'Python', a cmd window will popup to install Python. after the installation is finished then close the cmd window and now install 'FFmpeg' by clicking on the next install button. after the installation is finished close the cmd window and restart your Computer. 2. Now open PytubePP Helper (from system tray not from start menu or shotcut) you will see (blue) 'install' buttons. First click on the install button on the right side of 'Python', a cmd window will popup to install Python. after the installation is finished then close the cmd window and now install 'FFmpeg' by clicking on the next install button. after the installation is finished close the cmd window and restart your Computer.
3. Again open PytubePP Helper (from system tray not from start menu or shotcut) and install PytubePP at last. after it finishes you can close the cmd window. Now click on the 'Refresh' button and you will see the 'Ready' message. Then close PytubePP Helper 3. Again open PytubePP Helper and install PytubePP at the end. after it finishes you can close the cmd window. Now click on the 'Refresh' button and you will see the 'Ready' message. Then close PytubePP Helper
4. You can now add the [PytubePP Extension](https://github.com/neosubhamoy/pytubepp-extension) in your browser and it should work properly with [PytubePP](https://github.com/neosubhamoy/pytubepp) 4. You can now add the [PytubePP Extension](https://github.com/neosubhamoy/pytubepp-extension) in your browser and it should work properly with [PytubePP](https://github.com/neosubhamoy/pytubepp)
5. Pro Tips: 5. Pro Tips:
- Make sure PytubePP Helper is always running in the background (system tray) otherwise PytubePP Extension will not work properly. - Make sure PytubePP Helper is always running in the background (system tray) otherwise PytubePP Extension will not work properly.
- Always open PytubePP Helper from system tray if it's already running. if you open PytubePP Helper from start menu or shotcut when PytubePP Helper is already running in system tray then two instances of PytubePP Helper will run on the same time which may cause the app to malfunction!
- PytubePP Helper by default always autostarts itself when Windows starts. Make sure autostart is not disabled for PytubePP Helper in Task Manager (Startup apps tab) - PytubePP Helper by default always autostarts itself when Windows starts. Make sure autostart is not disabled for PytubePP Helper in Task Manager (Startup apps tab)
* **>> LINUX:** * **>> LINUX:**
@@ -64,7 +63,6 @@ A Helper App for PytubePP Extension/Addon to Communicate with Pytube Post Proces
3. Pro Tips: 3. Pro Tips:
- Make sure PytubePP Helper is always running in the background (Appindicator) otherwise PytubePP Extension will not work properly. - Make sure PytubePP Helper is always running in the background (Appindicator) otherwise PytubePP Extension will not work properly.
- Always open PytubePP Helper from Appindicator if it's already running. if you open PytubePP Helper from programs menu or shotcut when PytubePP Helper is already running in Appindicator then two instances of PytubePP Helper will run on the same time which may cause the app to malfunction!
- PytubePP Helper by default always autostarts itself when Linux Distro starts. Make sure autostart is not disabled for PytubePP Helper in your distro's Startup Manager / Applications - PytubePP Helper by default always autostarts itself when Linux Distro starts. Make sure autostart is not disabled for PytubePP Helper in your distro's Startup Manager / Applications
* **>> MAC OS:** * **>> MAC OS:**

View File

@@ -5,10 +5,8 @@ import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-msghost'); const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'aarch64-apple-darwin', 'release', 'pytubepp-helper-msghost');
const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost'); const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost');
const autostartSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-autostart');
const autostartDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart');
const autostartPlistSrc = path.join(__dirname, 'src-tauri', 'autostart', 'pytubepp-helper-autostart.plist'); const autostartPlistSrc = path.join(__dirname, 'src-tauri', 'autostart', 'pytubepp-helper-autostart.plist');
const autostartPlistDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.plist'); const autostartPlistDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.plist');
const msghostManifestMacChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'macos', 'chrome', 'com.neosubhamoy.pytubepp.helper.json'); const msghostManifestMacChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'macos', 'chrome', 'com.neosubhamoy.pytubepp.helper.json');
@@ -17,7 +15,7 @@ const msghostManifestMacFirefoxSrc = path.join(__dirname, 'src-tauri', 'msghost-
const msghostManifestMacFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json'); const msghostManifestMacFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json');
fs.copyFileSync(msghostSrc, msghostDest); fs.copyFileSync(msghostSrc, msghostDest);
fs.copyFileSync(autostartSrc, autostartDest); // fs.copyFileSync(autostartSrc, autostartDest);
fs.copyFileSync(autostartPlistSrc, autostartPlistDest); fs.copyFileSync(autostartPlistSrc, autostartPlistDest);
fs.copyFileSync(msghostManifestMacChromeSrc, msghostManifestMacChromeDest); fs.copyFileSync(msghostManifestMacChromeSrc, msghostManifestMacChromeDest);
fs.copyFileSync(msghostManifestMacFirefoxSrc, msghostManifestMacFirefoxDest); fs.copyFileSync(msghostManifestMacFirefoxSrc, msghostManifestMacFirefoxDest);

View File

@@ -7,15 +7,12 @@ const __dirname = path.dirname(__filename);
const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-msghost.exe'); const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-msghost.exe');
const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.exe'); const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.exe');
const autostartSrc = path.join(__dirname, 'src-tauri', 'target', 'release', 'pytubepp-helper-autostart.exe');
const autostartDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.exe');
const msghostManifestWinChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'chrome', 'com.neosubhamoy.pytubepp.helper.json'); const msghostManifestWinChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'chrome', 'com.neosubhamoy.pytubepp.helper.json');
const msghostManifestWinChromeDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.json'); const msghostManifestWinChromeDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost.json');
const msghostManifestWinFirefoxSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'firefox', 'com.neosubhamoy.pytubepp.helper.json'); const msghostManifestWinFirefoxSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'windows', 'firefox', 'com.neosubhamoy.pytubepp.helper.json');
const msghostManifestWinFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json'); const msghostManifestWinFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json');
fs.copyFileSync(msghostSrc, msghostDest); fs.copyFileSync(msghostSrc, msghostDest);
fs.copyFileSync(autostartSrc, autostartDest);
fs.copyFileSync(msghostManifestWinChromeSrc, msghostManifestWinChromeDest); fs.copyFileSync(msghostManifestWinChromeSrc, msghostManifestWinChromeDest);
fs.copyFileSync(msghostManifestWinFirefoxSrc, msghostManifestWinFirefoxDest); fs.copyFileSync(msghostManifestWinFirefoxSrc, msghostManifestWinFirefoxDest);
console.log('Files copied successfully'); console.log('Files copied successfully');

View File

@@ -7,8 +7,6 @@ const __dirname = path.dirname(__filename);
const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'x86_64-apple-darwin', 'release', 'pytubepp-helper-msghost'); const msghostSrc = path.join(__dirname, 'src-tauri', 'target', 'x86_64-apple-darwin', 'release', 'pytubepp-helper-msghost');
const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost'); const msghostDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost');
const autostartSrc = path.join(__dirname, 'src-tauri', 'target', 'x86_64-apple-darwin', 'release', 'pytubepp-helper-autostart');
const autostartDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart');
const autostartPlistSrc = path.join(__dirname, 'src-tauri', 'autostart', 'pytubepp-helper-autostart.plist'); const autostartPlistSrc = path.join(__dirname, 'src-tauri', 'autostart', 'pytubepp-helper-autostart.plist');
const autostartPlistDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.plist'); const autostartPlistDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-autostart.plist');
const msghostManifestMacChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'macos', 'chrome', 'com.neosubhamoy.pytubepp.helper.json'); const msghostManifestMacChromeSrc = path.join(__dirname, 'src-tauri', 'msghost-manifest', 'macos', 'chrome', 'com.neosubhamoy.pytubepp.helper.json');
@@ -17,7 +15,6 @@ const msghostManifestMacFirefoxSrc = path.join(__dirname, 'src-tauri', 'msghost-
const msghostManifestMacFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json'); const msghostManifestMacFirefoxDest = path.join(__dirname, 'src-tauri', 'pytubepp-helper-msghost-moz.json');
fs.copyFileSync(msghostSrc, msghostDest); fs.copyFileSync(msghostSrc, msghostDest);
fs.copyFileSync(autostartSrc, autostartDest);
fs.copyFileSync(autostartPlistSrc, autostartPlistDest); fs.copyFileSync(autostartPlistSrc, autostartPlistDest);
fs.copyFileSync(msghostManifestMacChromeSrc, msghostManifestMacChromeDest); fs.copyFileSync(msghostManifestMacChromeSrc, msghostManifestMacChromeDest);
fs.copyFileSync(msghostManifestMacFirefoxSrc, msghostManifestMacFirefoxDest); fs.copyFileSync(msghostManifestMacFirefoxSrc, msghostManifestMacFirefoxDest);

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "pytubepp-helper", "name": "pytubepp-helper",
"version": "0.4.0", "version": "0.5.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pytubepp-helper", "name": "pytubepp-helper",
"version": "0.4.0", "version": "0.5.0",
"dependencies": { "dependencies": {
"@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-slot": "^1.1.0",

View File

@@ -1,7 +1,7 @@
{ {
"name": "pytubepp-helper", "name": "pytubepp-helper",
"private": true, "private": true,
"version": "0.4.0", "version": "0.5.0",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

10
src-tauri/Cargo.lock generated
View File

@@ -2473,7 +2473,7 @@ dependencies = [
[[package]] [[package]]
name = "pytubepp-helper" name = "pytubepp-helper"
version = "0.4.0" version = "0.5.0"
dependencies = [ dependencies = [
"fix-path-env", "fix-path-env",
"futures-util", "futures-util",
@@ -2485,14 +2485,6 @@ dependencies = [
"tokio-tungstenite", "tokio-tungstenite",
] ]
[[package]]
name = "pytubepp-helper-autostart"
version = "0.1.0"
dependencies = [
"serde_json",
"websocket",
]
[[package]] [[package]]
name = "pytubepp-helper-msghost" name = "pytubepp-helper-msghost"
version = "0.1.0" version = "0.1.0"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "pytubepp-helper" name = "pytubepp-helper"
version = "0.4.0" version = "0.5.0"
description = "PytubePP Helper" description = "PytubePP Helper"
authors = ["neosubhamoy"] authors = ["neosubhamoy"]
edition = "2021" edition = "2021"
@@ -26,6 +26,5 @@ custom-protocol = ["tauri/custom-protocol"]
[workspace] [workspace]
members = [ members = [
".", ".",
"msghost", "msghost"
"autostart"
] ]

View File

@@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "pytubepp-helper-autostart"
version = "0.1.0"

View File

@@ -1,12 +0,0 @@
[package]
name = "pytubepp-helper-autostart"
version = "0.1.0"
description = "PytubePP Helper (Autostart)"
authors = ["neosubhamoy <hey@neosubhamoy.com>"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
websocket = "0.27.1"
serde_json = "1.0"

View File

@@ -2,7 +2,7 @@
Type=Application Type=Application
Name=pytubepp-helper Name=pytubepp-helper
Icon=pytubepp-helper Icon=pytubepp-helper
Comment=pytubepp-helper autostart script Comment=pytubepp-helper autostart
Exec=/usr/bin/pytubepp-helper-autostart Exec=/usr/bin/pytubepp-helper --hidden
StartupNotify=false StartupNotify=false
Terminal=false Terminal=false

View File

@@ -4,8 +4,11 @@
<dict> <dict>
<key>Label</key> <key>Label</key>
<string>com.neosubhamoy.pytubepp.helper</string> <string>com.neosubhamoy.pytubepp.helper</string>
<key>Program</key> <key>ProgramArguments</key>
<string>/Applications/pytubepp-helper.app/Contents/MacOS/pytubepp-helper</string> <array>
<string>/Applications/pytubepp-helper.app/Contents/MacOS/pytubepp-helper</string>
<string>--hidden</string>
</array>
<key>RunAtLoad</key> <key>RunAtLoad</key>
<true/> <true/>
</dict> </dict>

View File

@@ -1,70 +0,0 @@
#![windows_subsystem = "windows"]
use std::process::Command;
use websocket::client::ClientBuilder;
use websocket::OwnedMessage;
use std::thread::sleep;
use std::time::Duration;
fn connect_with_retry(url: &str, max_attempts: u32) -> Result<websocket::sync::Client<std::net::TcpStream>, Box<dyn std::error::Error>> {
let mut attempts = 0;
loop {
match ClientBuilder::new(url).unwrap().connect_insecure() {
Ok(client) => {
eprintln!("Successfully connected to Tauri app :)");
return Ok(client);
}
Err(e) => {
attempts += 1;
if attempts >= max_attempts {
return Err(Box::new(e));
}
let wait_time = Duration::from_secs(2u64.pow(attempts));
eprintln!("Connection attempt {} failed. Retrying in {:?}...", attempts, wait_time);
sleep(wait_time);
}
}
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(target_os = "windows")]
{
let _ = Command::new("pytubepp-helper.exe").spawn();
}
#[cfg(target_os = "linux")]
{
let _ = Command::new("pytubepp-helper").spawn();
}
#[cfg(target_os = "macos")]
{
let _ = Command::new("/Applications/pytubepp-helper.app/Contents/MacOS/pytubepp-helper").spawn();
}
// Launch the main application
// let _ = Command::new("pytubepp-helper")
// .spawn();
// Connect with the Tauri app
let websocket_url = "ws://localhost:3030";
eprintln!("Attempting to connect to {}", websocket_url);
let mut client = match connect_with_retry(websocket_url, 2) {
Ok(client) => client,
Err(e) => {
eprintln!("Failed to connect after multiple attempts: {:?}", e);
return Err(e);
}
};
// Send message to Tauri app
client.send_message(&OwnedMessage::Text(serde_json::json!({
"url": "",
"command": "autostart",
"argument": ""
}).to_string()))?;
Ok(())
}

View File

@@ -18,8 +18,8 @@ ${StrLoc}
!define MANUFACTURER "neosubhamoy" !define MANUFACTURER "neosubhamoy"
!define PRODUCTNAME "pytubepp-helper" !define PRODUCTNAME "pytubepp-helper"
!define VERSION "0.4.0" !define VERSION "0.5.0"
!define VERSIONWITHBUILD "0.4.0.0" !define VERSIONWITHBUILD "0.5.0.0"
!define SHORTDESCRIPTION "PytubePP Helper" !define SHORTDESCRIPTION "PytubePP Helper"
!define INSTALLMODE "currentUser" !define INSTALLMODE "currentUser"
!define LICENSE "..\..\..\..\..\LICENSE" !define LICENSE "..\..\..\..\..\LICENSE"
@@ -43,7 +43,7 @@ ${StrLoc}
!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}" !define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
!define UNINSTALLERSIGNCOMMAND "" !define UNINSTALLERSIGNCOMMAND ""
!define ESTIMATEDSIZE "0x002311" !define ESTIMATEDSIZE "0x002311"
!define AUTOSTART_EXEC "pytubepp-helper-autostart.exe" !define AUTOSTART_EXEC "pytubepp-helper.exe"
!define CHROME_REG_PATH "Software\Google\Chrome\NativeMessagingHosts\com.neosubhamoy.pytubepp.helper" !define CHROME_REG_PATH "Software\Google\Chrome\NativeMessagingHosts\com.neosubhamoy.pytubepp.helper"
!define FIREFOX_REG_PATH "Software\Mozilla\NativeMessagingHosts\com.neosubhamoy.pytubepp.helper" !define FIREFOX_REG_PATH "Software\Mozilla\NativeMessagingHosts\com.neosubhamoy.pytubepp.helper"
!define RUN_REG_PATH "Software\Microsoft\Windows\CurrentVersion\Run" !define RUN_REG_PATH "Software\Microsoft\Windows\CurrentVersion\Run"
@@ -548,7 +548,7 @@ Section Install
; Copy resources ; Copy resources
CreateDirectory "$INSTDIR\" CreateDirectory "$INSTDIR\"
File /a "/oname=pytubepp-helper-autostart.exe" "..\..\..\..\pytubepp-helper-autostart.exe" ; File /a "/oname=pytubepp-helper-autostart.exe" "..\..\..\..\pytubepp-helper-autostart.exe"
File /a "/oname=pytubepp-helper-msghost-moz.json" "..\..\..\..\pytubepp-helper-msghost-moz.json" File /a "/oname=pytubepp-helper-msghost-moz.json" "..\..\..\..\pytubepp-helper-msghost-moz.json"
File /a "/oname=pytubepp-helper-msghost.exe" "..\..\..\..\pytubepp-helper-msghost.exe" File /a "/oname=pytubepp-helper-msghost.exe" "..\..\..\..\pytubepp-helper-msghost.exe"
File /a "/oname=pytubepp-helper-msghost.json" "..\..\..\..\pytubepp-helper-msghost.json" File /a "/oname=pytubepp-helper-msghost.json" "..\..\..\..\pytubepp-helper-msghost.json"
@@ -585,7 +585,7 @@ Section Install
WriteRegStr HKCU "${FIREFOX_REG_PATH}" "" "$INSTDIR\pytubepp-helper-msghost-moz.json" WriteRegStr HKCU "${FIREFOX_REG_PATH}" "" "$INSTDIR\pytubepp-helper-msghost-moz.json"
; Add entry for automatic startup with Windows ; Add entry for automatic startup with Windows
WriteRegStr HKCU "${RUN_REG_PATH}" "${PRODUCTNAME}" "$\"$INSTDIR\${AUTOSTART_EXEC}$\"" WriteRegStr HKCU "${RUN_REG_PATH}" "${PRODUCTNAME}" "$\"$INSTDIR\${AUTOSTART_EXEC}$\" --hidden"
; Create start menu shortcut (GUI) ; Create start menu shortcut (GUI)
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
@@ -670,7 +670,7 @@ Section Uninstall
Delete "$INSTDIR\${MAINBINARYNAME}.exe" Delete "$INSTDIR\${MAINBINARYNAME}.exe"
; Delete resources ; Delete resources
Delete "$INSTDIR\pytubepp-helper-autostart.exe" ; Delete "$INSTDIR\pytubepp-helper-autostart.exe"
Delete "$INSTDIR\pytubepp-helper-msghost-moz.json" Delete "$INSTDIR\pytubepp-helper-msghost-moz.json"
Delete "$INSTDIR\pytubepp-helper-msghost.exe" Delete "$INSTDIR\pytubepp-helper-msghost.exe"
Delete "$INSTDIR\pytubepp-helper-msghost.json" Delete "$INSTDIR\pytubepp-helper-msghost.json"

View File

@@ -10,7 +10,7 @@
<RegistryValue Type="string" Value="[INSTALLDIR]pytubepp-helper-msghost-moz.json" KeyPath="no" /> <RegistryValue Type="string" Value="[INSTALLDIR]pytubepp-helper-msghost-moz.json" KeyPath="no" />
</RegistryKey> </RegistryKey>
<RegistryKey Root="HKCU" Key="Software\Microsoft\Windows\CurrentVersion\Run"> <RegistryKey Root="HKCU" Key="Software\Microsoft\Windows\CurrentVersion\Run">
<RegistryValue Name="pytubepp-helper" Type="string" Value="[INSTALLDIR]pytubepp-helper-autostart.exe" KeyPath="no" /> <RegistryValue Name="pytubepp-helper" Type="string" Value="&quot;[INSTALLDIR]pytubepp-helper.exe&quot; --hidden" KeyPath="no" />
</RegistryKey> </RegistryKey>
</Component> </Component>
</DirectoryRef> </DirectoryRef>

View File

@@ -1,11 +1,11 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!! // Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::{process::Command, sync::Arc, env}; use std::{process::Command, sync::Arc, env, time::Duration};
use serde_json::Value; use serde_json::Value;
use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu}; use tauri::{CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu};
use tokio::{net::{TcpListener, TcpStream}, sync::{Mutex, oneshot}}; use tokio::{net::{TcpListener, TcpStream}, sync::{Mutex, oneshot}, time::sleep};
use tokio_tungstenite::accept_async; use tokio_tungstenite::{accept_async, connect_async};
use futures_util::{SinkExt, StreamExt}; use futures_util::{SinkExt, StreamExt};
struct ResponseChannel { struct ResponseChannel {
@@ -17,6 +17,20 @@ struct WebSocketState {
response_channel: ResponseChannel, response_channel: ResponseChannel,
} }
async fn is_another_instance_running() -> bool {
match connect_async("ws://127.0.0.1:3030").await {
Ok(_) => true,
Err(_) => false
}
}
async fn try_bind_ws_port() -> Option<TcpListener> {
match TcpListener::bind("127.0.0.1:3030").await {
Ok(listener) => Some(listener),
Err(_) => None
}
}
#[tauri::command] #[tauri::command]
async fn send_to_extension( async fn send_to_extension(
message: String, message: String,
@@ -170,10 +184,40 @@ fn download_stream(url: String, stream: String) {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let _ = fix_path_env::fix(); let _ = fix_path_env::fix();
// Check if another instance is running
if is_another_instance_running().await {
println!("Another instance is already running. Exiting...");
std::process::exit(0);
}
// Try to bind to the WebSocket port with a few retries
let mut listener = None;
for _ in 0..3 {
if let Some(l) = try_bind_ws_port().await {
listener = Some(l);
break;
}
sleep(Duration::from_millis(100)).await;
}
// If we couldn't bind to the port after retries, assume another instance is running
let listener = match listener {
Some(l) => l,
None => {
println!("Could not bind to WebSocket port. Another instance might be running. Exiting...");
std::process::exit(0);
}
};
let args: Vec<String> = env::args().collect();
let start_hidden = args.contains(&"--hidden".to_string());
let websocket_state = Arc::new(Mutex::new(WebSocketState { let websocket_state = Arc::new(Mutex::new(WebSocketState {
sender: None, sender: None,
response_channel: ResponseChannel { sender: None }, response_channel: ResponseChannel { sender: None },
})); }));
let tray_menu = SystemTrayMenu::new() let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new("show".to_string(), "Show")) .add_item(CustomMenuItem::new("show".to_string(), "Show"))
.add_item(CustomMenuItem::new("quit".to_string(), "Quit")); .add_item(CustomMenuItem::new("quit".to_string(), "Quit"));
@@ -207,10 +251,16 @@ async fn main() {
}) })
.manage(websocket_state.clone()) .manage(websocket_state.clone())
.setup(move |app| { .setup(move |app| {
let window = app.get_window("main").unwrap();
if start_hidden {
window.hide().unwrap();
}
let app_handle = app.handle(); let app_handle = app.handle();
let ws_state = websocket_state.clone(); let ws_state = websocket_state.clone();
tokio::spawn(async move { tokio::spawn(async move {
let listener = TcpListener::bind("127.0.0.1:3030").await.unwrap();
println!("WebSocket server listening on ws://127.0.0.1:3030"); println!("WebSocket server listening on ws://127.0.0.1:3030");
while let Ok((stream, _)) = listener.accept().await { while let Ok((stream, _)) = listener.accept().await {
let app_handle = app_handle.clone(); let app_handle = app_handle.clone();

View File

@@ -7,7 +7,7 @@
}, },
"package": { "package": {
"productName": "pytubepp-helper", "productName": "pytubepp-helper",
"version": "0.4.0" "version": "0.5.0"
}, },
"tauri": { "tauri": {
"allowlist": { "allowlist": {

View File

@@ -1,7 +1,7 @@
{ {
"build": { "build": {
"beforeDevCommand": "npm run dev && cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --manifest-path=./src-tauri/autostart/Cargo.toml", "beforeDevCommand": "npm run dev && cargo build --manifest-path=./src-tauri/msghost/Cargo.toml",
"beforeBuildCommand": "npm run build && cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --release --manifest-path=./src-tauri/autostart/Cargo.toml", "beforeBuildCommand": "npm run build && cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml",
"devPath": "http://localhost:1422", "devPath": "http://localhost:1422",
"distDir": "../dist" "distDir": "../dist"
}, },
@@ -134,7 +134,6 @@
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json", "/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
"/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json", "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json",
"/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost", "/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost",
"/usr/bin/pytubepp-helper-autostart": "./target/release/pytubepp-helper-autostart",
"/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop" "/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop"
} }
}, },
@@ -148,7 +147,6 @@
"/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json", "/etc/chromium/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/chrome/com.neosubhamoy.pytubepp.helper.json",
"/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json", "/usr/lib/mozilla/native-messaging-hosts/com.neosubhamoy.pytubepp.helper.json": "./msghost-manifest/linux/firefox/com.neosubhamoy.pytubepp.helper.json",
"/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost", "/usr/bin/pytubepp-helper-msghost": "./target/release/pytubepp-helper-msghost",
"/usr/bin/pytubepp-helper-autostart": "./target/release/pytubepp-helper-autostart",
"/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop" "/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop"
} }
} }

View File

@@ -1,7 +1,7 @@
{ {
"build": { "build": {
"beforeDevCommand": "[[ -n \"$TARGET_ARCH\" ]] && ARCH=\"$TARGET_ARCH\" || ARCH=\"$(uname -m | sed 's/^arm64$/aarch64/')-apple-darwin\" && [[ \"$ARCH\" == \"aarch64-apple-darwin\" ]] && cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --manifest-path=./src-tauri/autostart/Cargo.toml || cargo build --target=$ARCH --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --target=$ARCH --manifest-path=./src-tauri/autostart/Cargo.toml && npm run dev", "beforeDevCommand": "[[ -n \"$TARGET_ARCH\" ]] && ARCH=\"$TARGET_ARCH\" || ARCH=\"$(uname -m | sed 's/^arm64$/aarch64/')-apple-darwin\" && cargo build --target=$ARCH --manifest-path=./src-tauri/msghost/Cargo.toml && npm run dev",
"beforeBuildCommand": "[[ -n \"$TARGET_ARCH\" ]] && ARCH=\"$TARGET_ARCH\" || ARCH=\"$(uname -m | sed 's/^arm64$/aarch64/')-apple-darwin\" && [[ \"$ARCH\" == \"aarch64-apple-darwin\" ]] && cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --release --manifest-path=./src-tauri/autostart/Cargo.toml && node copyFiles.${ARCH}.js && npm run build || cargo build --release --target=$ARCH --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --release --target=$ARCH --manifest-path=./src-tauri/autostart/Cargo.toml && node copyFiles.${ARCH}.js && npm run build", "beforeBuildCommand": "[[ -n \"$TARGET_ARCH\" ]] && ARCH=\"$TARGET_ARCH\" || ARCH=\"$(uname -m | sed 's/^arm64$/aarch64/')-apple-darwin\" && cargo build --release --target=$ARCH --manifest-path=./src-tauri/msghost/Cargo.toml && node copyFiles.${ARCH}.js && npm run build",
"devPath": "http://localhost:1422", "devPath": "http://localhost:1422",
"distDir": "../dist" "distDir": "../dist"
}, },
@@ -102,7 +102,6 @@
"$RESOURCE/pytubepp-helper-msghost.json", "$RESOURCE/pytubepp-helper-msghost.json",
"$RESOURCE/pytubepp-helper-msghost-moz.json", "$RESOURCE/pytubepp-helper-msghost-moz.json",
"$RESOURCE/pytubepp-helper-msghost", "$RESOURCE/pytubepp-helper-msghost",
"$RESOURCE/pytubepp-helper-autostart",
"$RESOURCE/pytubepp-helper-autostart.plist" "$RESOURCE/pytubepp-helper-autostart.plist"
] ]
}, },
@@ -156,7 +155,6 @@
"pytubepp-helper-msghost.json", "pytubepp-helper-msghost.json",
"pytubepp-helper-msghost-moz.json", "pytubepp-helper-msghost-moz.json",
"pytubepp-helper-msghost", "pytubepp-helper-msghost",
"pytubepp-helper-autostart",
"pytubepp-helper-autostart.plist" "pytubepp-helper-autostart.plist"
] ]
}, },

View File

@@ -1,7 +1,7 @@
{ {
"build": { "build": {
"beforeDevCommand": "cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --manifest-path=./src-tauri/autostart/Cargo.toml && npm run dev", "beforeDevCommand": "cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && npm run dev",
"beforeBuildCommand": "cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --release --manifest-path=./src-tauri/autostart/Cargo.toml && node copyFiles.js && npm run build", "beforeBuildCommand": "cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml && node copyFiles.js && npm run build",
"devPath": "http://localhost:1422", "devPath": "http://localhost:1422",
"distDir": "../dist" "distDir": "../dist"
}, },
@@ -93,8 +93,7 @@
"scope": [ "scope": [
"$RESOURCE/pytubepp-helper-msghost.json", "$RESOURCE/pytubepp-helper-msghost.json",
"$RESOURCE/pytubepp-helper-msghost-moz.json", "$RESOURCE/pytubepp-helper-msghost-moz.json",
"$RESOURCE/pytubepp-helper-msghost.exe", "$RESOURCE/pytubepp-helper-msghost.exe"
"$RESOURCE/pytubepp-helper-autostart.exe"
] ]
}, },
"window": { "window": {
@@ -148,8 +147,7 @@
"resources": [ "resources": [
"pytubepp-helper-msghost.json", "pytubepp-helper-msghost.json",
"pytubepp-helper-msghost-moz.json", "pytubepp-helper-msghost-moz.json",
"pytubepp-helper-msghost.exe", "pytubepp-helper-msghost.exe"
"pytubepp-helper-autostart.exe"
] ]
}, },
"systemTray": { "systemTray": {