Skip to content

Commit 5abe451

Browse files
authored
Merge pull request #3 from DeveloperMindset-com/v2
merging v2 beta support
2 parents f2e51cf + 542070f commit 5abe451

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

.changes/migrated-to-tauri-beta.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-plugin-gamepad": "minor"
3+
"tauri-plugin-gamepad-api": "minor"
4+
---
5+
6+
Changed tauri from alpha to beta.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[package]
22
name = "tauri-plugin-gamepad"
3-
version = "0.0.2"
3+
version = "0.0.3"
44
authors = [ "Eugene Hauptmann" ]
55
description = "A plugin for Tauri that provides a polyfill for Gamepad Web API that works on most common platforms."
66
edition = "2021"
77
rust-version = "1.60"
88
exclude = ["/examples", "/webview-dist", "/webview-src", "node_modules"]
99
license-file = "LICENSE"
1010
homepage = "https://developermindset.com/tauri-plugin-gamepad/"
11-
repository = "https://github.com/eugenehp/tauri-plugin-gamepad"
11+
repository = "https://github.com/DeveloperMindset-com/tauri-plugin-gamepad"
1212
readme = "README.md"
1313
keywords = ["polyfill", "gamepad", "gilrs", "tauri", "joystick"]
14-
categories = ["api-bindings","web-programming","simulation","os","game-development"]
14+
categories = ["api-bindings", "web-programming", "simulation", "os", "game-development"]
1515

1616
[dependencies]
17-
tauri = { version = "1.5.2" }
17+
tauri = { version = "2.0.0-beta" }
1818
serde = "1.0"
1919
thiserror = "1.0"
2020
gilrs = {version = "0.10.4", features = ["serde-serialize"]}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A plugin for [Tauri](https://github.com/tauri-apps/tauri) that provides a polyfi
66

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

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

1111
## Why
1212

package.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@
33
"version": "0.0.2",
44
"author": "Eugene Hauptmann",
55
"homepage": "https://developermindset.com/tauri-plugin-gamepad/",
6+
"repository": {"url": "https://github.com/eugenehp/tauri-plugin-gamepad"},
67
"description": "A plugin for Tauri that provides a polyfill for Gamepad Web API that works on most common platforms.",
78
"repository": {"url": "https://github.com/eugenehp/tauri-plugin-gamepad"},
89
"browser": "webview-dist/index.js",
910
"main": "webview-dist/index.js",
1011
"types": "webview-dist/index.d.ts",
11-
"keywords": ["polyfill", "api", "rust", "gamepad", "gilrs", "tauri", "joystick"],
12+
"type": "module",
13+
"keywords": [
14+
"polyfill",
15+
"api",
16+
"rust",
17+
"gamepad",
18+
"gilrs",
19+
"tauri",
20+
"joystick"
21+
],
1222
"scripts": {
1323
"build": "rollup -c ./webview-src/rollup.config.js",
1424
"watch": "rollup -c ./webview-src/rollup.config.js --watch",
1525
"prepublishOnly": "npm run build",
1626
"pretest": "npm run build"
1727
},
1828
"devDependencies": {
19-
"@rollup/plugin-node-resolve": "13.3.0",
20-
"@rollup/plugin-typescript": "8.3.3",
21-
"rollup": "2.75.6",
22-
"rollup-plugin-terser": "7.0.2",
29+
"@rollup/plugin-node-resolve": "15.2.3",
30+
"@rollup/plugin-typescript": "11.1.5",
31+
"rollup": "^4.9.0",
32+
"@rollup/plugin-terser": "0.4.4",
2333
"typescript": "4.7.3"
2434
},
2535
"dependencies": {
26-
"@tauri-apps/api": "^1.0.0",
36+
"@tauri-apps/api": "^2.0.0-alpha.12",
2737
"tslib": "^2.1.0"
2838
}
2939
}

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use tauri::{Emitter, EventTarget};
2+
13
use gilrs::{Event, EventType, Gamepad, Gilrs, MappingSource};
24

35
use serde_json::{json, Value};
@@ -8,7 +10,7 @@ use std::u16;
810
use tauri::{
911
command,
1012
plugin::{Builder, TauriPlugin},
11-
AppHandle, Manager, Runtime, Window,
13+
AppHandle, Runtime, Window,
1214
};
1315

1416
mod utils;
@@ -74,7 +76,7 @@ async fn execute<R: Runtime>(app: AppHandle<R>, _window: Window<R>) {
7476
while let Some(Event { id, event, time }) = gilrs.next_event() {
7577
let gamepad = gilrs.gamepad(id);
7678
let payload = gamepad_to_json(gamepad, event, time);
77-
app.emit_all("event", payload).unwrap();
79+
app.emit_to(EventTarget::any(), "event", payload).unwrap();
7880
}
7981
}
8082
}

webview-dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
//@ts-ignore
12
import { listen } from "@tauri-apps/api/event";
2-
import { invoke } from "@tauri-apps/api/tauri";
3+
//@ts-ignore
4+
import { invoke } from "@tauri-apps/api/primitives";
35

46
export type PluginEvent = {
57
id: number;
@@ -31,7 +33,8 @@ const start = () => {
3133
invoke("plugin:gamepad|execute");
3234
navigator.getGamepads = getGamepads;
3335

34-
unlisten = listen<PluginEvent>("event", ({ payload }) => {
36+
unlisten = listen<PluginEvent>("event", (event: any) => {
37+
const { payload } = event;
3538
let gamepad = eventToGamepad(payload);
3639
let added = false;
3740
gamepads = gamepads.map((g) => {

webview-src/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { nodeResolve } from '@rollup/plugin-node-resolve'
2-
import { terser } from 'rollup-plugin-terser'
2+
import terser from '@rollup/plugin-terser'
33
import typescript from '@rollup/plugin-typescript'
44

55
export default {

0 commit comments

Comments
 (0)