Skip to content

Commit

Permalink
refactor: Use Rust to get installed apps and consider also user apps (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
poegl authored Feb 1, 2024
1 parent 3406d09 commit f1c98ae
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 27 deletions.
38 changes: 36 additions & 2 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tauri-plugin-deep-link = "0.1.2"
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
enigo = "0.1.3"
swift-rs = "1.0.6"
rust_search = "2.1.0"


[features]
Expand Down
28 changes: 28 additions & 0 deletions src-tauri/src/apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use rust_search::SearchBuilder;

#[tauri::command]
pub fn get_apps() -> Vec<String> {
let result: Vec<String>;
result = search(
vec!["~/Applications", "/Applications", "/System/Applications"],
Some(".app"),
Some(1),
);
return result;
}

fn search(
search_locations: Vec<&str>,
extension: Option<&str>,
depth: Option<usize>,
) -> Vec<String> {
let (location, more_locations) = search_locations.split_first().unwrap();
let result: Vec<String> = SearchBuilder::default()
.location(location)
.more_locations(more_locations.to_vec())
.depth(depth.unwrap_or(1))
.ext(extension.unwrap_or("*"))
.build()
.collect();
return result;
}
12 changes: 7 additions & 5 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{env, path::PathBuf};
mod apps;

use apps::get_apps;
use enigo::{Enigo, MouseControllable};
use serde_json::json;
use std::{env, path::PathBuf};
use swift_rs::{swift, Bool, Int, SRString};
use tauri::{
ActivationPolicy, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, Wry,
};

use enigo::{Enigo, MouseControllable};
use swift_rs::{swift, Bool, Int, SRString};
use tauri_plugin_store::{with_store, StoreCollection};

swift!(fn get_default_browser() -> SRString);
Expand Down Expand Up @@ -35,7 +36,8 @@ fn main() {
make_default_browser,
retrieve_app_icon,
open_picker_window,
open_preferences_window
open_preferences_window,
get_apps
])
.setup(|app| {
//? Allows application to receive and parse the URI passed in when opened.
Expand Down
14 changes: 0 additions & 14 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
"read",
"~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure"
]
},
{
"name": "findApps",
"cmd": "find",
"args": [
"~/Applications",
"/Applications",
"-iname",
"*.app",
"-prune",
"-not",
"-path",
"\"*/.*\""
]
}
]
},
Expand Down
10 changes: 4 additions & 6 deletions src/utils/get-installed-app-names.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { path } from '@tauri-apps/api';

import { AppName, apps } from '@config/apps';
import { Command } from '@tauri-apps/api/shell';
import { path } from '@tauri-apps/api';
import { invoke } from '@tauri-apps/api/tauri'

async function getAllInstalledAppNames(): Promise<string[]> {
const output = await new Command('findApps').execute();
const appNamesRaw = output.stdout.trim().split('\n');
const appNamePromises = appNamesRaw.map(async (appPath) => {
const apps = await invoke('get_apps') as Array<string>
const appNamePromises = apps.map(async (appPath) => {
const baseName = await path.basename(appPath);
const appName = baseName.substring(0, baseName.length - 4);
return appName;
Expand Down

0 comments on commit f1c98ae

Please sign in to comment.