-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOBILE-3947 native: Fix chooser plugin
- Loading branch information
1 parent
d2fa4e6
commit c2b86a1
Showing
8 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,47 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { Injectable } from '@angular/core'; | ||
|
||
/** | ||
* Chooser plugin wrapper. | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class Chooser { | ||
|
||
/** | ||
* Displays native prompt for user to select a file. | ||
* | ||
* @param accept Optional MIME type filter (e.g. 'image/gif,video/*'). | ||
* @returns Selected file's raw binary data, base64-encoded data: URI, MIME type, display name, and original URI. | ||
* If user cancels, promise will be resolved as undefined. | ||
* If error occurs, promise will be rejected. | ||
*/ | ||
getFile(accept?: string): Promise<IChooserResult | undefined> { | ||
return cordova.chooser.getFile(accept); | ||
} | ||
|
||
/** | ||
* Displays native prompt for user to select a file. | ||
* | ||
* @param accept Optional MIME type filter (e.g. 'image/gif,video/*'). | ||
* @returns Selected file's MIME type, display name, and original URI. | ||
* If user cancels, promise will be resolved as undefined. | ||
* If error occurs, promise will be rejected. | ||
*/ | ||
getFileMetadata(accept?: string): Promise<IChooserResult | undefined> { | ||
return cordova.chooser.getFileMetadata(accept); | ||
} | ||
|
||
} |
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,18 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { makeSingleton } from '@singletons'; | ||
import { Chooser as ChooserService } from './chooser'; | ||
|
||
export const Chooser = makeSingleton(ChooserService); |
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,40 @@ | ||
// (C) Copyright 2015 Moodle Pty Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* Types for chooser cordova plugin. | ||
* | ||
* @see https://github.com/cyph/cordova-plugin-chooser | ||
*/ | ||
|
||
interface IChooserResult { | ||
data?: Uint8Array; | ||
dataURI?: string; | ||
mediaType: string; | ||
name: string; | ||
uri: string; | ||
} | ||
|
||
interface Cordova { | ||
|
||
chooser: { | ||
getFile(accept?: string): Promise<IChooserResult | undefined>; | ||
getFileMetadata(accept?: string): Promise<IChooserResult | undefined>; | ||
}; | ||
|
||
} | ||
|
||
declare module 'cordova-plugin-chooser' { | ||
export type ChooserResult = IChooserResult; | ||
} |