Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use Rust to get installed apps and consider also user apps #27

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -17,7 +15,7 @@
(res) => res.status === 'fulfilled'
) as PromiseFulfilledResult<string>[];
const results = fulfilledResults.map(({ value }) => value);
console.log(

Check warning on line 18 in src/utils/get-installed-app-names.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'🪵 | file: get-installed-app-names.ts:20 | getAllInstalledAppNames | results:',
results
);
Expand Down
Loading