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:
8
src-tauri/Cargo.lock
generated
8
src-tauri/Cargo.lock
generated
@@ -2485,14 +2485,6 @@ dependencies = [
|
||||
"tokio-tungstenite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytubepp-helper-autostart"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
"websocket",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytubepp-helper-msghost"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -26,6 +26,5 @@ custom-protocol = ["tauri/custom-protocol"]
|
||||
[workspace]
|
||||
members = [
|
||||
".",
|
||||
"msghost",
|
||||
"autostart"
|
||||
"msghost"
|
||||
]
|
||||
|
||||
7
src-tauri/autostart/Cargo.lock
generated
7
src-tauri/autostart/Cargo.lock
generated
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
@@ -43,7 +43,7 @@ ${StrLoc}
|
||||
!define MANUPRODUCTKEY "Software\${MANUFACTURER}\${PRODUCTNAME}"
|
||||
!define UNINSTALLERSIGNCOMMAND ""
|
||||
!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 FIREFOX_REG_PATH "Software\Mozilla\NativeMessagingHosts\com.neosubhamoy.pytubepp.helper"
|
||||
!define RUN_REG_PATH "Software\Microsoft\Windows\CurrentVersion\Run"
|
||||
@@ -548,7 +548,7 @@ Section Install
|
||||
|
||||
; Copy resources
|
||||
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.exe" "..\..\..\..\pytubepp-helper-msghost.exe"
|
||||
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"
|
||||
|
||||
; 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)
|
||||
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
|
||||
@@ -670,7 +670,7 @@ Section Uninstall
|
||||
Delete "$INSTDIR\${MAINBINARYNAME}.exe"
|
||||
|
||||
; 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.exe"
|
||||
Delete "$INSTDIR\pytubepp-helper-msghost.json"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<RegistryValue Type="string" Value="[INSTALLDIR]pytubepp-helper-msghost-moz.json" KeyPath="no" />
|
||||
</RegistryKey>
|
||||
<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=""[INSTALLDIR]pytubepp-helper.exe" --hidden" KeyPath="no" />
|
||||
</RegistryKey>
|
||||
</Component>
|
||||
</DirectoryRef>
|
||||
|
||||
@@ -170,10 +170,15 @@ fn download_stream(url: String, stream: String) {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let _ = fix_path_env::fix();
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let start_hidden = args.contains(&"--hidden".to_string());
|
||||
|
||||
let websocket_state = Arc::new(Mutex::new(WebSocketState {
|
||||
sender: None,
|
||||
response_channel: ResponseChannel { sender: None },
|
||||
}));
|
||||
|
||||
let tray_menu = SystemTrayMenu::new()
|
||||
.add_item(CustomMenuItem::new("show".to_string(), "Show"))
|
||||
.add_item(CustomMenuItem::new("quit".to_string(), "Quit"));
|
||||
@@ -207,6 +212,12 @@ async fn main() {
|
||||
})
|
||||
.manage(websocket_state.clone())
|
||||
.setup(move |app| {
|
||||
let window = app.get_window("main").unwrap();
|
||||
|
||||
if start_hidden {
|
||||
window.hide().unwrap();
|
||||
}
|
||||
|
||||
let app_handle = app.handle();
|
||||
let ws_state = websocket_state.clone();
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev && cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --manifest-path=./src-tauri/autostart/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",
|
||||
"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",
|
||||
"devPath": "http://localhost:1422",
|
||||
"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",
|
||||
"/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-autostart": "./target/release/pytubepp-helper-autostart",
|
||||
"/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",
|
||||
"/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-autostart": "./target/release/pytubepp-helper-autostart",
|
||||
"/etc/xdg/autostart/pytubepp-helper-autostart.desktop": "./autostart/pytubepp-helper-autostart.desktop"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"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 && cargo build --target=$ARCH --manifest-path=./src-tauri/autostart/Cargo.toml && npm run dev",
|
||||
"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 && cargo build --release --target=$ARCH --manifest-path=./src-tauri/autostart/Cargo.toml && node copyFiles.${ARCH}.js && npm run build",
|
||||
"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\" && cargo build --release --target=$ARCH --manifest-path=./src-tauri/msghost/Cargo.toml && node copyFiles.${ARCH}.js && npm run build",
|
||||
"devPath": "http://localhost:1422",
|
||||
"distDir": "../dist"
|
||||
},
|
||||
@@ -102,7 +102,6 @@
|
||||
"$RESOURCE/pytubepp-helper-msghost.json",
|
||||
"$RESOURCE/pytubepp-helper-msghost-moz.json",
|
||||
"$RESOURCE/pytubepp-helper-msghost",
|
||||
"$RESOURCE/pytubepp-helper-autostart",
|
||||
"$RESOURCE/pytubepp-helper-autostart.plist"
|
||||
]
|
||||
},
|
||||
@@ -156,7 +155,6 @@
|
||||
"pytubepp-helper-msghost.json",
|
||||
"pytubepp-helper-msghost-moz.json",
|
||||
"pytubepp-helper-msghost",
|
||||
"pytubepp-helper-autostart",
|
||||
"pytubepp-helper-autostart.plist"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"beforeDevCommand": "cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && cargo build --manifest-path=./src-tauri/autostart/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",
|
||||
"beforeDevCommand": "cargo build --manifest-path=./src-tauri/msghost/Cargo.toml && npm run dev",
|
||||
"beforeBuildCommand": "cargo build --release --manifest-path=./src-tauri/msghost/Cargo.toml && node copyFiles.js && npm run build",
|
||||
"devPath": "http://localhost:1422",
|
||||
"distDir": "../dist"
|
||||
},
|
||||
@@ -93,8 +93,7 @@
|
||||
"scope": [
|
||||
"$RESOURCE/pytubepp-helper-msghost.json",
|
||||
"$RESOURCE/pytubepp-helper-msghost-moz.json",
|
||||
"$RESOURCE/pytubepp-helper-msghost.exe",
|
||||
"$RESOURCE/pytubepp-helper-autostart.exe"
|
||||
"$RESOURCE/pytubepp-helper-msghost.exe"
|
||||
]
|
||||
},
|
||||
"window": {
|
||||
@@ -148,8 +147,7 @@
|
||||
"resources": [
|
||||
"pytubepp-helper-msghost.json",
|
||||
"pytubepp-helper-msghost-moz.json",
|
||||
"pytubepp-helper-msghost.exe",
|
||||
"pytubepp-helper-autostart.exe"
|
||||
"pytubepp-helper-msghost.exe"
|
||||
]
|
||||
},
|
||||
"systemTray": {
|
||||
|
||||
Reference in New Issue
Block a user