-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds support for the [CashDrawer](https://learn.microsoft.com/en-us/uwp/api/windows.devices.pointofservice.cashdrawer?view=winrt-22621) class in the [Windows.Devices.PointOfService](https://learn.microsoft.com/en-us/uwp/api/windows.devices.pointofservice?view=winrt-22621) namespace. It also adds a hook and an example to the example app.
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; | ||
import { TurboModuleRegistry } from 'react-native'; | ||
|
||
export interface CashDrawerSpec extends TurboModule { | ||
/** | ||
* Returns the first available cash drawer. | ||
* @throws {Error} A device is not found. | ||
* @see https://learn.microsoft.com/en-us/uwp/api/windows.devices.pointofservice.cashdrawer.getdefaultasync?view=winrt-22621#windows-devices-pointofservice-cashdrawer-getdefaultasync | ||
*/ | ||
getDefaultAsync(): Promise<ReactCashDrawer>; | ||
} | ||
|
||
export default TurboModuleRegistry.get<CashDrawerSpec>( | ||
'CashDrawer' | ||
) as CashDrawerSpec | null; | ||
|
||
/** @link windows/ReactNativePosTools/NativeCashDrawer.cs */ | ||
export interface ReactCashDrawer { | ||
/** @see https://learn.microsoft.com/en-us/uwp/api/windows.devices.pointofservice.cashdrawer.deviceid?view=winrt-22621 */ | ||
DeviceId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.ReactNative.Managed; | ||
|
||
using Windows.Devices.PointOfService; | ||
|
||
namespace ReactNativePosTools | ||
{ | ||
// This is the structure that will be returned to the JavaScript side | ||
// src/NativeCashDrawer.ts | ||
|
||
struct ReactCashDrawer | ||
{ | ||
public string DeviceId { get; set; } | ||
|
||
public ReactCashDrawer(string deviceId) | ||
{ | ||
DeviceId = deviceId; | ||
} | ||
}; | ||
|
||
[ReactModule("CashDrawer")] | ||
internal class NativeCashDrawer | ||
{ | ||
|
||
private CashDrawer drawer = null; | ||
|
||
[ReactMethod("getDefaultAsync")] | ||
public async void GetDefaultAsync(ReactPromise<ReactCashDrawer> result) | ||
{ | ||
try | ||
{ | ||
drawer = await CashDrawer.GetDefaultAsync(); | ||
if (drawer == null) | ||
{ | ||
result.Reject(new ReactError { Message = "Cash Drawer was not found" }); | ||
} | ||
else | ||
{ | ||
result.Resolve(new ReactCashDrawer { DeviceId = drawer.DeviceId }); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
result.Reject(new ReactError { Message = ex.Message }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters