Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/NativeComponents/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\NativeComponents;

use Composer\InstalledVersions;
use Illuminate\Foundation\Application;
use Illuminate\View\View;
use Native\Mobile\Edge\NativeComponent;

Expand All @@ -12,16 +14,21 @@ public function navTitle(): string
return 'Super Stack';
}

public function openScannerBenchmark(): void
{
$this->navigate('/scanner-benchmark');
}

public function render(): View
{
return view('native.home', [
'app' => config('app.name'),
'packages' => [
'Laravel' => \Illuminate\Foundation\Application::VERSION,
'Filament' => \Composer\InstalledVersions::getPrettyVersion('filament/filament'),
'NativePHP Mobile' => \Composer\InstalledVersions::getPrettyVersion('nativephp/mobile'),
'Web UI' => \Composer\InstalledVersions::getPrettyVersion('nativephp/web-ui'),
'Laravel MCP' => \Composer\InstalledVersions::getPrettyVersion('laravel/mcp'),
'Laravel' => Application::VERSION,
'Filament' => InstalledVersions::getPrettyVersion('filament/filament'),
'NativePHP Mobile' => InstalledVersions::getPrettyVersion('nativephp/mobile'),
'Web UI' => InstalledVersions::getPrettyVersion('nativephp/web-ui'),
'Laravel MCP' => InstalledVersions::getPrettyVersion('laravel/mcp'),
],
]);
}
Expand Down
91 changes: 91 additions & 0 deletions app/NativeComponents/ScannerBenchmark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\NativeComponents;

use Illuminate\View\View;
use Native\Mobile\Attributes\OnNative;
use Native\Mobile\Edge\NativeComponent;
use Sandip\Scanner\Native\Events\Scanner\CodeScanned;
use Sandip\Scanner\Native\Facades\Scanner;

class ScannerBenchmark extends NativeComponent
{
public int $totalScans = 0;

public int $uniqueScans = 0;

public ?string $lastValue = null;

public ?string $lastFormat = null;

public ?float $lastBridgeToPhpMs = null;

public ?float $lastPhpMs = null;

/** @var array<string, true> */
protected array $seen = [];

protected ?float $scanRequestedAt = null;

public function navTitle(): string
{
return 'Scanner benchmark';
}

public function startScanner(): void
{
$sessionId = 'benchmark-'.bin2hex(random_bytes(6));
$this->scanRequestedAt = microtime(true);

Scanner::scan()
->id($sessionId)
->prompt('Scan the benchmark code')
->continuous()
->scan();
}

#[OnNative(CodeScanned::class)]
public function codeScanned(CodeScanned $event): void
{
$phpStartedAt = microtime(true);
$this->totalScans++;
$this->lastValue = $event->data;
$this->lastFormat = $event->format;
$this->lastBridgeToPhpMs = $this->scanRequestedAt === null
? null
: round((microtime(true) - $this->scanRequestedAt) * 1000, 3);

if (! isset($this->seen[$event->data])) {
$this->seen[$event->data] = true;
$this->uniqueScans++;
}

$this->lastPhpMs = round((microtime(true) - $phpStartedAt) * 1000, 3);

logger()->info('scanner_benchmark.scan', [
'value_sha256' => hash('sha256', $event->data),
'format' => $event->format,
'total_scans' => $this->totalScans,
'unique_scans' => $this->uniqueScans,
'bridge_to_php_ms' => $this->lastBridgeToPhpMs,
'php_ms' => $this->lastPhpMs,
]);
}

public function reset(): void
{
$this->totalScans = 0;
$this->uniqueScans = 0;
$this->lastValue = null;
$this->lastFormat = null;
$this->lastBridgeToPhpMs = null;
$this->lastPhpMs = null;
$this->seen = [];
$this->scanRequestedAt = null;
}

public function render(): View
{
return view('native.scanner-benchmark');
}
}
10 changes: 6 additions & 4 deletions app/Providers/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Native\Mobile\UI\NativeUIServiceProvider;
use Sandip\Scanner\Native\ScannerServiceProvider;

class NativeServiceProvider extends ServiceProvider
{
Expand All @@ -29,13 +31,13 @@ public function boot(): void
* This is a security measure to prevent transitive dependencies from
* automatically registering plugins without your explicit consent.
*
* @return array<int, class-string<\Illuminate\Support\ServiceProvider>>
* @return array<int, class-string<ServiceProvider>>
*/
public function plugins(): array
{
return [
\Native\Mobile\UI\NativeUIServiceProvider::class,

NativeUIServiceProvider::class,
ScannerServiceProvider::class,
];
}
}
}
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"laravel/mcp": "^0.9.5",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^3.0",
"nativephp/mobile": "^4.4",
"nativephp/mobile": "4.4.0",
"nativephp/mobile-ui": "^0.4.0",
"nativephp/web-ui": "^0.0.1@alpha"
"nativephp/web-ui": "^0.0.1@alpha",
"sghimire/mobile-scanner": "1.0.3"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand Down Expand Up @@ -86,6 +87,15 @@
"extra": {
"laravel": []
},
"repositories": [
{
"type": "path",
"url": "packages/mobile-scanner",
"options": {
"symlink": false
}
}
],
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
Expand Down
Loading