tauri-plugin-gamecenter-api 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Shubham
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shubham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,311 @@
1
- # Temporary Holding Version
1
+ # tauri-plugin-gamecenter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![crates.io](https://img.shields.io/crates/v/tauri-plugin-gamecenter.svg)](https://crates.io/crates/tauri-plugin-gamecenter)
4
+ [![npm](https://img.shields.io/npm/v/tauri-plugin-gamecenter-api.svg)](https://www.npmjs.com/package/tauri-plugin-gamecenter-api)
5
+ [![docs.rs](https://img.shields.io/docsrs/tauri-plugin-gamecenter)](https://docs.rs/tauri-plugin-gamecenter)
6
+ [![CI](https://github.com/shbmx/tauri-plugin-gamecenter/actions/workflows/ci.yml/badge.svg)](https://github.com/shbmx/tauri-plugin-gamecenter/actions/workflows/ci.yml)
7
+
8
+ Apple Game Center (GameKit) for [Tauri 2](https://v2.tauri.app) apps: player sign-in, leaderboard
9
+ scores, achievements and the Game Center dashboard on iOS.
10
+
11
+ - Quiet sign-in at launch that never shows UI, and interactive sign-in when the player asks for it
12
+ - Submit scores to leaderboards (with an optional context value)
13
+ - Report achievement progress, with or without GameKit's completion banner
14
+ - Open the Game Center dashboard
15
+ - Typed JavaScript/TypeScript bindings and a typed Rust API (`app.gamecenter()`)
16
+
17
+ ## Platform support
18
+
19
+ | Platform | Supported | What happens |
20
+ | -------- | :-------: | ---------------------------------------------------------------------------- |
21
+ | iOS | ✔ | Full support (iOS 14+). |
22
+ | macOS | ✘ | The plugin registers; every call rejects with error code `UNSUPPORTED`. |
23
+ | Android | ✘ | Same: every call rejects with `UNSUPPORTED`. (Game Center is Apple-only.) |
24
+ | Windows | ✘ | Same. |
25
+ | Linux | ✘ | Same. |
26
+
27
+ Because the plugin registers everywhere, you can add it unconditionally and ship one codebase to
28
+ every platform. Catch the `UNSUPPORTED` error (or skip the calls) where Game Center is unavailable.
29
+
30
+ ## Install
31
+
32
+ Requires Rust 1.92+ and Tauri 2.13+.
33
+
34
+ Add the crate to `src-tauri/Cargo.toml`:
35
+
36
+ ```toml
37
+ [dependencies]
38
+ tauri-plugin-gamecenter = "0.1"
39
+ ```
40
+
41
+ Or, to only build it into the iOS app:
42
+
43
+ ```toml
44
+ [target.'cfg(target_os = "ios")'.dependencies]
45
+ tauri-plugin-gamecenter = "0.1"
46
+ ```
47
+
48
+ (then register it under `#[cfg(target_os = "ios")]` too).
49
+
50
+ Add the JavaScript bindings with your package manager:
51
+
52
+ ```sh
53
+ pnpm add tauri-plugin-gamecenter-api
54
+ # or: npm install tauri-plugin-gamecenter-api / yarn add tauri-plugin-gamecenter-api
55
+ ```
56
+
57
+ ## Register the plugin
58
+
59
+ `src-tauri/src/lib.rs`:
60
+
61
+ ```rust
62
+ #[cfg_attr(mobile, tauri::mobile_entry_point)]
63
+ pub fn run() {
64
+ tauri::Builder::default()
65
+ .plugin(tauri_plugin_gamecenter::init())
66
+ .run(tauri::generate_context!())
67
+ .expect("error while running tauri application");
68
+ }
69
+ ```
70
+
71
+ ## Permissions
72
+
73
+ Allow the commands in a capability, e.g. `src-tauri/capabilities/default.json`:
74
+
75
+ ```json
76
+ {
77
+ "$schema": "../gen/schemas/desktop-schema.json",
78
+ "identifier": "default",
79
+ "windows": ["main"],
80
+ "permissions": ["core:default", "gamecenter:default"]
81
+ }
82
+ ```
83
+
84
+ Or a separate iOS-only capability, e.g. `src-tauri/capabilities/ios.json`:
85
+
86
+ ```json
87
+ {
88
+ "$schema": "../gen/schemas/mobile-schema.json",
89
+ "identifier": "ios-gamecenter",
90
+ "windows": ["main"],
91
+ "platforms": ["iOS"],
92
+ "permissions": ["gamecenter:default"]
93
+ }
94
+ ```
95
+
96
+ `gamecenter:default` allows every command. To allow only some, list them individually:
97
+
98
+ | Permission | Command |
99
+ | ------------------------------------- | -------------------- |
100
+ | `gamecenter:allow-authenticate` | `authenticate` |
101
+ | `gamecenter:allow-is-authenticated` | `is_authenticated` |
102
+ | `gamecenter:allow-submit-score` | `submit_score` |
103
+ | `gamecenter:allow-report-achievement` | `report_achievement` |
104
+ | `gamecenter:allow-show-dashboard` | `show_dashboard` |
105
+
106
+ Each also has a `deny-*` counterpart. See [permissions/autogenerated/reference.md](permissions/autogenerated/reference.md).
107
+
108
+ ## Enable Game Center for the iOS app
109
+
110
+ ### 1. Entitlement
111
+
112
+ Game Center needs the `com.apple.developer.game-center` entitlement. After `tauri ios init`, open the
113
+ entitlements file Tauri generated at
114
+ `src-tauri/gen/apple/<app>_iOS/<app>_iOS.entitlements` (`<app>` is your product name) and add:
115
+
116
+ ```xml
117
+ <key>com.apple.developer.game-center</key>
118
+ <true/>
119
+ ```
120
+
121
+ A complete file looks like:
122
+
123
+ ```xml
124
+ <?xml version="1.0" encoding="UTF-8"?>
125
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
126
+ <plist version="1.0">
127
+ <dict>
128
+ <key>com.apple.developer.game-center</key>
129
+ <true/>
130
+ </dict>
131
+ </plist>
132
+ ```
133
+
134
+ Alternatively open the project in Xcode (`pnpm tauri ios open`), select the `<app>_iOS` target, then
135
+ **Signing & Capabilities → + Capability → Game Center**, which writes the same key. Commit
136
+ `src-tauri/gen/apple` so the change is kept.
137
+
138
+ The App ID in your Apple Developer account must have Game Center enabled (it is on by default for
139
+ explicit App IDs). If you use manual signing, regenerate the provisioning profile after enabling it.
140
+
141
+ ### 2. App Store Connect
142
+
143
+ 1. Create the app record in [App Store Connect](https://appstoreconnect.apple.com) with the same
144
+ bundle ID as `identifier` in `tauri.conf.json`.
145
+ 2. In the app's **Services → Game Center** (or the **Game Center** section of the app version page,
146
+ depending on the App Store Connect layout), enable Game Center.
147
+ 3. Add **leaderboards** (classic or recurring) and **achievements**. Each gets an ID you choose,
148
+ e.g. `com.example.mygame.highscores` or `first_win`. Those IDs are what you pass to
149
+ `submitScore` and `reportAchievement`.
150
+ 4. Before the first release, attach the leaderboards and achievements to the app version under
151
+ **Game Center** on the version page, so they go live with it.
152
+
153
+ Leaderboards and achievements work in development builds as soon as they exist in App Store Connect,
154
+ even before the app is released, for players signed in on the device.
155
+
156
+ ## Usage (JavaScript / TypeScript)
157
+
158
+ ```ts
159
+ import {
160
+ authenticate,
161
+ isAuthenticated,
162
+ submitScore,
163
+ reportAchievement,
164
+ showDashboard,
165
+ GameCenterError
166
+ } from 'tauri-plugin-gamecenter-api'
167
+
168
+ // At launch: quiet sign-in, never shows UI.
169
+ const { authenticated } = await authenticate()
170
+
171
+ // After a game:
172
+ if (authenticated) {
173
+ await submitScore('com.example.mygame.highscores', 1200)
174
+ await reportAchievement('first_win')
175
+ }
176
+
177
+ // When the player taps a "Game Center" button:
178
+ const state = await authenticate({ interactive: true })
179
+ if (state.authenticated) await showDashboard()
180
+ ```
181
+
182
+ ### Recommended pattern: quiet sign-in, interactive on demand
183
+
184
+ GameKit decides when to show its sign-in sheet, and only offers it **once per app launch**. If the
185
+ sheet pops up the moment the app starts, many players dismiss it and then cannot sign in again until
186
+ they restart the app. This plugin avoids that:
187
+
188
+ 1. At launch call `authenticate()` (quiet). Players already signed in on the device are signed in
189
+ with no UI at all. If GameKit wants to show a sign-in sheet, the plugin **holds on to it** instead
190
+ of showing it, and resolves `{ authenticated: false }`.
191
+ 2. When the player asks for Game Center (taps "Leaderboards", "Achievements", "Sign in to Game
192
+ Center"), call `authenticate({ interactive: true })`. The held sheet is shown now, when the player
193
+ expects it, and the promise resolves once it closes.
194
+ 3. Only submit scores and achievements while signed in. If a player is not signed in, skip them
195
+ quietly; don't nag.
196
+
197
+ ### API
198
+
199
+ All functions reject with a `GameCenterError` (`code` + `message`) on failure.
200
+
201
+ #### `authenticate(options?: { interactive?: boolean }): Promise<AuthState>`
202
+
203
+ Signs the local player in. Resolves `{ authenticated: boolean }`. With `interactive: false` (default)
204
+ no UI is ever shown. With `interactive: true` the sign-in sheet may be shown and the promise resolves
205
+ when it closes. Declining or cancelling resolves `{ authenticated: false }`; it does not reject.
206
+
207
+ #### `isAuthenticated(): Promise<boolean>`
208
+
209
+ Whether the local player is signed in, without starting a sign-in.
210
+
211
+ #### `submitScore(leaderboardId: string, score: number, context?: number): Promise<void>`
212
+
213
+ Submits an integer `score` to the leaderboard. `context` is an optional integer stored with the score
214
+ (default `0`). Rejects with `NOT_AUTHENTICATED` when signed out.
215
+
216
+ #### `reportAchievement(achievementId: string, percent?: number, options?: { showCompletionBanner?: boolean }): Promise<void>`
217
+
218
+ Reports progress from `0` to `100` (default `100`, unlocked; clamped). GameKit's completion banner
219
+ is shown unless `showCompletionBanner: false`. Rejects with `NOT_AUTHENTICATED` when signed out.
220
+
221
+ #### `showDashboard(): Promise<void>`
222
+
223
+ Presents the Game Center dashboard and resolves once it is on screen. Rejects with
224
+ `NOT_AUTHENTICATED` when signed out (sign in interactively first) and `NO_VIEW` if there is no view to
225
+ present on.
226
+
227
+ #### `GameCenterError`
228
+
229
+ | `code` | Meaning |
230
+ | ------------------- | -------------------------------------------------------------------------- |
231
+ | `UNSUPPORTED` | Not running on iOS. |
232
+ | `NOT_AUTHENTICATED` | The player is not signed in to Game Center. |
233
+ | `NO_VIEW` | No view controller to present Game Center UI on. |
234
+ | `GAMEKIT` | GameKit returned an error; `message` has its description. |
235
+ | `INVALID_ARGUMENT` | Rejected by the bindings before reaching Game Center (empty ID, non-integer score). |
236
+ | `UNKNOWN` | Anything else, e.g. the command is not allowed by your capabilities. |
237
+
238
+ ## Usage (Rust)
239
+
240
+ ```rust
241
+ use tauri_plugin_gamecenter::{GamecenterExt, UNSUPPORTED};
242
+
243
+ #[tauri::command]
244
+ async fn game_over(app: tauri::AppHandle, score: i64) -> Result<(), String> {
245
+ let gamecenter = app.gamecenter();
246
+ match gamecenter.authenticate(false).await {
247
+ Ok(state) if state.authenticated => gamecenter
248
+ .submit_score("com.example.mygame.highscores", score, 0)
249
+ .await
250
+ .map_err(|e| e.to_string()),
251
+ Ok(_) => Ok(()), // signed out: skip quietly
252
+ Err(e) if e.code() == Some(UNSUPPORTED) => Ok(()), // not iOS
253
+ Err(e) => Err(e.to_string()),
254
+ }
255
+ }
256
+ ```
257
+
258
+ Methods: `authenticate(interactive) -> Result<AuthState>`, `is_authenticated() -> Result<bool>`,
259
+ `submit_score(id, score, context)`, `report_achievement(id, percent, show_completion_banner)`,
260
+ `show_dashboard()`. All are `async`. See [docs.rs](https://docs.rs/tauri-plugin-gamecenter).
261
+
262
+ ## Troubleshooting
263
+
264
+ **`authenticate` always resolves `{ authenticated: false }`**
265
+ - The player is not signed in to Game Center on the device: **Settings → Game Center**.
266
+ - The quiet call held back a sign-in sheet: call `authenticate({ interactive: true })` from a button.
267
+ - The player already dismissed the sheet in this launch. GameKit won't offer it again until the app
268
+ restarts; the player can also sign in from Settings.
269
+ - The entitlement is missing or the provisioning profile doesn't include Game Center. Check the
270
+ `.entitlements` file and the signing settings; the Xcode console logs an entitlement error.
271
+ - The bundle ID has no app record in App Store Connect or Game Center is not enabled for it.
272
+
273
+ **`submitScore` / `reportAchievement` reject with `GAMEKIT`**
274
+ - The leaderboard or achievement ID does not exist (yet) in App Store Connect, or doesn't match
275
+ exactly (IDs are case-sensitive). New IDs can take a while to become available.
276
+ - The score was sent to a leaderboard of a different type than you expect (e.g. a recurring
277
+ leaderboard that hasn't started).
278
+ - No network: GameKit usually queues scores and achievements offline, but can report an error.
279
+
280
+ **Sandbox / testing**
281
+ - Development and TestFlight builds use the Game Center sandbox environment. Sign in with a normal
282
+ Apple Account; on recent iOS versions a separate sandbox account isn't needed, and the sign-in
283
+ sheet or a banner indicates the sandbox.
284
+ - Sandbox leaderboards and achievements are separate from production. To reset achievements while
285
+ testing, use App Store Connect or `GKAchievement.resetAchievements` from a debug build.
286
+ - The iOS Simulator supports Game Center, but signing in there can be unreliable. Test on a device
287
+ when in doubt.
288
+
289
+ **Everything rejects with `UNSUPPORTED`**: you're not on iOS. **`UNKNOWN` with "not allowed"**: add
290
+ `gamecenter:default` (or the specific `allow-*` permissions) to a capability for that window.
291
+
292
+ ## Example
293
+
294
+ [`examples/tauri-app`](examples/tauri-app) is a minimal Vite + TypeScript app using every call.
295
+
296
+ ## Contributing
297
+
298
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
299
+
300
+ ## License
301
+
302
+ Licensed under either of
303
+
304
+ - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
305
+ - MIT license ([LICENSE-MIT](LICENSE-MIT))
306
+
307
+ at your option.
308
+
309
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the
310
+ work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
311
+ additional terms or conditions.
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+
5
+ /**
6
+ * Apple Game Center (GameKit) for Tauri apps: sign-in, leaderboard scores, achievements and the
7
+ * Game Center dashboard.
8
+ *
9
+ * Game Center only exists on iOS. On every other platform each function rejects with a
10
+ * {@link GameCenterError} whose `code` is `"UNSUPPORTED"`.
11
+ *
12
+ * @module
13
+ */
14
+ const KNOWN_CODES = [
15
+ 'UNSUPPORTED',
16
+ 'NOT_AUTHENTICATED',
17
+ 'NO_VIEW',
18
+ 'GAMEKIT',
19
+ 'INVALID_ARGUMENT'
20
+ ];
21
+ /** The error every function in this module rejects with. */
22
+ class GameCenterError extends Error {
23
+ constructor(code, message) {
24
+ super(message);
25
+ this.name = 'GameCenterError';
26
+ this.code = code;
27
+ }
28
+ /** Normalizes whatever `invoke` rejected with (an object from Swift or Rust, or a string). */
29
+ static from(error) {
30
+ if (error instanceof GameCenterError)
31
+ return error;
32
+ if (typeof error === 'object' && error !== null) {
33
+ const { code, message } = error;
34
+ const known = KNOWN_CODES.find((value) => value === code);
35
+ const text = typeof message === 'string' ? message : String(code ?? 'Game Center call failed');
36
+ return new GameCenterError(known ?? 'UNKNOWN', text);
37
+ }
38
+ const text = typeof error === 'string' ? error : 'Game Center call failed';
39
+ return new GameCenterError('UNKNOWN', text);
40
+ }
41
+ }
42
+ async function call(command, args) {
43
+ try {
44
+ return await core.invoke(`plugin:gamecenter|${command}`, args);
45
+ }
46
+ catch (error) {
47
+ throw GameCenterError.from(error);
48
+ }
49
+ }
50
+ function invalid(message) {
51
+ return new GameCenterError('INVALID_ARGUMENT', message);
52
+ }
53
+ /**
54
+ * Signs the local player in to Game Center.
55
+ *
56
+ * Call it quietly (`interactive: false`) at app start: a player who is already signed in on the
57
+ * device is signed in without any UI. Call it with `interactive: true` when the player asks for
58
+ * Game Center (e.g. taps a leaderboard button) to show the sign-in sheet if one is needed.
59
+ *
60
+ * Declining or cancelling never rejects; it resolves `{ authenticated: false }`. GameKit only
61
+ * offers its sign-in sheet once per app launch, so after the player dismisses it, further calls
62
+ * resolve `{ authenticated: false }` until the app is restarted or the player signs in from the
63
+ * Settings app.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { authenticate } from 'tauri-plugin-gamecenter-api'
68
+ * const { authenticated } = await authenticate()
69
+ * ```
70
+ */
71
+ async function authenticate(options = {}) {
72
+ return await call('authenticate', { interactive: options.interactive ?? false });
73
+ }
74
+ /** Whether the local player is signed in, without starting a sign-in. */
75
+ async function isAuthenticated() {
76
+ const state = await call('is_authenticated');
77
+ return state.authenticated;
78
+ }
79
+ /**
80
+ * Submits a score to a leaderboard. Rejects with `NOT_AUTHENTICATED` when signed out and with
81
+ * `GAMEKIT` when, for example, the leaderboard ID does not exist in App Store Connect.
82
+ *
83
+ * @param leaderboardId The leaderboard ID as created in App Store Connect.
84
+ * @param score An integer score.
85
+ * @param context An optional integer stored with the score, opaque to Game Center.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * await submitScore('com.example.game.highscores', 1200)
90
+ * ```
91
+ */
92
+ async function submitScore(leaderboardId, score, context = 0) {
93
+ if (!leaderboardId)
94
+ throw invalid('leaderboardId must not be empty');
95
+ if (!Number.isSafeInteger(score))
96
+ throw invalid('score must be an integer');
97
+ if (!Number.isSafeInteger(context))
98
+ throw invalid('context must be an integer');
99
+ await call('submit_score', { leaderboardId, score, context });
100
+ }
101
+ /**
102
+ * Reports progress towards an achievement. Rejects with `NOT_AUTHENTICATED` when signed out and
103
+ * with `GAMEKIT` when, for example, the achievement ID does not exist in App Store Connect.
104
+ *
105
+ * @param achievementId The achievement ID as created in App Store Connect.
106
+ * @param percent Progress from `0` to `100` (default `100`, i.e. unlocked). Clamped to that range.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * await reportAchievement('first_win')
111
+ * await reportAchievement('play_100_games', 37, { showCompletionBanner: false })
112
+ * ```
113
+ */
114
+ async function reportAchievement(achievementId, percent = 100, options = {}) {
115
+ if (!achievementId)
116
+ throw invalid('achievementId must not be empty');
117
+ if (!Number.isFinite(percent))
118
+ throw invalid('percent must be a finite number');
119
+ await call('report_achievement', {
120
+ achievementId,
121
+ percent: Math.min(100, Math.max(0, percent)),
122
+ showCompletionBanner: options.showCompletionBanner ?? true
123
+ });
124
+ }
125
+ /**
126
+ * Opens the Game Center dashboard (leaderboards, achievements, profile). Resolves once it is on
127
+ * screen. Rejects with `NOT_AUTHENTICATED` when signed out, so sign in interactively first:
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const { authenticated } = await authenticate({ interactive: true })
132
+ * if (authenticated) await showDashboard()
133
+ * ```
134
+ */
135
+ async function showDashboard() {
136
+ await call('show_dashboard');
137
+ }
138
+
139
+ exports.GameCenterError = GameCenterError;
140
+ exports.authenticate = authenticate;
141
+ exports.isAuthenticated = isAuthenticated;
142
+ exports.reportAchievement = reportAchievement;
143
+ exports.showDashboard = showDashboard;
144
+ exports.submitScore = submitScore;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Apple Game Center (GameKit) for Tauri apps: sign-in, leaderboard scores, achievements and the
3
+ * Game Center dashboard.
4
+ *
5
+ * Game Center only exists on iOS. On every other platform each function rejects with a
6
+ * {@link GameCenterError} whose `code` is `"UNSUPPORTED"`.
7
+ *
8
+ * @module
9
+ */
10
+ /** The local player's Game Center sign-in state. */
11
+ export interface AuthState {
12
+ /** `true` when the local player is signed in to Game Center. */
13
+ authenticated: boolean;
14
+ }
15
+ /** Options for {@link authenticate}. */
16
+ export interface AuthenticateOptions {
17
+ /**
18
+ * When `true`, the Game Center sign-in sheet may be shown and the promise settles once the
19
+ * player closes it. When `false` (the default), no UI is ever shown.
20
+ */
21
+ interactive?: boolean;
22
+ }
23
+ /** Options for {@link reportAchievement}. */
24
+ export interface ReportAchievementOptions {
25
+ /** Show GameKit's banner when the achievement completes. Defaults to `true`. */
26
+ showCompletionBanner?: boolean;
27
+ }
28
+ /**
29
+ * Why a call failed:
30
+ *
31
+ * - `UNSUPPORTED`: not running on iOS.
32
+ * - `NOT_AUTHENTICATED`: the local player is not signed in to Game Center.
33
+ * - `NO_VIEW`: there was no view to present Game Center UI on.
34
+ * - `GAMEKIT`: GameKit returned an error (unknown ID, network, sandbox, ...); see `message`.
35
+ * - `INVALID_ARGUMENT`: an argument was rejected before reaching Game Center.
36
+ * - `UNKNOWN`: anything else, e.g. the command is not allowed by the app's capabilities.
37
+ */
38
+ export type GameCenterErrorCode = 'UNSUPPORTED' | 'NOT_AUTHENTICATED' | 'NO_VIEW' | 'GAMEKIT' | 'INVALID_ARGUMENT' | 'UNKNOWN';
39
+ /** The error every function in this module rejects with. */
40
+ export declare class GameCenterError extends Error {
41
+ /** Machine-readable reason; see {@link GameCenterErrorCode}. */
42
+ readonly code: GameCenterErrorCode;
43
+ constructor(code: GameCenterErrorCode, message: string);
44
+ /** Normalizes whatever `invoke` rejected with (an object from Swift or Rust, or a string). */
45
+ static from(error: unknown): GameCenterError;
46
+ }
47
+ /**
48
+ * Signs the local player in to Game Center.
49
+ *
50
+ * Call it quietly (`interactive: false`) at app start: a player who is already signed in on the
51
+ * device is signed in without any UI. Call it with `interactive: true` when the player asks for
52
+ * Game Center (e.g. taps a leaderboard button) to show the sign-in sheet if one is needed.
53
+ *
54
+ * Declining or cancelling never rejects; it resolves `{ authenticated: false }`. GameKit only
55
+ * offers its sign-in sheet once per app launch, so after the player dismisses it, further calls
56
+ * resolve `{ authenticated: false }` until the app is restarted or the player signs in from the
57
+ * Settings app.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { authenticate } from 'tauri-plugin-gamecenter-api'
62
+ * const { authenticated } = await authenticate()
63
+ * ```
64
+ */
65
+ export declare function authenticate(options?: AuthenticateOptions): Promise<AuthState>;
66
+ /** Whether the local player is signed in, without starting a sign-in. */
67
+ export declare function isAuthenticated(): Promise<boolean>;
68
+ /**
69
+ * Submits a score to a leaderboard. Rejects with `NOT_AUTHENTICATED` when signed out and with
70
+ * `GAMEKIT` when, for example, the leaderboard ID does not exist in App Store Connect.
71
+ *
72
+ * @param leaderboardId The leaderboard ID as created in App Store Connect.
73
+ * @param score An integer score.
74
+ * @param context An optional integer stored with the score, opaque to Game Center.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * await submitScore('com.example.game.highscores', 1200)
79
+ * ```
80
+ */
81
+ export declare function submitScore(leaderboardId: string, score: number, context?: number): Promise<void>;
82
+ /**
83
+ * Reports progress towards an achievement. Rejects with `NOT_AUTHENTICATED` when signed out and
84
+ * with `GAMEKIT` when, for example, the achievement ID does not exist in App Store Connect.
85
+ *
86
+ * @param achievementId The achievement ID as created in App Store Connect.
87
+ * @param percent Progress from `0` to `100` (default `100`, i.e. unlocked). Clamped to that range.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * await reportAchievement('first_win')
92
+ * await reportAchievement('play_100_games', 37, { showCompletionBanner: false })
93
+ * ```
94
+ */
95
+ export declare function reportAchievement(achievementId: string, percent?: number, options?: ReportAchievementOptions): Promise<void>;
96
+ /**
97
+ * Opens the Game Center dashboard (leaderboards, achievements, profile). Resolves once it is on
98
+ * screen. Rejects with `NOT_AUTHENTICATED` when signed out, so sign in interactively first:
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const { authenticated } = await authenticate({ interactive: true })
103
+ * if (authenticated) await showDashboard()
104
+ * ```
105
+ */
106
+ export declare function showDashboard(): Promise<void>;
@@ -0,0 +1,137 @@
1
+ import { invoke } from '@tauri-apps/api/core';
2
+
3
+ /**
4
+ * Apple Game Center (GameKit) for Tauri apps: sign-in, leaderboard scores, achievements and the
5
+ * Game Center dashboard.
6
+ *
7
+ * Game Center only exists on iOS. On every other platform each function rejects with a
8
+ * {@link GameCenterError} whose `code` is `"UNSUPPORTED"`.
9
+ *
10
+ * @module
11
+ */
12
+ const KNOWN_CODES = [
13
+ 'UNSUPPORTED',
14
+ 'NOT_AUTHENTICATED',
15
+ 'NO_VIEW',
16
+ 'GAMEKIT',
17
+ 'INVALID_ARGUMENT'
18
+ ];
19
+ /** The error every function in this module rejects with. */
20
+ class GameCenterError extends Error {
21
+ constructor(code, message) {
22
+ super(message);
23
+ this.name = 'GameCenterError';
24
+ this.code = code;
25
+ }
26
+ /** Normalizes whatever `invoke` rejected with (an object from Swift or Rust, or a string). */
27
+ static from(error) {
28
+ if (error instanceof GameCenterError)
29
+ return error;
30
+ if (typeof error === 'object' && error !== null) {
31
+ const { code, message } = error;
32
+ const known = KNOWN_CODES.find((value) => value === code);
33
+ const text = typeof message === 'string' ? message : String(code ?? 'Game Center call failed');
34
+ return new GameCenterError(known ?? 'UNKNOWN', text);
35
+ }
36
+ const text = typeof error === 'string' ? error : 'Game Center call failed';
37
+ return new GameCenterError('UNKNOWN', text);
38
+ }
39
+ }
40
+ async function call(command, args) {
41
+ try {
42
+ return await invoke(`plugin:gamecenter|${command}`, args);
43
+ }
44
+ catch (error) {
45
+ throw GameCenterError.from(error);
46
+ }
47
+ }
48
+ function invalid(message) {
49
+ return new GameCenterError('INVALID_ARGUMENT', message);
50
+ }
51
+ /**
52
+ * Signs the local player in to Game Center.
53
+ *
54
+ * Call it quietly (`interactive: false`) at app start: a player who is already signed in on the
55
+ * device is signed in without any UI. Call it with `interactive: true` when the player asks for
56
+ * Game Center (e.g. taps a leaderboard button) to show the sign-in sheet if one is needed.
57
+ *
58
+ * Declining or cancelling never rejects; it resolves `{ authenticated: false }`. GameKit only
59
+ * offers its sign-in sheet once per app launch, so after the player dismisses it, further calls
60
+ * resolve `{ authenticated: false }` until the app is restarted or the player signs in from the
61
+ * Settings app.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { authenticate } from 'tauri-plugin-gamecenter-api'
66
+ * const { authenticated } = await authenticate()
67
+ * ```
68
+ */
69
+ async function authenticate(options = {}) {
70
+ return await call('authenticate', { interactive: options.interactive ?? false });
71
+ }
72
+ /** Whether the local player is signed in, without starting a sign-in. */
73
+ async function isAuthenticated() {
74
+ const state = await call('is_authenticated');
75
+ return state.authenticated;
76
+ }
77
+ /**
78
+ * Submits a score to a leaderboard. Rejects with `NOT_AUTHENTICATED` when signed out and with
79
+ * `GAMEKIT` when, for example, the leaderboard ID does not exist in App Store Connect.
80
+ *
81
+ * @param leaderboardId The leaderboard ID as created in App Store Connect.
82
+ * @param score An integer score.
83
+ * @param context An optional integer stored with the score, opaque to Game Center.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * await submitScore('com.example.game.highscores', 1200)
88
+ * ```
89
+ */
90
+ async function submitScore(leaderboardId, score, context = 0) {
91
+ if (!leaderboardId)
92
+ throw invalid('leaderboardId must not be empty');
93
+ if (!Number.isSafeInteger(score))
94
+ throw invalid('score must be an integer');
95
+ if (!Number.isSafeInteger(context))
96
+ throw invalid('context must be an integer');
97
+ await call('submit_score', { leaderboardId, score, context });
98
+ }
99
+ /**
100
+ * Reports progress towards an achievement. Rejects with `NOT_AUTHENTICATED` when signed out and
101
+ * with `GAMEKIT` when, for example, the achievement ID does not exist in App Store Connect.
102
+ *
103
+ * @param achievementId The achievement ID as created in App Store Connect.
104
+ * @param percent Progress from `0` to `100` (default `100`, i.e. unlocked). Clamped to that range.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * await reportAchievement('first_win')
109
+ * await reportAchievement('play_100_games', 37, { showCompletionBanner: false })
110
+ * ```
111
+ */
112
+ async function reportAchievement(achievementId, percent = 100, options = {}) {
113
+ if (!achievementId)
114
+ throw invalid('achievementId must not be empty');
115
+ if (!Number.isFinite(percent))
116
+ throw invalid('percent must be a finite number');
117
+ await call('report_achievement', {
118
+ achievementId,
119
+ percent: Math.min(100, Math.max(0, percent)),
120
+ showCompletionBanner: options.showCompletionBanner ?? true
121
+ });
122
+ }
123
+ /**
124
+ * Opens the Game Center dashboard (leaderboards, achievements, profile). Resolves once it is on
125
+ * screen. Rejects with `NOT_AUTHENTICATED` when signed out, so sign in interactively first:
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const { authenticated } = await authenticate({ interactive: true })
130
+ * if (authenticated) await showDashboard()
131
+ * ```
132
+ */
133
+ async function showDashboard() {
134
+ await call('show_dashboard');
135
+ }
136
+
137
+ export { GameCenterError, authenticate, isAuthenticated, reportAchievement, showDashboard, submitScore };
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "tauri-plugin-gamecenter-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "author": "Shubham",
5
+ "description": "JavaScript bindings for tauri-plugin-gamecenter: Apple Game Center (GameKit) sign-in, leaderboards, achievements and the dashboard on iOS.",
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/shbmx/tauri-plugin-gamecenter.git"
10
+ },
11
+ "homepage": "https://github.com/shbmx/tauri-plugin-gamecenter#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/shbmx/tauri-plugin-gamecenter/issues"
14
+ },
15
+ "keywords": [
16
+ "tauri",
17
+ "tauri-plugin",
18
+ "gamecenter",
19
+ "game-center",
20
+ "gamekit",
21
+ "ios",
22
+ "leaderboards",
23
+ "achievements"
24
+ ],
25
+ "type": "module",
26
+ "types": "./dist-js/index.d.ts",
27
+ "main": "./dist-js/index.cjs",
28
+ "module": "./dist-js/index.js",
29
+ "exports": {
30
+ "types": "./dist-js/index.d.ts",
31
+ "import": "./dist-js/index.js",
32
+ "require": "./dist-js/index.cjs"
33
+ },
34
+ "files": [
35
+ "dist-js",
36
+ "README.md",
37
+ "LICENSE-MIT",
38
+ "LICENSE-APACHE"
39
+ ],
40
+ "sideEffects": false,
41
+ "dependencies": {
42
+ "@tauri-apps/api": "^2.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@rollup/plugin-typescript": "^12.1.4",
46
+ "rollup": "^4.52.5",
47
+ "tslib": "^2.8.1",
48
+ "typescript": "^5.9.3"
49
+ },
50
+ "scripts": {
51
+ "build": "rollup -c",
52
+ "typecheck": "tsc"
53
+ }
6
54
  }