From f85af953f0a416f001ce492a6bb77495c71a81db Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Wed, 28 Feb 2024 13:18:45 +0100 Subject: [PATCH] Scroll view test --- .github/workflows/ci.yaml | 38 +++++++++++++++++++++++ Cargo.toml | 4 +++ wasm/index.html | 33 ++++++++++++++++++++ wasm/restart-audio-context.js | 57 +++++++++++++++++++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 wasm/index.html create mode 100644 wasm/restart-audio-context.js diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2895013..edce5a9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -76,3 +76,41 @@ jobs: components: rustfmt - name: Run cargo fmt run: cargo fmt --all -- --check + web_build: + runs-on: ubuntu-latest + timeout-minutes: 30 + concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ github.ref || github.run_id }} + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - name: Install wasm bindgen + uses: baptiste0928/cargo-install@v2 + with: + crate: wasm-bindgen-cli + - name: Build + run: cargo build --release --example simple --target wasm32-unknown-unknown && wasm-bindgen --out-dir ./out/ --target web ../target/wasm32-unknown-unknown/release/examples/simple.wasm + - name: Copy + working-directory: ./bevy_forge + run: cp -R assets out/ && cp wasm/* out/ && ls -R out + - name: Push + uses: s0/git-publish-subdir-action@develop + env: + SQUASH_HISTORY: true + REPO: self + BRANCH: gh-pages # The branch name where you want to push the assets + FOLDER: ./bevy_forge/out # The directory where your assets are generated + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub will automatically add this - you don't need to bother getting a token + MESSAGE: "Build: ({sha}) {msg}" # The commit message diff --git a/Cargo.toml b/Cargo.toml index 1a3a9c3..f389eb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,10 @@ name = "bevy_simple_scroll_view" version = "0.1.0" edition = "2021" +exclude = [".github/","wasm/"] +categories = ["game-development", "gui"] +keywords = ["bevy","ui"] +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/wasm/index.html b/wasm/index.html new file mode 100644 index 0000000..2033c8a --- /dev/null +++ b/wasm/index.html @@ -0,0 +1,33 @@ + + + + + Scroll view + + + + + + + + \ No newline at end of file diff --git a/wasm/restart-audio-context.js b/wasm/restart-audio-context.js new file mode 100644 index 0000000..69d9e4b --- /dev/null +++ b/wasm/restart-audio-context.js @@ -0,0 +1,57 @@ +// taken from https://developer.chrome.com/blog/web-audio-autoplay/#moving-forward +(function () { + // An array of all contexts to resume on the page + const audioContextList = []; + + // An array of various user interaction events we should listen for + const userInputEventNames = [ + 'click', + 'contextmenu', + 'auxclick', + 'dblclick', + 'mousedown', + 'mouseup', + 'pointerup', + 'touchend', + 'keydown', + 'keyup', + ]; + + // A proxy object to intercept AudioContexts and + // add them to the array for tracking and resuming later + self.AudioContext = new Proxy(self.AudioContext, { + construct(target, args) { + const result = new target(...args); + audioContextList.push(result); + return result; + }, + }); + + // To resume all AudioContexts being tracked + function resumeAllContexts(event) { + let count = 0; + + audioContextList.forEach(context => { + if (context.state !== 'running') { + context.resume(); + } else { + count++; + } + }); + + // If all the AudioContexts have now resumed then we + // unbind all the event listeners from the page to prevent + // unnecessary resume attempts + if (count == audioContextList.length) { + userInputEventNames.forEach(eventName => { + document.removeEventListener(eventName, resumeAllContexts); + }); + } + } + + // We bind the resume function for each user interaction + // event on the page + userInputEventNames.forEach(eventName => { + document.addEventListener(eventName, resumeAllContexts); + }); +})();