Skip to content
Draft
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
15 changes: 12 additions & 3 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ jobs:
- os: ubuntu-20.04
filename: 'beans-rs'
target: x86_64-unknown-linux-gnu
feature: gui

- os: ubuntu-20.04
filename: 'beans-rs'
target: x86_64-unknown-linux-musl
feature: default

- os: windows-latest
target: x86_64-pc-windows-msvc
filename: 'beans-rs.exe'
feature: gui
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -50,7 +58,8 @@ jobs:
libxinerama-dev \
libfltk1.3 \
libfltk1.3-dev \
libssl-dev
libssl-dev \
musl-tools

- uses: actions-rs/toolchain@v1
with:
Expand All @@ -60,7 +69,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --verbose --target ${{ matrix.target }}
args: --verbose --target ${{ matrix.target }} -F ${{ matrix.feature }}
- name: Code Signing (Windows)
if: ${{ matrix.os == 'windows-latest' }}
uses: skymatic/code-sign-action@v1
Expand All @@ -73,5 +82,5 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ matrix.target }}
name: binary-${{ matrix.os }}-${{ matrix.target }}-${{ matrix.feature }}
path: target/${{ matrix.target }}/debug/${{ matrix.filename }}
21 changes: 18 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ jobs:
include:
- os: ubuntu-20.04
filename: 'beans-rs'
output_filename: 'beans-rs'
target: x86_64-unknown-linux-gnu
feature: gui
- os: ubuntu-20.04
filename: 'beans-rs'
output_filename: 'beans-rs-nogui'
target: x86_64-unknown-linux-musl
feature: default

- os: windows-latest
target: x86_64-pc-windows-msvc
filename: 'beans-rs.exe'
output_filename: 'beans-rs.exe'
feature: gui

steps:
- uses: actions/checkout@master
Expand Down Expand Up @@ -51,7 +60,8 @@ jobs:
libxinerama-dev \
libfltk1.3 \
libfltk1.3-dev \
libssl-dev
libssl-dev \
musl-tools

- uses: actions-rs/toolchain@v1
with:
Expand All @@ -61,7 +71,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
args: --release --target ${{ matrix.target }} -F ${{ matrix.feature }}

- name: Code Signing (Windows)
if: ${{ matrix.os == 'windows-latest' }}
Expand All @@ -73,10 +83,15 @@ jobs:
description: 'beans-rs'
certificatesha1: '${{ secrets.CODESIGN_HASH }}'

- name: Rename output file
if: ${{ matrix.filename != matrix.output_filename }}
shell: pwsh
run: Move-Item -Path target/${{ matrix.target }}/release/${{ matrix.filename }} -Destination target/${{ matrix.target }}/release/${{ matrix.output_filename }}

- name: Upload binaries to release
uses: softprops/action-gh-release@v1
with:
files: target/${{ matrix.target }}/release/${{ matrix.filename }}
files: target/${{ matrix.target }}/release/${{ matrix.output_filename }}
tag_name: ${{ github.event.inputs.tag }}
draft: false
prerelease: true
Expand Down
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ description = "Installer for Open Fortress"
repository = "https://github.com/ktwrd/beans-rs"
license = "GPL-3.0"

[features]
default = []
gui = ["fl2rust", "fltk", "fltk-theme", "dark-light", "image"]

[dependencies]
async-recursion = "1.1.1"
async-stream = "0.3.5"
Expand All @@ -35,13 +39,13 @@ colored = "3.0.0"
sentry-log = "0.36.0"
chrono = "0.4.38"

fltk = { version = "1.5.1" }
fltk-theme = "0.7.4"
dark-light = "2.0.0"
image = { version = "0.25.5", features = ["png"] }
fltk = { version = "1.5.1", optional = true }
fltk-theme = {version = "0.7.4",optional = true }
dark-light = {version = "2.0.0", optional = true }
image = { version = "0.25.5", features = ["png"], optional = true }

[build-dependencies]
fl2rust = "0.6.0"
fl2rust = { version = "0.6.0", optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
winconsole = { version = "0.11.1", features = ["window"] }
Expand Down
7 changes: 5 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::path::PathBuf;
#[allow(dead_code, unused_macros, unused_imports)]
use std::{env,
io};
Expand All @@ -21,11 +20,12 @@ fn main()
}

/// generate files for fltk ui stuff
#[cfg(feature = "gui")]
fn fltk() -> Result<(), BuildError>
{
println!("cargo:rerun-if-changed=src/gui/shared_ui.fl");
let g = fl2rust::Generator::default();
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_path = std::path::PathBuf::from(env::var("OUT_DIR").unwrap());
if let Err(e) = g.in_out(
"src/gui/shared_ui.fl",
out_path.join("shared_ui.rs").to_str().unwrap()
Expand All @@ -39,6 +39,9 @@ fn fltk() -> Result<(), BuildError>

Ok(())
}
#[cfg(not(feature = "gui"))]
fn fltk() -> Result<(), BuildError>
{Ok(())}

/// check if a location exists
#[allow(dead_code)]
Expand Down
20 changes: 19 additions & 1 deletion src/gui/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use fltk::{image::PngImage,
prelude::*,
text::TextBuffer,
*};
use fltk::window::Window;
use log::warn;

use crate::gui::{apply_app_scheme,
icon,
shared_ui::GenericDialog,
wait_for_quit,
window_centre_screen,
GUIAppStatus};

pub struct DialogBuilder
Expand Down Expand Up @@ -113,3 +113,21 @@ impl DialogBuilder
wait_for_quit(&app, &receive_action);
}
}


/// Make the `window` provided the in be the center of the current screen.
fn window_centre_screen(window: &mut Window)
{
let (sx, sy) = app::screen_coords();
let width = window.width();
let height = window.height();
let (mut x, mut y) = app::screen_size();
x -= width as f64;
y -= height as f64;
window.resize(
((x / 2.0) as i32) + sx,
((y / 2.0) as i32) + sy,
width,
height
);
}
66 changes: 66 additions & 0 deletions src/gui/dialog_headless.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pub struct DialogBuilder
{
pub title: String,
pub content: String,
}

pub enum DialogIconKind
{
Default,
Warn,
Error
}

impl Default for crate::gui::DialogBuilder
{
fn default() -> Self
{
Self {
title: format!("beans v{}", crate::VERSION),
content: String::new()
}
}
}

impl crate::gui::DialogBuilder
{
pub fn new() -> Self
{
Self::default()
}
pub fn with_png_data(
mut self,
data: &[u8]
) -> Self
{
self
}
pub fn with_icon(
self,
kind: crate::gui::DialogIconKind
) -> Self
{
self
}
pub fn with_title(
mut self,
content: String
) -> Self
{
self.title = content.clone();
self
}
pub fn with_content(
mut self,
content: String
) -> Self
{
self.content = content.clone();
self
}
pub fn run(&self)
{
println!("============ {} ============", self.title);
println!("{}", self.content);
}
}
62 changes: 20 additions & 42 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
#[cfg(feature = "gui")]
use fltk::{app::Receiver,
prelude::*,
window::Window,
*};
#[cfg(feature = "gui")]
use fltk_theme::{color_themes,
ColorTheme};
#[cfg(feature = "gui")]
use log::debug;

#[cfg(feature = "gui")]
mod dialog;
#[cfg(not(feature = "gui"))]
mod dialog_headless;
#[cfg(feature = "gui")]
pub(crate) mod shared_ui;

#[cfg(feature = "gui")]
pub use dialog::*;
#[cfg(not(feature = "gui"))]
pub use dialog_headless::*;

pub mod icon;

Expand All @@ -33,56 +43,23 @@ pub enum GUIAppStatus
BtnContinue
}

/// Make the `window` provided the in be the center of the current screen.
pub fn window_centre_screen(window: &mut Window)
{
let (sx, sy) = app::screen_coords();
let width = window.width();
let height = window.height();
let (mut x, mut y) = app::screen_size();
x -= width as f64;
y -= height as f64;
window.resize(
((x / 2.0) as i32) + sx,
((y / 2.0) as i32) + sy,
width,
height
);
}
#[cfg(not(feature = "gui"))]
pub fn get_center_screen() -> (i32, i32)
{(0, 0)}

/// Get the X and Y position of the center of the current screen.
#[cfg(feature = "gui")]
pub fn get_center_screen() -> (i32, i32)
{
let (px, py) = app::screen_coords();
let (sw, sh) = app::screen_size();
(((sw / 2.0) as i32) + px, ((sh / 2.0) as i32) + py)
}

/// Ensure that a window has a fixed width & height, and that it will appear in
/// the centre of the current screen.
pub fn window_ensure(
win: &mut Window,
width: i32,
height: i32
)
{
window_centre_screen(win);
win.handle(move |w, ev| match ev
{
fltk::enums::Event::Resize =>
{
if w.width() > width || w.height() > height
{
w.set_size(width, height);
}
true
}
_ => false
});
win.make_resizable(false);
win.show();
}

#[cfg(not(feature = "gui"))]
pub fn apply_app_scheme()
{}
#[cfg(feature = "gui")]
pub fn apply_app_scheme()
{
let theme_content = match dark_light::detect()
Expand All @@ -109,7 +86,8 @@ pub fn apply_app_scheme()
theme.apply();
}

pub fn wait_for_quit(
#[cfg(feature = "gui")]
pub(crate) fn wait_for_quit(
app: &app::App,
receive_action: &Receiver<GUIAppStatus>
)
Expand Down
Loading