Skip to content

Commit

Permalink
update macos script
Browse files Browse the repository at this point in the history
  • Loading branch information
x86y committed Mar 18, 2024
1 parent aae12ff commit e118485
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 50 deletions.
38 changes: 38 additions & 0 deletions assets/Dynasty.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>dynasty</string>
<key>CFBundleIdentifier</key>
<string>org.x86y.dynasty</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Dynasty</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>aae12ff-dirty</string>
<key>CFBundleIconFile</key>
<string>dynasty.icns</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSMainNibFile</key>
<string></string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>CFBundleDisplayName</key>
<string>Halloy</string>
<key>NSRequiresAquaSystemAppearance</key>
<string>NO</string>
</dict>
</plist>
Binary file not shown.
4 changes: 3 additions & 1 deletion scripts/macos
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash
# taken from https://github.com/squidowl/halloy/blob/main/scripts/build-macos.sh
# credits to Halloy

TARGET="dynasty"
ASSETS_DIR="assets"
RELEASE_DIR="target/release"
APP_NAME="Dynasty.app"
APP_TEMPLATE="$ASSETS_DIR/macos/$APP_NAME"
APP_TEMPLATE="$ASSETS_DIR/$APP_NAME"
APP_TEMPLATE_PLIST="$APP_TEMPLATE/Contents/Info.plist"
APP_DIR="$RELEASE_DIR/macos"
APP_BINARY="$RELEASE_DIR/$TARGET"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Config {
.await
.map_err(|_| SaveError::Write)?;
}
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
//tokio::time::sleep(std::time::Duration::from_secs(2)).await;
Ok(())
}
}
Expand Down
103 changes: 65 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod theme;
mod views;
mod ws;

use binance::api::Binance;
use binance::rest_model::OrderStatus;
use binance::ws_model::TradesEvent;
use config::Config;
Expand All @@ -23,6 +22,7 @@ use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::env;
use views::panes::orders::tb;
use views::panes::style;
use views::panes::view_controls;
use views::panes::Pane;
Expand Down Expand Up @@ -219,7 +219,10 @@ impl Application for App {

fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Saved(_) => Command::none(),
Message::Saved(_) => {
self.current_view = ViewState::Dashboard;
Command::none()
}
Message::SaveConfig(pub_k, sec_k) => Command::perform(
Config {
api_key: pub_k,
Expand Down Expand Up @@ -561,7 +564,7 @@ impl Application for App {
let focus = self.focus;
let total_panes = self.panes.len();

let pane_grid = PaneGrid::new(&self.panes, |id, pane, is_maximized| {
let dashboard_grid = PaneGrid::new(&self.panes, |id, pane, is_maximized| {
let is_focused = focus == Some(id);

let title = row![text(pane.id.to_string()).style(if is_focused {
Expand Down Expand Up @@ -590,7 +593,7 @@ impl Application for App {
PaneType::Book => book_view(&self.data.book),
PaneType::Trades => trades_view(&self.data.trades),
PaneType::Market => market_view(&self.new_price, &self.new_amt, &self.new_pair),
PaneType::Balances => balances_view(&self.data.balances, &self.data.prices),
PaneType::Balances => balances_view(&self.data.balances),
PaneType::Orders => orders_view(&self.data.orders, &self.data.prices),
}))
.title_bar(title_bar)
Expand All @@ -607,36 +610,47 @@ impl Application for App {
.on_drag(Message::Dragged)
.on_resize(10, Message::Resized);

let header = row![
Row::with_children(
self.watchlist_favorites
.iter()
.map(|t| {
let price_now = self.data.prices.get(t).unwrap_or(&0.0);
let ticker = t.split("USDT").next().unwrap();
let handle = svg::Handle::from_path(format!(
"{}/assets/logos/{}.svg",
env!("CARGO_MANIFEST_DIR"),
ticker
));

let svg = svg(handle)
.width(Length::Fixed(16.0))
.height(Length::Fixed(16.0));
return row![svg, text(format!("{:.2}", price_now))]
.spacing(4)
.align_items(iced::Alignment::Center);
})
.map(Element::from)
)
.spacing(12),
Space::new(Length::Fill, 1),
button("Settings")
.padding(8)
.style(iced::theme::Button::Text)
.on_press(Message::SetSettingsView)
]
.align_items(iced::Alignment::Center);
let header = container(
row![
Row::with_children(
self.watchlist_favorites
.iter()
.map(|t| {
let price_now = self.data.prices.get(t).unwrap_or(&0.0);
let ticker = t.split("USDT").next().unwrap();
let handle = svg::Handle::from_path(format!(
"{}/assets/logos/{}.svg",
env!("CARGO_MANIFEST_DIR"),
ticker
));

let svg = svg(handle)
.width(Length::Fixed(16.0))
.height(Length::Fixed(16.0));
return row![svg, text(format!("{:.2}", price_now)).size(14)]
.spacing(4)
.align_items(iced::Alignment::Center);
})
.map(Element::from)
)
.spacing(12),
Space::new(Length::Fill, 1),
button(text("Settings").size(14))
.padding(8)
.style(iced::theme::Button::Text)
.on_press(Message::SetSettingsView)
]
.align_items(iced::Alignment::Center),
)
.padding([0, 16])
.style(container::Appearance {
background: Some(iced::Background::Color(Color::from_rgb(0.07, 0.07, 0.07))),
border: iced::Border {
radius: 16.0.into(),
..Default::default()
},
..Default::default()
});

let api_key_input = text_input("API Key", &self.config.api_key)
.secure(true)
Expand All @@ -655,15 +669,25 @@ impl Application for App {
api_secret_key_input,
]
.spacing(10),
button("SAVE!").on_press(Message::SaveConfig(
button(tb("Save")).on_press(Message::SaveConfig(
self.config.api_key.clone(),
self.config.api_secret_key.clone()
)),
]
.spacing(10)
.padding(20)
.width(Length::Fill)
.height(Length::Fill)
.align_items(iced::Alignment::Center),
)
.style(container::Appearance {
background: Some(iced::Background::Color(Color::from_rgb(0.07, 0.07, 0.07))),
border: iced::Border {
radius: 16.0.into(),
..Default::default()
},
..Default::default()
})
.center_x()
.center_y();

Expand All @@ -678,10 +702,13 @@ impl Application for App {
column![container(
column![
header,
if self.current_view == ViewState::Dashboard {
container(pane_grid)
if self.current_view == ViewState::Dashboard
&& !self.config.api_key.is_empty()
&& !self.config.api_secret_key.is_empty()
{
container(dashboard_grid)
} else {
container(column![settings].width(Length::Fill).height(Length::Fill))
container(settings)
}
]
.spacing(8)
Expand Down
3 changes: 1 addition & 2 deletions src/views/panes/balances.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;

use binance::rest_model::Balance;
use iced::{
Expand All @@ -10,7 +9,7 @@ use crate::{theme::h2c, Message};

use crate::views::components::unstyled_btn::UnstyledBtn;

pub fn balances_view<'a>(bs: &[Balance], ps: &'a HashMap<String, f32>) -> Element<'a, Message> {
pub fn balances_view<'a>(bs: &[Balance]) -> Element<'a, Message> {
scrollable(
Column::with_children(
bs.iter()
Expand Down
33 changes: 25 additions & 8 deletions src/views/panes/market.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::views::components::better_btn::{GreenBtn, RedBtn};
use crate::views::components::input::Inp;
use iced::Font;
use iced::{
widget::{button, column, container, row, text, text_input, Space},
Alignment, Element, Length,
};

use crate::Message;

use super::orders::t;

macro_rules! bbtn {
($e: expr) => {
button($e).style(iced::theme::Button::Text).padding(8)
Expand Down Expand Up @@ -58,15 +61,29 @@ pub fn market_view<'a>(quote: &str, amt: &str, pair: &str) -> Element<'a, Messag
.spacing(4.0)
.width(350.0),
row![
button("BUY")
.style(iced::theme::Button::Custom(Box::new(GreenBtn {})))
.padding(8)
.on_press(Message::BuyPressed),
button(
t("Buy")
.font(Font {
weight: iced::font::Weight::Bold,
..Default::default()
})
.size(12)
)
.style(iced::theme::Button::Custom(Box::new(GreenBtn {})))
.padding(8)
.on_press(Message::BuyPressed),
Space::new(5.0, 0.0),
button("Sell")
.style(iced::theme::Button::Custom(Box::new(RedBtn {})))
.padding(8)
.on_press(Message::SellPressed)
button(
t("Sell")
.font(Font {
weight: iced::font::Weight::Bold,
..Default::default()
})
.size(12)
)
.style(iced::theme::Button::Custom(Box::new(RedBtn {})))
.padding(8)
.on_press(Message::SellPressed)
],
Space::new(Length::Fill, 1.0)
]
Expand Down

0 comments on commit e118485

Please sign in to comment.