Skip to content

Commit

Permalink
a new update, user wide installs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Nov 29, 2024
1 parent 685c96e commit bf4f26f
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src-ahqstore-types/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-ahqstore-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ahqstore-types"
description = "Standard types used by AHQ Store"
version = "3.10.2"
version = "3.10.3"
edition = "2021"
license-file = "../LICENSE.md"
repository = "https://github.com/ahqsoftwares/tauri-ahq-store"
Expand Down
2 changes: 2 additions & 0 deletions src-ahqstore-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
Types used by AHQ Store app

**NOTE:** This crate is used internally by AHQ Store Organisation projects for sharing the unified app schema and protocol signatures

THIS CRATE DOES NOT FOLLOW SEMANTIC VERSIONING
2 changes: 1 addition & 1 deletion src-ahqstore-types/src/app/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct InstallerOptions {

#[allow(non_snake_case)]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "js", wasm_bindgen(getter_with_clone))]
#[cfg_attr(feature = "js", wasm_bindgen)]
pub enum WindowsInstallScope {
User,
Machine
Expand Down
9 changes: 1 addition & 8 deletions src-ahqstore-types/src/app/other_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@ pub enum InstallerFormat {
#[doc = "🎯 Stable as of v2\n\n"]
WindowsInstallerMsi,

#[doc = "🔬 Planned as of v2.5 or v3\n\n"]
/// **Doesn't work**
/// **⚠️ AHQ Store will act just like downloading from the web and running it ONCE[^1]**
///
/// [^1]: You'll need to provide app's final location
#[doc = "🎯 Stable after v2\n\n"]
WindowsInstallerExe,

#[doc = "🔬 Planned as of v3\n\n"]
/// **Doesn't work**
/// **Won't be worked on, until other formats are supported**
/// **⚠️ AHQ Store will act just like downloading from the web and running it ONCE[^1]**
///
/// [^1]: You'll need to provide app's final location
WindowsUWPMsix,

#[doc = "🎯 Stable as of v2\n\n"]
Expand Down
3 changes: 2 additions & 1 deletion src-ahqstore-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(dead_code, unused_imports, reason = "Conditional compilation")]
#![allow(dead_code, unused_imports, non_local_definitions, reason = "Conditional compilation")]

use serde::{Deserialize, Serialize};
use serde_json::{from_str, to_string, to_string_pretty};
Expand Down Expand Up @@ -157,6 +157,7 @@ pub struct Library {
pub progress: f64,
pub max: u64,
pub app: Option<AHQStoreApplication>,
pub user: String
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src-service/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src-service/src/handlers/daemon/dwn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub async fn handle(resp: &mut Library, state: &mut DaemonState, imp: &mut bool)
println!("100 %");
let _ = x.file.flush();
let _ = x.file.sync_all();
//let app = x.app.clone();

//Drop the File
let mut data = replace(&mut state.data, None);
Expand All @@ -38,7 +37,7 @@ pub async fn handle(resp: &mut Library, state: &mut DaemonState, imp: &mut bool)
resp.status = AppStatus::AVScanning;

let inst = get_installer_file(&x.app);
state.data = Some(DaemonData::AVScan((x.app, av::scan::scan_threaded(&inst))));
state.data = Some(DaemonData::AVScan(x.app, av::scan::scan_threaded(&inst)));
state.step = Step::AVScanning;
*imp = true;
}
Expand All @@ -50,13 +49,13 @@ pub async fn handle(resp: &mut Library, state: &mut DaemonState, imp: &mut bool)
pub async fn av_scan(resp: &mut Library, state: &mut DaemonState, imp: &mut bool) {
let data = state.data.as_mut().unwrap();

if let DaemonData::AVScan((app, x)) = data {
if let DaemonData::AVScan(app, x) = data {
if x.is_finished() {
*imp = true;
let mut data = replace(&mut state.data, None);
let data = data.expect("Impossible to be null");

let DaemonData::AVScan((app, x)) = data else {
let DaemonData::AVScan(app, x) = data else {
panic!("Impossible panic");
};

Expand All @@ -65,7 +64,7 @@ pub async fn av_scan(resp: &mut Library, state: &mut DaemonState, imp: &mut bool
if !av_flagged.unwrap_or(true) {
resp.status = AppStatus::Installing;

if let Some(x) = install_app(&app, resp.is_update).await {
if let Some(x) = install_app(&app, resp.is_update, &resp.user).await {
state.step = Step::Installing;
state.data = Some(DaemonData::Inst(x));
} else {
Expand Down
42 changes: 37 additions & 5 deletions src-service/src/handlers/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
default,
fs::File,
future::{Future, IntoFuture},
mem::replace,
process::Child,
sync::mpsc::{channel, Receiver, Sender},
thread::JoinHandle,
Expand All @@ -21,7 +22,7 @@ use tokio::{
time::{sleep, Sleep},
};

use crate::utils::{get_iprocess, ws_send};
use crate::utils::{get_iprocess, structs::get_current_user, ws_send};

#[cfg(windows)]
use crate::handlers::pipe;
Expand All @@ -33,6 +34,9 @@ use super::{
uninstall_app, InstallResult,
};

#[cfg(windows)]
use super::list_user_apps;

pub static mut UPDATE_STATUS_REPORT: Option<UpdateStatusReport> = None;
pub static mut LIBRARY: Option<Vec<Library>> = None;

Expand Down Expand Up @@ -92,7 +96,7 @@ pub enum Step {

pub enum DaemonData {
Dwn(DownloadData),
AVScan((AHQStoreApplication, JoinHandle<Option<Malicious>>)),
AVScan(AHQStoreApplication, JoinHandle<Option<Malicious>>),
Inst(InstallResult),
Unst(JoinHandle<bool>),
None,
Expand Down Expand Up @@ -297,7 +301,7 @@ pub async fn check_update() -> Option<bool> {
.await;
}

if let Some(x) = list_apps() {
let mut manage = async |x: Vec<(String, String)>, user: String| {
for (id, ver) in x {
if &ver == "custom" {
continue;
Expand All @@ -306,14 +310,40 @@ pub async fn check_update() -> Option<bool> {
let app = get_app(0, id).await;
match app {
Response::AppData(_, id, app) => {
use ahqstore_types::{InstallerFormat, WindowsInstallScope};

// Skip if the user is not the currently logged in user
// Because WindowsInstallerExe cannot install if the user is not logged in
if let (Some(x), Some(y)) = (app.get_win_download(), app.get_win_options()) {
let scope = y.scope.as_ref().unwrap_or(&WindowsInstallScope::Machine);

if matches!(&x.installerType, &InstallerFormat::WindowsInstallerExe)
&& matches!(scope, &WindowsInstallScope::User)
{
if get_current_user().unwrap_or("") != &user {
continue;
}
}
}
if &ver == &app.version {
continue;
}
to_update.push((id, app));
to_update.push((id, app, user.clone()));
}
_ => {}
}
}
};

if let Some(x) = list_apps() {
manage(x, "machine".into()).await;
}

#[cfg(windows)]
if let Some(x) = list_user_apps(None) {
for (user, apps) in x {
manage(apps, user).await;
}
}

let library = unsafe { LIBRARY.as_mut().unwrap() };
Expand All @@ -331,7 +361,7 @@ pub async fn check_update() -> Option<bool> {
return Some(false);
}

to_update.into_iter().for_each(|(id, app)| {
to_update.into_iter().for_each(|(id, app, user)| {
library.push(Library {
app_id: id.clone(),
is_update: true,
Expand All @@ -340,6 +370,7 @@ pub async fn check_update() -> Option<bool> {
to: ToDo::Uninstall,
max: 0,
app: Some(app.clone()),
user: user.clone(),
});
library.push(Library {
app_id: id,
Expand All @@ -349,6 +380,7 @@ pub async fn check_update() -> Option<bool> {
to: ToDo::Install,
app: Some(app),
max: 0,
user,
});
});

Expand Down
10 changes: 9 additions & 1 deletion src-service/src/handlers/daemon/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::mpsc::Receiver;

use crate::{
handlers::{get_app, get_app_local},
utils::{ws_send, ServiceIpc},
utils::{structs::get_current_user, ws_send, ServiceIpc},
};

use super::{lib_msg, BETWEEN};
Expand All @@ -26,6 +26,10 @@ pub async fn recv(
progress: 0.0,
max: 0,
app: None,
// It is important to clone here so that it can be processed correctly even if the user changes
user: get_current_user()
.expect("Impossible to be null")
.to_string(),
});
}
Command::UninstallApp(ref_id, app_id) => {
Expand All @@ -38,6 +42,10 @@ pub async fn recv(
max: 0,
status: AppStatus::Pending,
to: ToDo::Uninstall,
// It is important to clone here so that it can be processed correctly even if the user changes
user: get_current_user()
.expect("Impossible to be null")
.to_string(),
});
}
}
Expand Down
12 changes: 10 additions & 2 deletions src-service/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::{io::AsyncWriteExt, spawn};
use crate::{
utils::{
get_iprocess, get_perms,
structs::{Command, ErrorType, Reason, Response},
structs::{get_current_user, Command, ErrorType, Reason, Response},
},
write_log,
};
Expand Down Expand Up @@ -65,7 +65,15 @@ pub fn handle_msg(admin: bool, data: String) {
}

(_, _, _, Command::ListApps(ref_id)) => {
if let Some(x) = list_apps() {
if let Some(mut x) = list_apps() {
let user = get_current_user().unwrap_or("");

if let Some(mut a) = list_user_apps(Some(user.into())) {
let (_, mut data) = a.remove(0);
drop(a);
x.extend(data);
}

let val = Response::as_msg(Response::ListApps(ref_id, x));

ws_send(&mut ws, &val).await;
Expand Down
15 changes: 14 additions & 1 deletion src-service/src/handlers/service/windows/exe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ static mut COUNTER: RefId = 0;
mod daemon;
pub mod pipe;

pub async fn install(path: &str, app: &AHQStoreApplication, update: bool) -> Option<InstallResult> {
pub async fn install(
path: &str,
app: &AHQStoreApplication,
update: bool,
_user: bool,
_username: &str,
) -> Option<InstallResult> {
if unsafe { !CONNECTED } {
return None;
}
Expand All @@ -40,12 +46,19 @@ pub async fn install(path: &str, app: &AHQStoreApplication, update: bool) -> Opt
resp.push(0);
}

let windows_options = app.get_win_options()?;
let args = windows_options
.installerArgs
.as_ref()
.map_or_else(|| vec![], |x| x.iter().map(|x| x.as_str()).collect());

let data = serde_json::to_string(&json!({
"display": app.appDisplayName,
"id": app.appId,
"icon": &icon_path,
"path": &path,
"count": count,
"args": args
}))
.ok()?;

Expand Down
Loading

0 comments on commit bf4f26f

Please sign in to comment.