Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
.DS_Store
# ignore bin in built app
assets/macos/RustCast.app/Contents/MacOS/rustcast
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libc = "0.2.180"
log = "0.4.29"
minreq = { version = "2.14.1", features = ["https"] }
objc2 = "0.6.3"
objc2-app-kit = { version = "0.3.2", features = ["NSImage"] }
objc2-app-kit = { version = "0.3.2", features = ["NSImage", "NSScreen"] }
objc2-application-services = { version = "0.3.2", default-features = false, features = ["HIServices", "Processes"] }
objc2-core-foundation = "0.3.2"
objc2-core-graphics = { version = "0.3.2", features = ["CGEvent", "CGEventTypes", "CGRemoteOperation", "CGEventSource", "libc"] }
Expand Down
150 changes: 150 additions & 0 deletions assets/macos/RustCast.app/Contents/_CodeSignature/CodeResources
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>files</key>
<dict>
<key>Resources/icon.icns</key>
<data>
6M/cpx7PY0OdSPJTqZaFRWut0sU=
</data>
<key>Resources/icon.png</key>
<data>
cDJSpM8kGx53az6YYfkoZQA7wXc=
</data>
<key>Resources/lemon.png</key>
<data>
BE7OfGooJAzXwW8xgNPIWyh3nDs=
</data>
</dict>
<key>files2</key>
<dict>
<key>Resources/icon.icns</key>
<dict>
<key>hash2</key>
<data>
UVP08uiw8dyYIE2w18hd9PCcJox0BmkNVkSO2/qKnRo=
</data>
</dict>
<key>Resources/icon.png</key>
<dict>
<key>hash2</key>
<data>
phEsB7JUmgrkWy/0M10O7pbf8D2F3gBO7BV0Wo5NAq4=
</data>
</dict>
<key>Resources/lemon.png</key>
<dict>
<key>hash2</key>
<data>
bvgew5Cbsqdqva7z76ytvdUA1pJikiUQFKnz1LUKQyA=
</data>
</dict>
</dict>
<key>rules</key>
<dict>
<key>^Resources/</key>
<true/>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^version.plist$</key>
<true/>
</dict>
<key>rules2</key>
<dict>
<key>.*\.dSYM($|/)</key>
<dict>
<key>weight</key>
<real>11</real>
</dict>
<key>^(.*/)?\.DS_Store$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>2000</real>
</dict>
<key>^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^.*</key>
<true/>
<key>^Info\.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^PkgInfo$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^Resources/.*\.lproj/</key>
<dict>
<key>optional</key>
<true/>
<key>weight</key>
<real>1000</real>
</dict>
<key>^Resources/.*\.lproj/locversion.plist$</key>
<dict>
<key>omit</key>
<true/>
<key>weight</key>
<real>1100</real>
</dict>
<key>^Resources/Base\.lproj/</key>
<dict>
<key>weight</key>
<real>1010</real>
</dict>
<key>^[^/]+$</key>
<dict>
<key>nested</key>
<true/>
<key>weight</key>
<real>10</real>
</dict>
<key>^embedded\.provisionprofile$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
<key>^version\.plist$</key>
<dict>
<key>weight</key>
<real>20</real>
</dict>
</dict>
</dict>
</plist>
7 changes: 7 additions & 0 deletions scripts/local-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cargo build --release
mv target/release/rustcast assets/macos/RustCast.app/Contents/MacOS/rustcast
rm -rf ~/Applications/Rustcast.app
cp -r assets/macos/Rustcast.app ~/Applications/Rustcast.app
codesign --force --deep --sign - ~/Applications/RustCast.app
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum ResetField {
DebounceDelay,
StartAtLogin,
AutoUpdate,
CheckForUpdates,
HapticFeedback,
ShowMenubarIcon,
ClipboardHistory,
Expand Down Expand Up @@ -182,6 +183,7 @@ pub enum SetConfigFields {
SearchUrl(String),
ClipboardHistory(bool),
SetAutoUpdate(bool),
SetCheckForUpdates(bool),
HapticFeedback(bool),
ShowMenubarIcon(bool),
SetPage(MainPage),
Expand Down
34 changes: 34 additions & 0 deletions src/app/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,40 @@ impl App {
]
}

/// Window tiling actions (12 positions)
pub fn window_apps() -> Vec<App> {
use crate::platform::macos::window::TilePosition;

let icons = icns_data_to_handle(ICNS_ICON.to_vec());

let actions: &[(&str, TilePosition)] = &[
("Left Half", TilePosition::LeftHalf),
("Right Half", TilePosition::RightHalf),
("Top Half", TilePosition::TopHalf),
("Bottom Half", TilePosition::BottomHalf),
("Top Left Quarter", TilePosition::TopLeft),
("Top Right Quarter", TilePosition::TopRight),
("Bottom Left Quarter", TilePosition::BottomLeft),
("Bottom Right Quarter", TilePosition::BottomRight),
("Left Third", TilePosition::LeftThird),
("Center Third", TilePosition::CenterThird),
("Right Third", TilePosition::RightThird),
("Maximize", TilePosition::Maximize),
];

actions
.iter()
.map(|(name, pos)| App {
ranking: 0,
open_command: AppCommand::Function(Function::TileWindow(pos.clone())),
desc: "Window Tiling".to_string(),
icons: icons.clone(),
display_name: name.to_string(),
search_name: name.to_lowercase(),
})
.collect()
}

/// This renders the app into an iced element, allowing it to be displayed in the search results
pub fn render(
self,
Expand Down
20 changes: 20 additions & 0 deletions src/app/pages/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,25 @@ fn general_tab(config: Box<Config>, theme: crate::config::Theme) -> Column<'stat
theme.clone(),
);

let theme_clone = theme.clone();
let check_for_updates = settings_row_with_reset(
settings_item_row([
settings_hint_text(theme.clone(), "Check for updates"),
checkbox(config.clone().check_for_updates)
.style(move |_, _| settings_checkbox_style(&theme_clone))
.on_toggle(move |input| {
Message::SetConfig(SetConfigFields::SetCheckForUpdates(input))
})
.into(),
notice_item(
theme.clone(),
"If rustcast should check for new releases and show the menubar indicator",
),
]),
ResetField::CheckForUpdates,
theme.clone(),
);

let theme_clone = theme.clone();
let haptic = settings_row_with_reset(
Row::from_iter([
Expand Down Expand Up @@ -400,6 +419,7 @@ fn general_tab(config: Box<Config>, theme: crate::config::Theme) -> Column<'stat
debounce,
start_at_login,
auto_update,
check_for_updates,
haptic,
tray_icon,
clipboard_history,
Expand Down
11 changes: 7 additions & 4 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Tile {
Subscription::run(crate::platform::macos::urlscheme::url_stream),
Subscription::run(handle_recipient),
Subscription::run(reload_events),
Subscription::run(handle_version_and_rankings),
Subscription::run_with(self.config.check_for_updates, handle_version_and_rankings),
Subscription::run(handle_theme_mode),
Subscription::run(check_event_tap),
Subscription::run(handle_clipboard_history),
Expand Down Expand Up @@ -828,10 +828,13 @@ fn handle_theme_mode() -> impl futures::Stream<Item = Message> {
})
}

fn handle_version_and_rankings() -> impl futures::Stream<Item = Message> {
stream::channel(100, async |mut output| {
fn handle_version_and_rankings(
check_for_updates: &bool,
) -> impl futures::Stream<Item = Message> + use<> {
let check_for_updates = *check_for_updates;
stream::channel(100, async move |mut output| {
loop {
if new_version_available().is_some() {
if check_for_updates && new_version_available().is_some() {
output.send(Message::UpdateAvailable).await.ok();
}
tokio::time::sleep(Duration::from_secs(30)).await;
Expand Down
2 changes: 2 additions & 0 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub fn new(hotkeys: Hotkeys, config: &Config) -> (Tile, Task<Message>) {

options.extend(App::basic_apps());
info!("Loaded basic apps / default apps");
options.extend(App::window_apps());
info!("Loaded window tiling apps");
options.par_sort_by_key(|x| x.display_name.len());
let options = AppIndex::from_apps(options);

Expand Down
23 changes: 22 additions & 1 deletion src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
std::process::exit(1);
}
};
if tile.config.show_trayicon {
if let Some(ref mut icon) = tile.tray_icon {
icon.set_menu(Some(Box::new(menu_builder(
tile.config.clone(),
sender,
tile.update_available,
))));
} else if tile.config.show_trayicon {
tile.tray_icon = Some(menu_icon(tile.config.clone(), sender));
}
Task::none()
Expand Down Expand Up @@ -532,6 +538,14 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

Message::RunFunction(command) => {
if let Function::TileWindow(pos) = &command {
if let Some(pid) = tile.frontmost.as_ref().map(|a| a.processIdentifier()) {
let ok = crate::platform::macos::window::tile_focused_window(pid, pos);
if !ok && tile.config.haptic_feedback {
perform_haptic(HapticPattern::Alignment);
}
}
}
command.execute(&tile.config);
let page_task = match tile.page {
Page::Settings => Task::done(Message::SwitchToPage(Page::Main)),
Expand Down Expand Up @@ -632,6 +646,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
new_options.extend(tile.config.shells.iter().map(|x| x.to_app()));
new_options.extend(tile.config.modes.to_apps());
new_options.extend(App::basic_apps());
new_options.extend(App::window_apps());
new_options.par_sort_by_key(|x| x.display_name.len());
tile.options = AppIndex::from_apps(new_options);

Expand Down Expand Up @@ -959,6 +974,9 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
SetConfigFields::SetAutoUpdate(au) => {
final_config.auto_update = au;
}
SetConfigFields::SetCheckForUpdates(check) => {
final_config.check_for_updates = check;
}
SetConfigFields::ShowMenubarIcon(show) => final_config.show_trayicon = show,
SetConfigFields::SetThemeFields(SetConfigThemeFields::Font(fnt)) => {
final_config.theme.font = Some(fnt)
Expand Down Expand Up @@ -1013,6 +1031,9 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
ResetField::DebounceDelay => tile.config.debounce_delay = default.debounce_delay,
ResetField::StartAtLogin => tile.config.start_at_login = default.start_at_login,
ResetField::AutoUpdate => tile.config.auto_update = default.auto_update,
ResetField::CheckForUpdates => {
tile.config.check_for_updates = default.check_for_updates;
}
ResetField::HapticFeedback => tile.config.haptic_feedback = default.haptic_feedback,
ResetField::ShowMenubarIcon => tile.config.show_trayicon = default.show_trayicon,
ResetField::ClipboardHistory => tile.config.cbhist = default.cbhist,
Expand Down
5 changes: 5 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum Function {
GoogleSearch(String),
Calculate(Expr),
Quit,
TileWindow(crate::platform::macos::window::TilePosition),
}

impl Function {
Expand Down Expand Up @@ -122,6 +123,10 @@ impl Function {
},

Function::Quit => std::process::exit(0),

// TileWindow is intercepted in the RunFunction handler which has
// access to the frontmost PID; nothing to do here.
Function::TileWindow(_) => {}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct Config {
pub log_path: String,
pub debounce_delay: u64,
pub auto_update: bool,
pub check_for_updates: bool,
}

impl Default for Config {
Expand All @@ -55,6 +56,7 @@ impl Default for Config {
cbhist_paste_on_select: false,
haptic_feedback: false,
auto_update: true,
check_for_updates: true,
show_trayicon: true,
main_page: MainPage::default(),
search_dirs: vec!["~".to_string()],
Expand Down
1 change: 1 addition & 0 deletions src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod events;
pub mod haptics;
pub mod launching;
pub mod urlscheme;
pub mod window;

use iced::wgpu::rwh::WindowHandle;

Expand Down
Loading
Loading