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

(refactor): switched to cli --hidden autostart method from WebSockets and fixed macOS autostart not auto hiding after restart issue

This commit is contained in:
2024-12-29 19:29:37 +05:30
Verified
parent 5eef3d01f7
commit e1be9e86a0
16 changed files with 33 additions and 131 deletions

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
Name=pytubepp-helper
Icon=pytubepp-helper
Comment=pytubepp-helper autostart script
Exec=/usr/bin/pytubepp-helper-autostart
Comment=pytubepp-helper autostart
Exec=/usr/bin/pytubepp-helper --hidden
StartupNotify=false
Terminal=false

View File

@@ -4,8 +4,11 @@
<dict>
<key>Label</key>
<string>com.neosubhamoy.pytubepp.helper</string>
<key>Program</key>
<string>/Applications/pytubepp-helper.app/Contents/MacOS/pytubepp-helper</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/pytubepp-helper.app/Contents/MacOS/pytubepp-helper</string>
<string>--hidden</string>
</array>
<key>RunAtLoad</key>
<true/>
</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(())
}