Skip to content

Commit

Permalink
Merge pull request #3 from DeveloperMindset-com/v2
Browse files Browse the repository at this point in the history
merging v2 beta support
  • Loading branch information
eugenehp authored Jul 14, 2024
2 parents f2e51cf + 542070f commit 5abe451
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changes/migrated-to-tauri-beta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-plugin-gamepad": "minor"
"tauri-plugin-gamepad-api": "minor"
---

Changed tauri from alpha to beta.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "tauri-plugin-gamepad"
version = "0.0.2"
version = "0.0.3"
authors = [ "Eugene Hauptmann" ]
description = "A plugin for Tauri that provides a polyfill for Gamepad Web API that works on most common platforms."
edition = "2021"
rust-version = "1.60"
exclude = ["/examples", "/webview-dist", "/webview-src", "node_modules"]
license-file = "LICENSE"
homepage = "https://developermindset.com/tauri-plugin-gamepad/"
repository = "https://github.com/eugenehp/tauri-plugin-gamepad"
repository = "https://github.com/DeveloperMindset-com/tauri-plugin-gamepad"
readme = "README.md"
keywords = ["polyfill", "gamepad", "gilrs", "tauri", "joystick"]
categories = ["api-bindings","web-programming","simulation","os","game-development"]
categories = ["api-bindings", "web-programming", "simulation", "os", "game-development"]

[dependencies]
tauri = { version = "1.5.2" }
tauri = { version = "2.0.0-beta" }
serde = "1.0"
thiserror = "1.0"
gilrs = {version = "0.10.4", features = ["serde-serialize"]}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A plugin for [Tauri](https://github.com/tauri-apps/tauri) that provides a polyfi

It's built on top of [gilrs](https://crates.io/crates/gilrs) library.

This plugin supports Tauri `1.x`, for `2.x` support check [v2 branch](https://github.com/eugenehp/tauri-plugin-gamepad/tree/v2).
This plugin supports Tauri `2.x` beta. For v1 version check [v1 branch](https://github.com/eugenehp/tauri-plugin-gamepad/tree/v1)

## Why

Expand Down
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@
"version": "0.0.2",
"author": "Eugene Hauptmann",
"homepage": "https://developermindset.com/tauri-plugin-gamepad/",
"repository": {"url": "https://github.com/eugenehp/tauri-plugin-gamepad"},
"description": "A plugin for Tauri that provides a polyfill for Gamepad Web API that works on most common platforms.",
"repository": {"url": "https://github.com/eugenehp/tauri-plugin-gamepad"},
"browser": "webview-dist/index.js",
"main": "webview-dist/index.js",
"types": "webview-dist/index.d.ts",
"keywords": ["polyfill", "api", "rust", "gamepad", "gilrs", "tauri", "joystick"],
"type": "module",
"keywords": [
"polyfill",
"api",
"rust",
"gamepad",
"gilrs",
"tauri",
"joystick"
],
"scripts": {
"build": "rollup -c ./webview-src/rollup.config.js",
"watch": "rollup -c ./webview-src/rollup.config.js --watch",
"prepublishOnly": "npm run build",
"pretest": "npm run build"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.3.3",
"rollup": "2.75.6",
"rollup-plugin-terser": "7.0.2",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-typescript": "11.1.5",
"rollup": "^4.9.0",
"@rollup/plugin-terser": "0.4.4",
"typescript": "4.7.3"
},
"dependencies": {
"@tauri-apps/api": "^1.0.0",
"@tauri-apps/api": "^2.0.0-alpha.12",
"tslib": "^2.1.0"
}
}
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tauri::{Emitter, EventTarget};

use gilrs::{Event, EventType, Gamepad, Gilrs, MappingSource};

use serde_json::{json, Value};
Expand All @@ -8,7 +10,7 @@ use std::u16;
use tauri::{
command,
plugin::{Builder, TauriPlugin},
AppHandle, Manager, Runtime, Window,
AppHandle, Runtime, Window,
};

mod utils;
Expand Down Expand Up @@ -74,7 +76,7 @@ async fn execute<R: Runtime>(app: AppHandle<R>, _window: Window<R>) {
while let Some(Event { id, event, time }) = gilrs.next_event() {
let gamepad = gilrs.gamepad(id);
let payload = gamepad_to_json(gamepad, event, time);
app.emit_all("event", payload).unwrap();
app.emit_to(EventTarget::any(), "event", payload).unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion webview-dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions webview-src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ts-ignore
import { listen } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/tauri";
//@ts-ignore
import { invoke } from "@tauri-apps/api/primitives";

export type PluginEvent = {
id: number;
Expand Down Expand Up @@ -31,7 +33,8 @@ const start = () => {
invoke("plugin:gamepad|execute");
navigator.getGamepads = getGamepads;

unlisten = listen<PluginEvent>("event", ({ payload }) => {
unlisten = listen<PluginEvent>("event", (event: any) => {
const { payload } = event;
let gamepad = eventToGamepad(payload);
let added = false;
gamepads = gamepads.map((g) => {
Expand Down
2 changes: 1 addition & 1 deletion webview-src/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { terser } from 'rollup-plugin-terser'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'

export default {
Expand Down

0 comments on commit 5abe451

Please sign in to comment.