Skip to content
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
236 commits
Select commit Hold shift + click to select a range
82e92d3
init
Asys-sh Dec 18, 2025
8bcac24
Merge branch 'master' of https://github.com/Nazeofel/rustcast
Asys-sh Dec 18, 2025
189b476
chore(app.rs): gets config file from new function..
Asys-sh Dec 18, 2025
597deba
fix(utils.rs):
Asys-sh Dec 18, 2025
0e6add6
fix(Windows/app.rs)
Asys-sh Dec 18, 2025
8ac5ed1
Merge remote-tracking branch 'upstream/master'
Asys-sh Dec 18, 2025
5d47c49
fix(Windows/commands.rs)
Asys-sh Dec 18, 2025
03d683a
format
Asys-sh Dec 18, 2025
d96c440
feat(windows): centering
Asys-sh Dec 18, 2025
df924f3
remove(unused struct)
Asys-sh Dec 18, 2025
6a06803
chore(windows/app.rs)
Asys-sh Dec 18, 2025
58cbb2d
Merge pull request #32 from Nazeofel/master
unsecretised Dec 18, 2025
cbf77e4
fix(macos)
Asys-sh Dec 18, 2025
c071eb6
fix(windows/app.rs)
Asys-sh Dec 18, 2025
fbb7eb3
fix(windows): focus app
Asys-sh Dec 18, 2025
ea49759
Merge pull request #36 from Nazeofel/windows-support
unsecretised Dec 19, 2025
16022c7
Fix issues clippy highlighted
unsecretised Dec 19, 2025
188c908
Formatting
unsecretised Dec 19, 2025
9fde49e
Merge pull request #37 from unsecretised/windows-support-clippy-fixes
unsecretised Dec 19, 2025
f03ff73
yay
Asys-sh Dec 19, 2025
b6bb6ff
hmm
Asys-sh Dec 19, 2025
3a8e96e
fix for mac
Asys-sh Dec 19, 2025
9f526e2
chore(imports)
Asys-sh Dec 19, 2025
ae4dfa7
feat(macos/indexing):
Asys-sh Dec 19, 2025
4de0d83
fix(windows/imports)
Asys-sh Dec 19, 2025
0a5fdd3
Merge branch 'windows-support' into windows-support
unsecretised Dec 20, 2025
7344853
Remove `.DS_Store`
unsecretised Dec 20, 2025
d1a853e
Merge branch 'master' into windows-support
unsecretised Jan 13, 2026
5f8a683
Fix functionality and a ~~few~~ lot of errors
unsecretised Jan 13, 2026
9b3e8f1
fix: make it compile
Jan 13, 2026
33d5f55
refractor: general refractors
Jan 13, 2026
d56dd98
refractor: shove cross platform into its own module
Jan 13, 2026
035ad27
refractor: use url crate
Jan 13, 2026
d98040e
clean: remove pointless #[cfg]
Jan 13, 2026
2d14724
refractor: use get_config_installation_dir instead of hardcoded env var
Jan 13, 2026
910d25e
clean: run cargo fmt
Jan 13, 2026
0f53e9c
Merge pull request #92 from Mnem42/windows-support
unsecretised Jan 14, 2026
a077788
fix up macos related stuff that broke
unsecretised Jan 14, 2026
d901d8b
A few fixes
unsecretised Jan 14, 2026
067def7
Switch condition
unsecretised Jan 14, 2026
3404ecf
Merge pull request #96 from unsecretised/fix-trayicon-for-windows
unsecretised Jan 14, 2026
878e2a7
Merge branch 'master' into windows-support
unsecretised Jan 14, 2026
eba8e68
remove warning
unsecretised Jan 14, 2026
f05d3cf
Merge branch 'master' into windows-support
unsecretised Jan 16, 2026
4e34b23
Format -_-
unsecretised Jan 16, 2026
c220d73
chore: fix import error
unsecretised Jan 16, 2026
fb7e04d
Merge branch 'master' into windows-support
unsecretised Jan 16, 2026
e3bf8dd
Merge branch 'master' into windows-support
unsecretised Jan 16, 2026
8097eb0
Merge branch 'master' into windows-support
unsecretised Jan 16, 2026
93c8875
Merge branch 'master' into windows-support
unsecretised Jan 19, 2026
9b5d2c9
Fix up merge stuff
unsecretised Jan 19, 2026
d53ce1c
feat: a bit of tracing support
Jan 19, 2026
c626864
clean: use_unwrap_or_default()
Jan 19, 2026
5fb7cd8
clean: smol rename
Jan 19, 2026
10ad725
feat: more tracing
Jan 19, 2026
e01d657
clean: run cargo fmt
Jan 19, 2026
4a803da
Merge branch 'windows-support' into windows-support
Mnem42 Jan 19, 2026
6739d3e
fix(cfg/macos)
Asys-sh Jan 20, 2026
08af1ec
fix(windows/indexing)
Asys-sh Jan 20, 2026
4634d60
fix(menubar)
Asys-sh Jan 20, 2026
cf52bd6
fastser
Asys-sh Jan 20, 2026
e309041
feat: put very verbose (i.e. trace) logs in another file
Mnem42 Jan 20, 2026
da47240
Merge branch 'windows-support' into windows-support
Mnem42 Jan 20, 2026
498fdde
stuff
Mnem42 Jan 20, 2026
057c896
clean: fix formatting
Mnem42 Jan 20, 2026
72af67b
fix: better error message
Mnem42 Jan 20, 2026
bf9aa59
fix: remove random URL sitting in the code
Mnem42 Jan 20, 2026
3e1067a
clean: better error message
Mnem42 Jan 20, 2026
a41bcf3
fix: replace todo with some proper text
Jan 20, 2026
d56d9d4
clean: remove unused header from Cargo.toml
Jan 20, 2026
425b78e
fix: unbreak use
Jan 20, 2026
565528f
Jan 20, 2026
8c78b79
clean: run cargo fmt
Jan 20, 2026
6356081
clean: run cargo clippy --fix
Jan 20, 2026
3639e3c
stuff
Jan 20, 2026
21404e1
clean: run cargo fmt and clippy --fix
Jan 20, 2026
cadf527
general stuff
Jan 20, 2026
2996e8c
clean: run cargo fmt
Jan 20, 2026
bb22985
shhh
Jan 20, 2026
9671165
refactor: make get_apps_from_known_folder an iter
Jan 20, 2026
f630b76
Revert "refactor: make get_apps_from_known_folder an iter"
Jan 20, 2026
5bfffa9
clean: run cargo fmt
Jan 20, 2026
8d395bb
Merge pull request #113 from Mnem42/windows-support
unsecretised Jan 21, 2026
43ae23f
Merge branch 'master' into windows-support
unsecretised Jan 21, 2026
2e381a2
Fixes for macos
unsecretised Jan 21, 2026
0d423ea
refactor: use PathBuf instead of string
Jan 21, 2026
d91f119
doc: general
Jan 21, 2026
260d9a7
feat: add config entries and glob
Jan 21, 2026
79ee28e
fix: unbreak
Jan 21, 2026
64d2185
feat: working exclude pattern system
Jan 21, 2026
2310313
Add include patterns
Jan 21, 2026
c6dfb78
refactor: do the pattern parsing the right way + other stuff
Jan 21, 2026
ba10b99
clean: run cargo fmt
Jan 21, 2026
468e19c
Merge branch 'windows-support' into path_exclusions
Mnem42 Jan 21, 2026
9afbe9a
refactor: better error handling and stuff
Jan 21, 2026
52a3e61
clean: run clippy --fix and fmt
Jan 21, 2026
37e5ae5
clean: remove parse_patterns
Jan 21, 2026
c3f3403
Merge branch 'path_exclusions' of https://github.com/Mnem42/rustcast …
Jan 21, 2026
aac19f9
fix: this match
Jan 21, 2026
ebbb976
fix: general minor unbreaking
Jan 22, 2026
fb0726f
refactor: promote windows.rs into a directory and split
Jan 22, 2026
340fd70
clean: run clippy --fix and fmt
Jan 22, 2026
994d972
clean: comment out capture_frontmost + remove meaningless warn
Jan 22, 2026
ff35cd6
refactor: split unit conversion
Jan 22, 2026
d304761
docs: convert the tsdocs to rust docs
Jan 22, 2026
4156b58
feat: opening urls on all platforms
Jan 22, 2026
21d75d4
feat: general minor logging improvements
Jan 22, 2026
1eab43b
refactor: move debug stuff out of cfg'd stuff
Jan 22, 2026
3607173
refactor: make update handling logs trace
Jan 22, 2026
3eea53e
stuff
Jan 22, 2026
83e2aec
clean: run fmt and clippy
Jan 22, 2026
3d6ff63
clean: clear warning
Jan 22, 2026
b00cbba
feat: general app finding refactors
Jan 23, 2026
7020ef8
clean: run fmt and clippy --fix
Jan 23, 2026
bb7d177
fix: usage of index_exclude_patterns
Jan 23, 2026
527f77a
feat: make it possible to set depths for include files
Jan 23, 2026
173e356
fix: remove trailing slash
Jan 23, 2026
f63d1b4
Merge branch 'master' into windows-support
unsecretised Jan 26, 2026
19cc7c7
Merge branch 'master' into windows-support
unsecretised Jan 26, 2026
49ad2a9
a bit of linux support (can't build bcs of some xdo lib :/)
kybe236 Jan 26, 2026
6a8df2e
add nix dev shell to repo for easy dev setup for nix users
kybe236 Jan 26, 2026
5b9b158
idk
kybe236 Jan 26, 2026
e7f33ca
general fixes for macos
Jan 26, 2026
e02272f
should be working on linux with some inconveniences like the window n…
kybe236 Jan 27, 2026
279b25d
WIP: move off of keybinds for linux
kybe236 Jan 27, 2026
b2aa544
WIP: remove debug logging and fmt
kybe236 Jan 27, 2026
eec601a
test
kybe236 Jan 27, 2026
42ccae0
make it only be taller for linux
kybe236 Jan 27, 2026
96a1012
tweak ci
kybe236 Jan 28, 2026
9121567
fmt
kybe236 Jan 28, 2026
66f8f8e
ci tweaks
kybe236 Jan 28, 2026
e1ac17e
ci tweaks
kybe236 Jan 28, 2026
9f9a6c5
ci tweaks
kybe236 Jan 28, 2026
e229c06
fix macos clippy
kybe236 Jan 28, 2026
b83124a
fmt
kybe236 Jan 28, 2026
5c18d5e
tweak url alike checking
kybe236 Jan 28, 2026
e0d9125
implement sockets to reopen the window on linux
kybe236 Jan 28, 2026
8b87d70
add clipboard arg for linux
kybe236 Jan 28, 2026
71ffcfc
stuff
kybe236 Jan 30, 2026
f5f5b35
merge and stuff
Jan 30, 2026
f083ecd
fix: general warning clearing
Jan 30, 2026
8028cd4
Merge branch 'windows-support' into path_exclusions
Jan 30, 2026
dd1c4ec
Merge pull request #119 from Mnem42/path_exclusions
Mnem42 Jan 30, 2026
81779ab
.
Jan 30, 2026
27a1c98
Merge branch 'windows-support' of https://github.com/Mnem42/rustcast …
Jan 30, 2026
d4d4594
refactor: extract handler for Message::SearchQueryChanged
Mnem42 Jan 30, 2026
5a63e65
clean: clippy and fmt
Mnem42 Jan 30, 2026
f641b7c
.
Mnem42 Jan 30, 2026
c5216f4
clean: general use statement stuff
Mnem42 Jan 30, 2026
3296234
fix: general macos fixes
Mnem42 Jan 30, 2026
e71636f
clean: clear warning
Mnem42 Jan 30, 2026
0746d20
clean: quick fmt run
Mnem42 Jan 30, 2026
71a4401
Merge pull request #139 from Mnem42/windows-support
Mnem42 Jan 30, 2026
d8b7b50
fix: very minor changes to make it compile on windows
Mnem42 Jan 30, 2026
7413fb0
fix linux compilation error and fmt
kybe236 Jan 30, 2026
3ca13ba
refactor: trace icon pngs as svg
Mnem42 Jan 30, 2026
2b8df32
refactor: move icons to their own subdir
Mnem42 Jan 30, 2026
5d467b0
chore: generate pngs from icons
Mnem42 Jan 30, 2026
63e7db7
feat: extra icon sizes cause why not
Mnem42 Jan 30, 2026
6981da7
oops, wrong branch
Mnem42 Jan 30, 2026
f06d956
thicken part of icon + new icon size
Mnem42 Jan 31, 2026
406b96f
feat: general icon improvements
Mnem42 Jan 31, 2026
dc10609
clean: minor cleaning
Mnem42 Jan 31, 2026
753ee37
feat: general .lnk loading improvements
Mnem42 Jan 31, 2026
ae16573
clean: remove unused import
Mnem42 Jan 31, 2026
807dd41
feat: get shortcut icons (and theoretically registry app icons)
Mnem42 Jan 31, 2026
c5f8e07
clean: clippy and fmt
Mnem42 Jan 31, 2026
f782747
refactor: use PathBuf instead of plain String
Mnem42 Jan 31, 2026
501650a
fix: prevent finder from showing up on platforms other than macos
Mnem42 Jan 31, 2026
f9c2224
refactor: rename extract_appicons to appicon
Mnem42 Jan 31, 2026
481dfaa
fix: colours being inverted
Mnem42 Jan 31, 2026
aa92582
clean: clippy and fmt
Mnem42 Jan 31, 2026
f1e547d
Merge branch 'shortcut-fix' into taskbar-fix
Mnem42 Jan 31, 2026
ef2065f
re-add these sizes
Mnem42 Jan 31, 2026
bd5b9f9
fix: change the icons back to their original size
Mnem42 Jan 31, 2026
865cfb3
fix: make icons render as 32x32
Mnem42 Jan 31, 2026
5f7d6f3
fix: prevent icons from being zoomed
Mnem42 Jan 31, 2026
ee39115
clean: run cargo fmt
Mnem42 Jan 31, 2026
90db674
chore: regen optimised svg
Mnem42 Jan 31, 2026
d6230f2
fix: make it compile on macos
Mnem42 Jan 31, 2026
f010d2d
chore: update app version in Cargo.toml
Mnem42 Jan 31, 2026
23d31b8
feat: bigger taskbar icon size
Mnem42 Jan 31, 2026
f34bbd3
refactor: comment out unused icon sizes
Mnem42 Jan 31, 2026
81d858f
feat: use the 256x256 icon for taskbar
Mnem42 Jan 31, 2026
99ee6fa
fix: center window on open
cnaples79 Feb 1, 2026
bda2870
fix: center window on open
cnaples79 Feb 1, 2026
974dce6
Merge pull request #145 from Mnem42/upstream/windows-support
Mnem42 Feb 3, 2026
28c32e7
fix: make the GDI object cleanup code always run
Mnem42 Feb 3, 2026
b5c17eb
refactor: prevent get_first_icon from making useless img handles
Mnem42 Feb 3, 2026
cdf421b
improve nix dev env
kybe236 Feb 4, 2026
c38b826
mergy
kybe236 Feb 4, 2026
33205db
don't crash if the app icon path doesn't exist (doesn't rn on linux)
kybe236 Feb 4, 2026
b398a60
fmt
kybe236 Feb 4, 2026
1900218
add index_dirs support for linux
kybe236 Feb 7, 2026
c526e17
Merge branch 'windows-support' of https://github.com/Mnem42/rustcast …
Mnem42 Feb 7, 2026
18827d7
tweak flake.nix
kybe236 Feb 7, 2026
f778364
Merge pull request #136 from kybe236/linux-support
unsecretised Feb 7, 2026
5e09dbb
Merge branch 'windows-support' of https://github.com/Mnem42/rustcast …
Mnem42 Feb 7, 2026
fe6c882
refactor: General stuff to App
Mnem42 Feb 8, 2026
6d5a85e
fix: display icons for builtins and commands
Mnem42 Feb 8, 2026
b86fe87
fix: make it compile on macos
Mnem42 Feb 8, 2026
ae55ac1
clean: clippy --fix and fmt
Mnem42 Feb 8, 2026
fcd497e
refactor: use PathBuf instead of String
Mnem42 Feb 8, 2026
ffc5370
refactor: rename name_lc to alias
Mnem42 Feb 8, 2026
012bbfb
doc: add some docs
Mnem42 Feb 8, 2026
21ef137
refactor: make the default comparison by data and not by id
Mnem42 Feb 8, 2026
08b1520
clean: run cargo fmt
Mnem42 Feb 10, 2026
3035a39
fix: make it compile on macos
Mnem42 Feb 10, 2026
4753e9d
fix: linux fixes
Mnem42 Feb 10, 2026
440663e
Merge branch 'windows-support' into taskbar-fix
Mnem42 Feb 10, 2026
ad9cdfd
fix: .
Mnem42 Feb 10, 2026
6ce3cfe
clean: clippy --fix and fmt
Mnem42 Feb 10, 2026
9b836bf
Merge pull request #146 from unsecretised/app-refactor
unsecretised Feb 11, 2026
d5f97b5
Fix #147
unsecretised Feb 11, 2026
2c515f8
Merge branch 'windows-support' into taskbar-fix
Mnem42 Feb 11, 2026
f894e6f
fix: general unbreaking
Mnem42 Feb 11, 2026
c3c2778
clean: clippy and fmt
Mnem42 Feb 11, 2026
1637368
Merge branch 'windows-support' into taskbar-fix
Mnem42 Feb 11, 2026
d37b6e7
fix: use file name instead of full path
Mnem42 Feb 11, 2026
ef6164f
fix: fix compile errors on macos
Mnem42 Feb 12, 2026
d130def
clean: run cargo fmt
Mnem42 Feb 12, 2026
235d45c
add experimental config files for debian packages
iamnotmega Feb 13, 2026
0e6a170
Merge branch 'unsecretised:windows-support' into windows-support
iamnotmega Feb 13, 2026
76e5308
Merge pull request #154 from iamnotmega/windows-support
Mnem42 Feb 13, 2026
dbdb900
feat: generally better logging
Mnem42 Feb 13, 2026
232a8f4
Merge branch 'unsecretised:windows-support' into windows-support
Mnem42 Feb 13, 2026
a9aee4d
Merge pull request #156 from Mnem42/windows-support
Mnem42 Feb 13, 2026
1de514f
Merge branch 'windows-support' into taskbar-fix
Mnem42 Feb 14, 2026
617e5e5
clean: general cleaning and simplification
Mnem42 Feb 14, 2026
971bfa3
Merge branch 'taskbar-fix' of https://github.com/Mnem42/rustcast into…
Mnem42 Feb 14, 2026
374ae17
stuff i cba to label
Mnem42 Feb 14, 2026
65eadfd
feat: stuff
Mnem42 Feb 14, 2026
8727a91
fix: duplicated code
Mnem42 Feb 14, 2026
d9d3eec
feat: set target for icon fetching
Mnem42 Feb 14, 2026
03a39ff
clean: cargo fmt
Mnem42 Feb 14, 2026
0758a2b
Merge pull request #141 from Mnem42/taskbar-fix
unsecretised Feb 19, 2026
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

22 changes: 15 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ name = "rustcast"
version = "0.1.0"
edition = "2024"


[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.52"
windows = { version = "0.58", features = ["Win32_UI_WindowsAndMessaging", "Win32_Foundation", "Win32_Graphics_Gdi", "Win32_System_Com", "Win32_UI_Shell"] }

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.6.3"
objc2-app-kit = "0.3.2"
objc2-application-services = { version = "0.3.2", default-features = false, features = [
"HIServices",
"Processes",
] }
objc2-foundation = { version = "0.3.2", features = ["NSString"] }

[dependencies]
anyhow = "1.0.100"
applications = "0.3.1"
Expand All @@ -11,18 +25,12 @@ global-hotkey = "0.7.0"
iced = { version = "0.14.0", features = ["image", "smol", "tokio"] }
icns = "0.3.1"
image = "0.25.9"
objc2 = "0.6.3"
objc2-app-kit = "0.3.2"
objc2-application-services = { version = "0.3.2", default-features = false, features = [
"HIServices",
"Processes",
] }
objc2-foundation = { version = "0.3.2", features = ["NSString"] }
rand = "0.9.2"
rayon = "1.11.0"
serde = { version = "1.0.228", features = ["derive"] }
tokio = { version = "1.48.0", features = ["full"] }
toml = "0.9.8"
walkdir = "2"

[package.metadata.bundle]
name = "RustCast"
Expand Down
138 changes: 94 additions & 44 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::commands::Function;
use crate::config::Config;
use crate::macos::{focus_this_app, transform_process_to_ui_element};
use crate::{macos, utils::get_installed_apps};

use crate::utils::{get_config_file_path, get_installed_apps, read_config_file};
use global_hotkey::{GlobalHotKeyEvent, HotKeyState};
use iced::futures::SinkExt;
use iced::{
Expand All @@ -18,8 +16,23 @@ use iced::{
window::{self, Id, Settings},
};

use objc2::rc::Retained;
use objc2_app_kit::NSRunningApplication;
#[cfg(target_os = "macos")]
use {
crate::macos::{focus_this_app, macos_window_config, transform_process_to_ui_element},
objc2::rc::Retained,
objc2_app_kit::NSApplicationActivationOptions,
objc2_app_kit::NSRunningApplication,
objc2_app_kit::NSWorkspace,
};

#[cfg(target_os = "windows")]
use {
crate::windows::open_on_focused_monitor,
iced::window::Position::Specific,
windows::Win32::Foundation::HWND,
windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, SetForegroundWindow},
};

use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use rayon::slice::ParallelSliceMut;

Expand Down Expand Up @@ -145,40 +158,45 @@ pub struct Tile {
options: Vec<App>,
visible: bool,
focused: bool,
#[cfg(target_os = "macos")]
frontmost: Option<Retained<NSRunningApplication>>,
#[cfg(target_os = "windows")]
frontmost: Option<HWND>,
config: Config,
open_hotkey_id: u32,
}

impl Tile {
/// A base window
pub fn new(keybind_id: u32, config: &Config) -> (Self, Task<Message>) {
let (id, open) = window::open(default_settings());
let settings = default_settings();
#[cfg(target_os = "windows")]
{
// get normal settings and modify position
let pos = open_on_focused_monitor();
settings.position = Specific(pos);
}

let (id, open) = window::open(settings);

let open = open.discard().chain(window::run(id, |handle| {
macos::macos_window_config(
&handle.window_handle().expect("Unable to get window handle"),
);
// should work now that we have a window
transform_process_to_ui_element();
{
#[cfg(target_os = "macos")]
{
macos_window_config(
&handle.window_handle().expect("Unable to get window handle"),
);
// should work now that we have a window
transform_process_to_ui_element();
}
}
}));

let store_icons = config.theme.show_icons;
// get config
let path = get_config_file_path();
let config = read_config_file(&path).unwrap();

let user_local_path = std::env::var("HOME").unwrap() + "/Applications/";

let paths = vec![
"/Applications/",
user_local_path.as_str(),
"/System/Applications/",
"/System/Applications/Utilities/",
];

let mut options: Vec<App> = paths
.par_iter()
.map(|path| get_installed_apps(path, store_icons))
.flatten()
.collect();
let mut options: Vec<App> = get_installed_apps(&config);

options.extend(config.shells.iter().map(|x| x.to_app()));
options.extend(App::basic_apps());
Expand Down Expand Up @@ -206,7 +224,11 @@ impl Tile {
match message {
Message::OpenWindow => {
self.capture_frontmost();
focus_this_app();
#[cfg(target_os = "macos")]
{
focus_this_app();
}

self.focused = true;
Task::none()
}
Expand Down Expand Up @@ -272,16 +294,13 @@ impl Tile {
Message::ClearSearchQuery => {
self.query_lc = String::new();
self.query = String::new();
self.prev_query_lc = String::new();
Task::none()
}

Message::ReloadConfig => {
self.config = toml::from_str(
&fs::read_to_string(
std::env::var("HOME").unwrap_or("".to_owned())
+ "/.config/rustcast/config.toml",
)
.unwrap_or("".to_owned()),
&fs::read_to_string(get_config_file_path()).unwrap_or("".to_owned()),
)
.unwrap();

Expand All @@ -292,12 +311,27 @@ impl Tile {
if hk_id == self.open_hotkey_id {
self.visible = !self.visible;
if self.visible {
Task::chain(
window::open(default_settings())
.1
.map(|_| Message::OpenWindow),
operation::focus("query"),
)
#[cfg(target_os = "windows")]
{
// get normal settings and modify position
let pos = open_on_focused_monitor();
let mut settings = default_settings();
settings.position = Specific(pos);
Task::chain(
window::open(settings).1.map(|_| Message::OpenWindow),
operation::focus("query"),
)
}

#[cfg(target_os = "macos")]
{
Task::chain(
window::open(default_settings())
.1
.map(|_| Message::OpenWindow),
operation::focus("query"),
)
}
} else {
let to_close = window::latest().map(|x| x.unwrap());
Task::batch([
Expand Down Expand Up @@ -445,18 +479,34 @@ impl Tile {
}

pub fn capture_frontmost(&mut self) {
use objc2_app_kit::NSWorkspace;
#[cfg(target_os = "macos")]
{
let ws = NSWorkspace::sharedWorkspace();
self.frontmost = ws.frontmostApplication();
};

let ws = NSWorkspace::sharedWorkspace();
self.frontmost = ws.frontmostApplication();
#[cfg(target_os = "windows")]
{
self.frontmost = Some(unsafe { GetForegroundWindow() });
}
}

#[allow(deprecated)]
pub fn restore_frontmost(&mut self) {
use objc2_app_kit::NSApplicationActivationOptions;
#[cfg(target_os = "macos")]
{
if let Some(app) = self.frontmost.take() {
app.activateWithOptions(NSApplicationActivationOptions::ActivateIgnoringOtherApps);
}
}

if let Some(app) = self.frontmost.take() {
app.activateWithOptions(NSApplicationActivationOptions::ActivateIgnoringOtherApps);
#[cfg(target_os = "windows")]
{
if let Some(handle) = self.frontmost {
unsafe {
let _ = SetForegroundWindow(handle);
}
}
}
}
}
Expand Down
38 changes: 24 additions & 14 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::process::Command;

use arboard::Clipboard;
#[cfg(target_os = "macos")]
use objc2_app_kit::NSWorkspace;
#[cfg(target_os = "macos")]
use objc2_foundation::NSURL;

use crate::config::Config;
use crate::utils::{get_config_file_path, open_application};

#[derive(Debug, Clone)]
pub enum Function {
Expand All @@ -20,9 +23,7 @@ impl Function {
pub fn execute(&self, config: &Config) {
match self {
Function::OpenApp(path) => {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(path),
));
open_application(path);
}
Function::RunShellCommand(shell_command) => {
Command::new("sh")
Expand All @@ -42,21 +43,30 @@ impl Function {
let query_args = query_string.replace(" ", "+");
let query = config.search_url.replace("%s", &query_args);
let query = query.strip_suffix("?").unwrap_or(&query);
NSWorkspace::new().openURL(
&NSURL::URLWithString_relativeToURL(
&objc2_foundation::NSString::from_str(query),
None,
)
.unwrap(),
);

#[cfg(target_os = "windows")]
{
Command::new("powershell")
.args(["-Command", &format!("Start-Process {}", query)])
.status()
.ok();
}

#[cfg(target_os = "macos")]
{
NSWorkspace::new().openURL(
&NSURL::URLWithString_relativeToURL(
&objc2_foundation::NSString::from_str(query),
None,
)
.unwrap(),
);
}
}

Function::OpenPrefPane => {
Command::new("open")
.arg(
std::env::var("HOME").unwrap_or("".to_string())
+ "/.config/rustcast/config.toml",
)
.arg(get_config_file_path())
.spawn()
.ok();
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Config {
pub placeholder: String,
pub search_url: String,
pub shells: Vec<Shelly>,
pub index_dirs: Vec<String>,
}

impl Default for Config {
Expand All @@ -27,6 +28,7 @@ impl Default for Config {
placeholder: String::from("Time to be productive!"),
search_url: "https://google.com/search?q=%s".to_string(),
shells: vec![],
index_dirs: vec![],
}
}
}
Expand Down
Loading