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

Feature disable upload feature on capture cam #3216

Merged
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
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true,
"source.organizeImports": true
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit",
"source.organizeImports": "explicit"
},
"typescript.preferences.importModuleSpecifier": "relative"
}
1 change: 0 additions & 1 deletion android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies {
implementation project(':capacitor-share')
implementation project(':capacitor-splash-screen')
implementation project(':capacitor-storage')
implementation project(':capawesome-capacitor-file-picker')
implementation project(':numbersprotocol-preview-camera')
implementation project(':numbersprotocol-preview-memory')
implementation project(':numbersprotocol-preview-video')
Expand Down
4 changes: 0 additions & 4 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
"pkg": "@capacitor/storage",
"classpath": "com.capacitorjs.plugins.storage.StoragePlugin"
},
{
"pkg": "@capawesome/capacitor-file-picker",
"classpath": "io.capawesome.capacitorjs.plugins.filepicker.FilePickerPlugin"
},
{
"pkg": "@numbersprotocol/preview-camera",
"classpath": "io.numbersprotocol.capturelite.plugins.previewcamera.PreviewCameraPlugin"
Expand Down
3 changes: 0 additions & 3 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capa
include ':capacitor-storage'
project(':capacitor-storage').projectDir = new File('../node_modules/@capacitor/storage/android')

include ':capawesome-capacitor-file-picker'
project(':capawesome-capacitor-file-picker').projectDir = new File('../node_modules/@capawesome/capacitor-file-picker/android')

include ':numbersprotocol-preview-camera'
project(':numbersprotocol-preview-camera').projectDir = new File('../node_modules/@numbersprotocol/preview-camera/android')

Expand Down
1 change: 0 additions & 1 deletion ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def capacitor_pods
pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage'
pod 'CapawesomeCapacitorFilePicker', :path => '../../node_modules/@capawesome/capacitor-file-picker'
pod 'NumbersprotocolPreviewCamera', :path => '../../node_modules/@numbersprotocol/preview-camera'
pod 'NumbersprotocolPreviewMemory', :path => '../../node_modules/@numbersprotocol/preview-memory'
pod 'NumbersprotocolPreviewVideo', :path => '../../node_modules/@numbersprotocol/preview-video'
Expand Down
8 changes: 1 addition & 7 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ PODS:
- Capacitor
- CapacitorStorage (1.2.4):
- Capacitor
- CapawesomeCapacitorFilePicker (0.6.3):
- Capacitor
- CordovaPlugins (5.0.5):
- CapacitorCordova
- Firebase/CoreOnly (10.14.0):
Expand Down Expand Up @@ -134,7 +132,6 @@ DEPENDENCIES:
- "CapacitorShare (from `../../node_modules/@capacitor/share`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"
- "CapacitorStorage (from `../../node_modules/@capacitor/storage`)"
- "CapawesomeCapacitorFilePicker (from `../../node_modules/@capawesome/capacitor-file-picker`)"
- CordovaPlugins (from `../capacitor-cordova-ios-plugins`)
- Firebase/Messaging
- FirebaseCore
Expand Down Expand Up @@ -201,8 +198,6 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/splash-screen"
CapacitorStorage:
:path: "../../node_modules/@capacitor/storage"
CapawesomeCapacitorFilePicker:
:path: "../../node_modules/@capawesome/capacitor-file-picker"
CordovaPlugins:
:path: "../capacitor-cordova-ios-plugins"
NumbersprotocolPreviewCamera:
Expand Down Expand Up @@ -236,7 +231,6 @@ SPEC CHECKSUMS:
CapacitorShare: 427bba238a1e3f116b2b349019aec6ea7f42cebd
CapacitorSplashScreen: 93a389d4f7673c08214ae25bb6f21d867d5305c5
CapacitorStorage: 8ec2cf8fec179d829288b16c6fba6c3c43d2bdc9
CapawesomeCapacitorFilePicker: f354c9ec6e4722908876032939a85ffb94642630
CordovaPlugins: c905b3b4dfc87d2a11bdbdaf396289c4a22c39dd
Firebase: 6c1bf3f534bc422d52af2e41fe0d50bf08b6b773
FirebaseCore: 6fc17ac9f03509d51c131298aacb3ee5698b4f02
Expand All @@ -252,6 +246,6 @@ SPEC CHECKSUMS:
NumbersprotocolPreviewVideo: 2cfa3fa666c83850903a220d74dc855ac5b6a520
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4

PODFILE CHECKSUM: 24ca1bcaa3932b2d964431fb23583535c4454ed9
PODFILE CHECKSUM: bc27c544feb7d8f533aeb72cadce60b633a90ab4

COCOAPODS: 1.14.3
24 changes: 0 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"@capacitor/share": "^5.0.4",
"@capacitor/splash-screen": "^5.0.4",
"@capacitor/storage": "^1.2.4",
"@capawesome/capacitor-file-picker": "^0.6.3",
"@ionic/angular": "^6.2.5",
"@ionic/core": "^6.2.5",
"@ionic/pwa-elements": "^3.0.2",
Expand Down
4 changes: 3 additions & 1 deletion src/app/features/home/custom-camera/custom-camera.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
</div>
</div>
<div class="footer-camera-buttons">
<mat-icon (click)="pickMedia()"> imagesmode </mat-icon>
<mat-icon (click)="redirectToCaptureDashboard()">
imagesmode
</mat-icon>

<circle-progress
(click)="onPress()"
Expand Down
93 changes: 11 additions & 82 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Router } from '@angular/router';
import { CameraSource } from '@capacitor/camera';
import { Capacitor } from '@capacitor/core';
import { Directory, Filesystem } from '@capacitor/filesystem';
import { FilePicker, PickedFile } from '@capawesome/capacitor-file-picker';
import { NavController, Platform } from '@ionic/angular';
import { AlertController, NavController, Platform } from '@ionic/angular';
import { TranslocoService } from '@ngneat/transloco';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import {
Expand Down Expand Up @@ -39,10 +38,7 @@ import { ConfirmAlert } from '../../../shared/confirm-alert/confirm-alert.servic
import { ErrorService } from '../../../shared/error/error.service';
import { UserGuideService } from '../../../shared/user-guide/user-guide.service';
import { GoProBluetoothService } from '../../settings/go-pro/services/go-pro-bluetooth.service';
import {
MAX_RECORD_TIME_IN_MILLISECONDS,
toCustomCameraMimeType,
} from './custom-camera';
import { MAX_RECORD_TIME_IN_MILLISECONDS } from './custom-camera';
import {
CustomCameraService,
SaveToCameraRollDecision,
Expand Down Expand Up @@ -115,6 +111,7 @@ export class CustomCameraPage implements OnInit, OnDestroy {
private readonly errorService: ErrorService,
private readonly userGuideService: UserGuideService,
private readonly confirmAlert: ConfirmAlert,
private readonly alertController: AlertController,
private readonly translocoService: TranslocoService,
private readonly captureTabService: CaptureTabService,
private readonly ref: ChangeDetectorRef,
Expand Down Expand Up @@ -286,82 +283,14 @@ export class CustomCameraPage implements OnInit, OnDestroy {
this.customCameraService.stopPreviewCamera();
}

/**
* Handles media picking, prepares it for publishing, and deals with possible errors.
*/
async pickMedia() {
try {
const filePickerResult = await FilePicker.pickMedia();
const file = filePickerResult.files[0];

const filePath = await this.convertFilePath(file);

if (filePath === undefined) return;

const result: CaptureSuccessResult = {
mimeType: toCustomCameraMimeType(file.mimeType),
name: file.name,
path: filePath,
size: file.size,
};

this.prepareForPublishing(result, CameraSource.Photos);
} catch (error: any) {
// User didn't pick a file, in this case, we do not bother the user by showing any alerts.
if (
!(error instanceof Error && error.message === 'pickFiles canceled.')
) {
/**
* Error handling: In case the media picking or prepareForPublishing fails,
* an error should be reported to the crash reporting system (currently not in place).
* TODO: Implement error reporting to the crash reporting system when available.
*/
// Error not reported due to the absence of a crash reporting system.
this.errorService.toastError$(error.message ?? error).subscribe();
}
}
}

private async convertFilePath(file: PickedFile): Promise<string | undefined> {
/**
* WORKAROUND: https://github.com/numbersprotocol/capture-lite/issues/2857
* Convert Android picked image file path to "file:///" format for editing and saving.
*
* Here is the explanation of the WORKAROUND:
* We have a CapacitorJS project where we encounter an issue with picking images
* from the gallery on Android. When users pick media from the gallery on iOS, the
* file path is in the format "file:///", while on Android it is in the format
* "content:///". This discrepancy in file paths poses a challenge for us as we
* need to perform additional pre-publish editing, such as cropping and applying a
* grayscale filter, on the picked images. However, to save the edited image to the
* file system, we require the file path to be in the "file:///" format instead of
* "content:///".
*
* To address this issue, we have implemented a workaround that involves copying
* the picked image to the file system, ensuring that the file path is in the
* required "file:///" format. This workaround allows us to seamlessly perform the
* necessary editing operations on the image and successfully save it to the file
* system.
*
* Note: This workaround is specifically designed to handle picked images from the
* gallery on Android and does not impact the functionality on iOS.
*
*/

if (file.path === undefined) return undefined;

if (this.platform.is('android') && file.mimeType.startsWith('image/')) {
const readFileResult = await Filesystem.readFile({ path: file.path });
const writeFileresult = await Filesystem.writeFile({
data: readFileResult.data,
path: `${file.name}`,
directory: Directory.Cache,
recursive: true,
});
return writeFileresult.uri;
}

return file.path;
async redirectToCaptureDashboard() {
const alert = await this.alertController.create({
message: this.translocoService.translate(
'customCamera.redirectToCaptureDashboard'
),
buttons: [this.translocoService.translate('ok')],
});
await alert.present();
}

async flipCamera() {
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@
"duplicateAsset": "The asset you are trying to upload already exists on the blockchain. Please try again or contact support.",
"canNotStartCamera": "Sorry, we encountered an issue while starting the camera. We apologize for the inconvenience. If the problem persists, please report the issue to our developers through the 'Contact Developers' section on the app's support page. Your feedback will help us improve the app and resolve the issue faster. Thank you for your understanding and cooperation.",
"fileSizeExeedsLimit": "File size exceeds 25MB limit. Please select a smaller file and try again."
}
},
"redirectToCaptureDashboard": "Need to upload files? <br/> For a seamless upload experience, please visit <a href=\"https://dashboard.captureapp.xyz/\" target=\"_blank\">https://dashboard.captureapp.xyz</a>."
},
"wallets": {
"wallets": "Wallets",
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@
"duplicateAsset": "您嘗試上傳的資產已有上鏈紀錄,請重新嘗試,或聯繫開發團隊取得協助。",
"canNotStartCamera": "很抱歉,我們在啟動相機時遇到問題。對於造成的不便,我們深感抱歉。如果問題持續存在,請透過應用程式支援頁面的「聯絡開發人員」區域向我們的開發人員報告問題。您的反饋將有助於我們改善應用程式並更快地解決問題。感謝您的理解和配合。",
"fileSizeExeedsLimit": "檔案大小超過25MB的限制,請選擇較小的檔案並重試。"
}
},
"redirectToCaptureDashboard": "為提供更好的上傳體驗,建議使用 <a href=\"https://dashboard.captureapp.xyz/\" target=\"_blank\">https://dashboard.captureapp.xyz</a>。"
},
"wallets": {
"wallets": "錢包",
Expand Down
Loading