Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how external QR code scanning works #19743

Merged
merged 5 commits into from
Feb 14, 2024
Merged
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
85 changes: 57 additions & 28 deletions src/external_app/external_messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,22 @@ interface EMOutgoingMessageConfigGet extends EMMessage {
type: "config/get";
}

interface EMOutgoingMessageScanQRCode extends EMMessage {
type: "qr_code/scan";
interface EMOutgoingMessageBarCodeScan extends EMMessage {
type: "bar_code/scan";
title: string;
description: string;
alternative_option_label?: string;
}

interface EMOutgoingMessageBarCodeClose extends EMMessage {
type: "bar_code/close";
}

interface EMOutgoingMessageBarCodeNotify extends EMMessage {
type: "bar_code/notify";
message: string;
}

interface EMOutgoingMessageMatterCommission extends EMMessage {
type: "matter/commission";
}
Expand All @@ -55,13 +64,6 @@ type EMOutgoingMessageWithAnswer = {
request: EMOutgoingMessageConfigGet;
response: ExternalConfig;
};
"qr_code/scan": {
request: EMOutgoingMessageScanQRCode;
response:
| EMIncomingMessageQRCodeResponseCanceled
| EMIncomingMessageQRCodeResponseAlternativeOptions
| EMIncomingMessageQRCodeResponseScanResult;
};
};

interface EMOutgoingMessageExoplayerPlayHLS extends EMMessage {
Expand Down Expand Up @@ -124,20 +126,23 @@ interface EMOutgoingMessageAssistShow extends EMMessage {
}

type EMOutgoingMessageWithoutAnswer =
| EMOutgoingMessageHaptic
| EMOutgoingMessageConnectionStatus
| EMMessageResultError
| EMMessageResultSuccess
| EMOutgoingMessageAppConfiguration
| EMOutgoingMessageTagWrite
| EMOutgoingMessageSidebarShow
| EMOutgoingMessageAssistShow
| EMOutgoingMessageBarCodeClose
| EMOutgoingMessageBarCodeNotify
| EMOutgoingMessageBarCodeScan
| EMOutgoingMessageConnectionStatus
| EMOutgoingMessageExoplayerPlayHLS
| EMOutgoingMessageExoplayerResize
| EMOutgoingMessageExoplayerStop
| EMOutgoingMessageThemeUpdate
| EMMessageResultSuccess
| EMMessageResultError
| EMOutgoingMessageHaptic
| EMOutgoingMessageImportThreadCredentials
| EMOutgoingMessageMatterCommission
| EMOutgoingMessageImportThreadCredentials;
| EMOutgoingMessageSidebarShow
| EMOutgoingMessageTagWrite
| EMOutgoingMessageThemeUpdate;

interface EMIncomingMessageRestart {
id: number;
Expand Down Expand Up @@ -172,25 +177,49 @@ interface EMIncomingMessageShowAutomationEditor {
};
}

export interface EMIncomingMessageQRCodeResponseCanceled {
action: "canceled";
}

export interface EMIncomingMessageQRCodeResponseAlternativeOptions {
action: "alternative_options";
export interface EMIncomingMessageBarCodeScanResult {
id: number;
type: "command";
command: "bar_code/scan_result";
payload: {
// A string decoded from the barcode data.
rawValue: string;
// https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API#supported_barcode_formats
format:
| "aztec"
| "code_128"
| "code_39"
| "code_93"
| "codabar"
| "data_matrix"
| "ean_13"
| "ean_8"
| "itf"
| "pdf417"
| "qr_code"
| "upc_a"
| "upc_e"
| "unknown";
};
}

export interface EMIncomingMessageQRCodeResponseScanResult {
action: "scan_result";
result: string;
export interface EMIncomingMessageBarCodeScanAborted {
id: number;
type: "command";
command: "bar_code/aborted";
payload: {
reason: "canceled" | "alternative_options";
};
}

export type EMIncomingMessageCommands =
| EMIncomingMessageRestart
| EMIncomingMessageShowNotifications
| EMIncomingMessageToggleSidebar
| EMIncomingMessageShowSidebar
| EMIncomingMessageShowAutomationEditor;
| EMIncomingMessageShowAutomationEditor
| EMIncomingMessageBarCodeScanResult
| EMIncomingMessageBarCodeScanAborted;

type EMIncomingMessage =
| EMMessageResultSuccess
Expand All @@ -207,7 +236,7 @@ export interface ExternalConfig {
canCommissionMatter: boolean;
canImportThreadCredentials: boolean;
hasAssist: boolean;
hasQRScanner: number;
hasBarCodeScanner: number;
}

export class ExternalMessaging {
Expand Down
Loading