diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0a01eef..67818f2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,15 +3,47 @@ on: push: jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - windows-latest - - ubuntu-latest - - macos-latest - fail-fast: true + linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + # TODO: refactor toolchain version + toolchain: 1.49.0 + components: clippy, rustfmt + default: true + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libxcb-composite0-dev + - name: Build binary + run: | + cargo build --verbose --release + - name: Run clippy + uses: actions-rs/clippy-check@v1.0.7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets -- -D warnings + - name: Check formatting + run: cargo fmt --all -- --check + - name: Upload binary + uses: actions/upload-artifact@v2 + with: + name: stevenarella-linux + path: target/release/stevenarella + - name: Release binary + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: | + stevenarella* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + windows: + runs-on: windows-latest steps: - uses: actions/checkout@v2 - name: Install Rust @@ -20,14 +52,44 @@ jobs: toolchain: 1.49.0 components: clippy, rustfmt default: true - - name: Install dependencies - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y libxcb-composite0-dev - name: Build binary run: | cargo build --verbose --release + - name: Run clippy + uses: actions-rs/clippy-check@v1.0.7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets -- -D warnings + - name: Check formatting + run: cargo fmt --all -- --check + - name: Upload binary + uses: actions/upload-artifact@v2 + with: + name: stevenarella.exe + path: target/release/stevenarella.exe + - name: Release binary + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: | + target/release/stevenarella.exe + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: 1.49.0 + components: clippy, rustfmt + default: true + - name: Build binary + run: | + cargo build --verbose --release + chmod a+x target/release/stevenarella env: MACOSX_DEPLOYMENT_TARGET: 10.14 - name: Run clippy @@ -37,24 +99,59 @@ jobs: args: --all-targets -- -D warnings - name: Check formatting run: cargo fmt --all -- --check - - name: Move binary + - name: Package binary run: | - if [[ ${{ matrix.os }} == windows ]]; then - mv target/release/stevenarella.exe stevenarella-${{ matrix.os }}.exe - else - mv target/release/stevenarella stevenarella-${{ matrix.os }} - fi - shell: bash + cargo install cargo-bundle + cargo bundle --release + chmod a+x target/release/bundle/osx/Stevenarella.app/Contents/MacOS/stevenarella + cd target/release/bundle/osx + zip -r Stevenarella.app.zip Stevenarella.app - name: Upload binary uses: actions/upload-artifact@v2 with: - name: stevenarella-${{ matrix.os }} - path: stevenarella* + name: Stevenarella.app.zip + path: target/release/bundle/osx/Stevenarella.app.zip - name: Release binary if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v1 with: files: | - stevenarella* + target/release/bundle/osx/Stevenarella.app.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + web: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + # TODO: refactor toolchain version + toolchain: 1.49.0 + components: clippy, rustfmt + default: true + - name: Install wasm-pack + uses: jetli/wasm-pack-action@v0.3.0 + with: + version: 'latest' + - name: Build binary + run: | + rustup target add wasm32-unknown-unknown + cargo install wasm-bindgen-cli + wasm-pack build --dev + - name: Upload binary + uses: actions/upload-artifact@v2 + with: + name: stevenarella.wasm + path: target/wasm32-unknown-unknown/debug/stevenarella.wasm + # TODO: npm bundle? or only the .wasm + - name: Release binary + if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 + with: + files: | + target/wasm32-unknown-unknown/debug/stevenarella.wasm + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/Cargo.lock b/Cargo.lock index 5c2c6e1..f279f8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,6 +87,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "atty" version = "0.2.14" @@ -137,6 +149,17 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + [[package]] name = "block" version = "0.1.6" @@ -389,6 +412,12 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "core-foundation" version = "0.7.0" @@ -597,6 +626,26 @@ dependencies = [ "generic-array", ] +[[package]] +name = "dirs" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +dependencies = [ + "libc", + "redox_users", + "winapi 0.3.9", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -2080,6 +2129,17 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.15", + "redox_syscall", + "rust-argon2", +] + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -2134,6 +2194,18 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rusttype" version = "0.9.2" @@ -2401,6 +2473,7 @@ dependencies = [ "clipboard", "collision", "console_error_panic_hook", + "dirs", "flate2", "getrandom 0.2.1", "glow", diff --git a/Cargo.toml b/Cargo.toml index 950e431..0ec33cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,13 @@ description = "Multi-protocol multi-platform Minecraft-compatible client" repository = "https://github.com/iceiix/stevenarella" license = "MIT/Apache-2.0" +[package.metadata.bundle] +name = "Stevenarella" +identifier = "io.github.iceiix.stevenarella" +icon = ["resources/icon*.png"] +category = "Game" +osx_minimum_system_version = "10.14" + [lib] crate-type = ["cdylib", "rlib"] path = "src/main.rs" @@ -40,6 +47,7 @@ rsa_public_encrypt_pkcs1 = "0.3.0" structopt = "0.3.21" clipboard = "0.5.0" instant = "0.1.9" +dirs = "3.0.1" # clippy = "*" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/resources/icon128x128.png b/resources/icon128x128.png new file mode 100644 index 0000000..30f8f21 Binary files /dev/null and b/resources/icon128x128.png differ diff --git a/resources/icon32x32.png b/resources/icon32x32.png new file mode 100644 index 0000000..b4d8b4f Binary files /dev/null and b/resources/icon32x32.png differ diff --git a/src/main.rs b/src/main.rs index 2615820..9a37304 100644 --- a/src/main.rs +++ b/src/main.rs @@ -209,14 +209,7 @@ cfg_if! { use glow::HasRenderLoop; extern crate console_error_panic_hook; pub use console_error_panic_hook::set_once as set_panic_hook; - } else { - #[inline] - pub fn set_panic_hook() {} - } -} -cfg_if! { - if #[cfg(target_arch = "wasm32")] { use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -227,11 +220,26 @@ cfg_if! { } } -fn main2() { - let opt = Opt::from_args(); +fn init_config_dir() { + if std::path::Path::new("conf.cfg").exists() { + return; + } + if let Some(mut path) = dirs::config_dir() { + path.push("Stevenarella"); + if !path.exists() { + std::fs::create_dir_all(path.clone()).unwrap(); + } + std::env::set_current_dir(path).unwrap(); + } +} + +fn main2() { + #[cfg(target_arch = "wasm32")] set_panic_hook(); + init_config_dir(); + let opt = Opt::from_args(); let con = Arc::new(Mutex::new(console::Console::new())); let proxy = console::ConsoleProxy::new(con.clone()); @@ -641,6 +649,11 @@ fn handle_window_event( if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed { ui_container.key_type(game, codepoint); } + + #[cfg(target_os = "macos")] + if game.is_logo_pressed && codepoint == 'q' { + game.should_close = true; + } } WindowEvent::MouseInput { state, button, .. } => match (state, button) {