Skip to content

Commit

Permalink
feat: add soft scan trigger (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
flashmatt authored Nov 24, 2021
1 parent 5d8b672 commit a0961e8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 1 deletion.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ npx cap sync
* [`disable()`](#disable)
* [`enableScanner()`](#enablescanner)
* [`disableScanner()`](#disablescanner)
* [`startScanning()`](#startscanning)
* [`stopScanning()`](#stopscanning)
* [`addListener('scan', ...)`](#addlistenerscan-)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
Expand Down Expand Up @@ -90,6 +92,36 @@ Broadcasts intent action with `.SCANNER_INPUT_PLUGIN` extra set to `DISABLE_PLUG
--------------------


### startScanning()

```typescript
startScanning() => Promise<void>
```

Starts software scanning trigger

Broadcasts intent action with `.SOFT_SCAN_TRIGGER` extra set to `START_SCANNING`

**Since:** 0.1.2

--------------------


### stopScanning()

```typescript
stopScanning() => Promise<void>
```

Stops software scanning trigger

Broadcasts intent action with `.SOFT_SCAN_TRIGGER` extra set to `STOP_SCANNING`

**Since:** 0.1.2

--------------------


### addListener('scan', ...)

```typescript
Expand Down
16 changes: 16 additions & 0 deletions android/src/main/java/com/jkbz/capacitor/datawedge/DataWedge.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,21 @@ public Intent disableScanner() {

return intent;
}

public Intent startScanning() {
Intent intent = new Intent();
intent.setAction(DATAWEDGE_PACKAGE + ".ACTION");
intent.putExtra("com.symbol.datawedge.api.SOFT_SCAN_TRIGGER", "START_SCANNING");

return intent;
}

public Intent stopScanning() {
Intent intent = new Intent();
intent.setAction(DATAWEDGE_PACKAGE + ".ACTION");
intent.putExtra("com.symbol.datawedge.api.SOFT_SCAN_TRIGGER", "STOP_SCANNING");

return intent;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ public void disableScanner(PluginCall call) {
}
}

@PluginMethod
public void startScanning(PluginCall call) {
Intent intent = implementation.startScanning();

try {
broadcast(intent);
} catch (ActivityNotFoundException e) {
call.reject("DataWedge is not installed or not running");
}
}

@PluginMethod
public void stopScanning(PluginCall call) {
Intent intent = implementation.stopScanning();

try {
broadcast(intent);
} catch (ActivityNotFoundException e) {
call.reject("DataWedge is not installed or not running");
}
}

@PluginMethod
@Override
public void addListener(PluginCall call) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-datawedge",
"version": "0.1.1",
"version": "0.1.2",
"description": "DataWedge plugin for capacitor",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down
18 changes: 18 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ export interface DataWedgePlugin {
*/
disableScanner(): Promise<void>;

/**
* Starts software scanning trigger
*
* Broadcasts intent action with `.SOFT_SCAN_TRIGGER` extra set to `START_SCANNING`
*
* @since 0.1.2
*/
startScanning(): Promise<void>;

/**
* Stops software scanning trigger
*
* Broadcasts intent action with `.SOFT_SCAN_TRIGGER` extra set to `STOP_SCANNING`
*
* @since 0.1.2
*/
stopScanning(): Promise<void>;

/**
* Listen for successful barcode readings
*
Expand Down
8 changes: 8 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ export class DataWedgeWeb extends WebPlugin implements DataWedgePlugin {
async disableScanner(): Promise<void> {
throw 'DataWedge is not supported on web';
}

async startScanning(): Promise<void> {
throw 'DataWedge is not supported on web';
}

async stopScanning(): Promise<void> {
throw 'DataWedge is not supported on web';
}
}

0 comments on commit a0961e8

Please sign in to comment.