MOBILE-4616 chore: Move copyClipboard to CoreText
This commit is contained in:
		
							parent
							
								
									caa100979a
								
							
						
					
					
						commit
						7068db3f62
					
				| @ -45,6 +45,7 @@ import { ActivatedRoute } from '@angular/router'; | |||||||
| import { CoreConstants } from '@/core/constants'; | import { CoreConstants } from '@/core/constants'; | ||||||
| import { CoreDom } from '@singletons/dom'; | import { CoreDom } from '@singletons/dom'; | ||||||
| import { CoreKeyboard } from '@singletons/keyboard'; | import { CoreKeyboard } from '@singletons/keyboard'; | ||||||
|  | import { CoreText } from '@singletons/text'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Page that displays a message discussion page. |  * Page that displays a message discussion page. | ||||||
| @ -924,7 +925,7 @@ export class AddonMessagesDiscussionPage implements OnInit, OnDestroy, AfterView | |||||||
|      */ |      */ | ||||||
|     copyMessage(message: AddonMessagesConversationMessageFormatted): void { |     copyMessage(message: AddonMessagesConversationMessageFormatted): void { | ||||||
|         const text = 'smallmessage' in message ? message.smallmessage || message.text || '' : message.text || ''; |         const text = 'smallmessage' in message ? message.smallmessage || message.text || '' : message.text || ''; | ||||||
|         CoreUtils.copyToClipboard(CoreTextUtils.decodeHTMLEntities(text)); |         CoreText.copyToClipboard(CoreTextUtils.decodeHTMLEntities(text)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ import { ContextLevel } from '@/core/constants'; | |||||||
| import { Component, EventEmitter, HostBinding, Input, OnInit, Output } from '@angular/core'; | import { Component, EventEmitter, HostBinding, Input, OnInit, Output } from '@angular/core'; | ||||||
| import { CoreAnimations } from '@components/animations'; | import { CoreAnimations } from '@components/animations'; | ||||||
| import { CoreSites } from '@services/sites'; | import { CoreSites } from '@services/sites'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreText } from '@singletons/text'; | ||||||
| import { CoreTextUtils } from '@services/utils/text'; | import { CoreTextUtils } from '@services/utils/text'; | ||||||
| import { CoreUserWithAvatar } from '@components/user-avatar/user-avatar'; | import { CoreUserWithAvatar } from '@components/user-avatar/user-avatar'; | ||||||
| 
 | 
 | ||||||
| @ -102,7 +102,7 @@ export class CoreMessageComponent implements OnInit { | |||||||
|      * Copy message to clipboard. |      * Copy message to clipboard. | ||||||
|      */ |      */ | ||||||
|     copyMessage(): void { |     copyMessage(): void { | ||||||
|         CoreUtils.copyToClipboard(CoreTextUtils.decodeHTMLEntities(this.text)); |         CoreText.copyToClipboard(CoreTextUtils.decodeHTMLEntities(this.text)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ import { CoreNavigator } from '@services/navigator'; | |||||||
| import { CorePlatform } from '@services/platform'; | import { CorePlatform } from '@services/platform'; | ||||||
| import { CoreSites } from '@services/sites'; | import { CoreSites } from '@services/sites'; | ||||||
| import { CoreDomUtils, ToastDuration } from '@services/utils/dom'; | import { CoreDomUtils, ToastDuration } from '@services/utils/dom'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreText } from '@singletons/text'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Page that displays the developer options. |  * Page that displays the developer options. | ||||||
| @ -165,7 +165,7 @@ export class CoreSettingsDevPage implements OnInit { | |||||||
|      * Copies site info. |      * Copies site info. | ||||||
|      */ |      */ | ||||||
|     copyInfo(): void { |     copyInfo(): void { | ||||||
|         CoreUtils.copyToClipboard(JSON.stringify({ disabledFeatures: this.disabledFeatures, sitePlugins: this.sitePlugins })); |         CoreText.copyToClipboard(JSON.stringify({ disabledFeatures: this.disabledFeatures, sitePlugins: this.sitePlugins })); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ import { CorePlatform } from '@services/platform'; | |||||||
| import { CoreNetwork } from '@services/network'; | import { CoreNetwork } from '@services/network'; | ||||||
| import { CoreLoginHelper } from '@features/login/services/login-helper'; | import { CoreLoginHelper } from '@features/login/services/login-helper'; | ||||||
| import { CoreSitesFactory } from '@services/sites-factory'; | import { CoreSitesFactory } from '@services/sites-factory'; | ||||||
|  | import { CoreText } from '@singletons/text'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Device Info to be shown and copied to clipboard. |  * Device Info to be shown and copied to clipboard. | ||||||
| @ -226,7 +227,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { | |||||||
|      * Copies device info into the clipboard. |      * Copies device info into the clipboard. | ||||||
|      */ |      */ | ||||||
|     copyInfo(): void { |     copyInfo(): void { | ||||||
|         CoreUtils.copyToClipboard(JSON.stringify(this.deviceInfo)); |         CoreText.copyToClipboard(JSON.stringify(this.deviceInfo)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -238,7 +239,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { | |||||||
|         const el = <Element>e.target; |         const el = <Element>e.target; | ||||||
|         const text = el?.closest('ion-item')?.textContent?.trim(); |         const text = el?.closest('ion-item')?.textContent?.trim(); | ||||||
| 
 | 
 | ||||||
|         text && CoreUtils.copyToClipboard(text); |         text && CoreText.copyToClipboard(text); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ | |||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreText } from '@singletons/text'; | ||||||
| import { CoreErrorLogs, CoreSettingsErrorLog } from '@singletons/error-logs'; | import { CoreErrorLogs, CoreSettingsErrorLog } from '@singletons/error-logs'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -39,9 +39,9 @@ export class CoreSettingsErrorLogPage implements OnInit { | |||||||
|      */ |      */ | ||||||
|     async copyError(error?: CoreSettingsErrorLog): Promise<void> { |     async copyError(error?: CoreSettingsErrorLog): Promise<void> { | ||||||
|         if (error) { |         if (error) { | ||||||
|             await CoreUtils.copyToClipboard(JSON.stringify(error)); |             await CoreText.copyToClipboard(JSON.stringify(error)); | ||||||
|         } else { |         } else { | ||||||
|             await CoreUtils.copyToClipboard(JSON.stringify({ errors: this.errorLogs })); |             await CoreText.copyToClipboard(JSON.stringify({ errors: this.errorLogs })); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -17,7 +17,7 @@ import { CoreSharedModule } from '@/core/shared.module'; | |||||||
| import { Component, Input } from '@angular/core'; | import { Component, Input } from '@angular/core'; | ||||||
| import { CoreFileEntry } from '@services/file-helper'; | import { CoreFileEntry } from '@services/file-helper'; | ||||||
| 
 | 
 | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreText } from '@singletons/text'; | ||||||
| import { ModalController } from '@singletons'; | import { ModalController } from '@singletons'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -56,7 +56,7 @@ export class CoreViewerTextComponent { | |||||||
|      * Copy the text to clipboard. |      * Copy the text to clipboard. | ||||||
|      */ |      */ | ||||||
|     copyText(): void { |     copyText(): void { | ||||||
|         CoreUtils.copyToClipboard(this.content || ''); |         CoreText.copyToClipboard(this.content || ''); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ import { CoreWS } from '@services/ws'; | |||||||
| import { CoreDomUtils } from '@services/utils/dom'; | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
| import { CoreMimetypeUtils } from '@services/utils/mimetype'; | import { CoreMimetypeUtils } from '@services/utils/mimetype'; | ||||||
| import { CoreTextUtils } from '@services/utils/text'; | import { CoreTextUtils } from '@services/utils/text'; | ||||||
| import { makeSingleton, Clipboard, InAppBrowser, FileOpener, WebIntent, Translate, NgZone } from '@singletons'; | import { makeSingleton, InAppBrowser, FileOpener, WebIntent, Translate, NgZone } from '@singletons'; | ||||||
| import { CoreLogger } from '@singletons/logger'; | import { CoreLogger } from '@singletons/logger'; | ||||||
| import { CoreCanceledError } from '@classes/errors/cancelederror'; | import { CoreCanceledError } from '@classes/errors/cancelederror'; | ||||||
| import { CoreFileEntry } from '@services/file-helper'; | import { CoreFileEntry } from '@services/file-helper'; | ||||||
| @ -40,6 +40,7 @@ import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; | |||||||
| import { CoreUrlUtils } from './url'; | import { CoreUrlUtils } from './url'; | ||||||
| import { QRScanner } from '@features/native/plugins'; | import { QRScanner } from '@features/native/plugins'; | ||||||
| import { CoreArray } from '@singletons/array'; | import { CoreArray } from '@singletons/array'; | ||||||
|  | import { CoreText } from '@singletons/text'; | ||||||
| 
 | 
 | ||||||
| export type TreeNode<T> = T & { children: TreeNode<T>[] }; | export type TreeNode<T> = T & { children: TreeNode<T>[] }; | ||||||
| 
 | 
 | ||||||
| @ -366,22 +367,12 @@ export class CoreUtilsProvider { | |||||||
|      * Copies a text to clipboard and shows a toast message. |      * Copies a text to clipboard and shows a toast message. | ||||||
|      * |      * | ||||||
|      * @param text Text to be copied |      * @param text Text to be copied | ||||||
|      * @returns Promise resolved when text is copied. |      * @returns Promise resolved when the text is copied. | ||||||
|  |      * | ||||||
|  |      * @deprecated since 4.5 Use CoreText.copyToClipboard instead. | ||||||
|      */ |      */ | ||||||
|     async copyToClipboard(text: string): Promise<void> { |     async copyToClipboard(text: string): Promise<void> { | ||||||
|         try { |         return CoreText.copyToClipboard(text); | ||||||
|             await Clipboard.copy(text); |  | ||||||
|         } catch { |  | ||||||
|             // Use HTML Copy command.
 |  | ||||||
|             const virtualInput = document.createElement('textarea'); |  | ||||||
|             virtualInput.innerHTML = text; |  | ||||||
|             virtualInput.select(); |  | ||||||
|             virtualInput.setSelectionRange(0, 99999); |  | ||||||
|             document.execCommand('copy'); // eslint-disable-line deprecation/deprecation
 |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         // Show toast using ionicLoading.
 |  | ||||||
|         CoreDomUtils.showToast('core.copiedtoclipboard', true); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -12,6 +12,9 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
|  | import { Clipboard } from '@singletons'; | ||||||
|  | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * Singleton with helper functions for text manipulation. |  * Singleton with helper functions for text manipulation. | ||||||
|  */ |  */ | ||||||
| @ -68,4 +71,25 @@ export class CoreText { | |||||||
|         return text.substring(1); |         return text.substring(1); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Copies a text to clipboard and shows a toast message. | ||||||
|  |      * | ||||||
|  |      * @param text Text to be copied | ||||||
|  |      */ | ||||||
|  |     static async copyToClipboard(text: string): Promise<void> { | ||||||
|  |         try { | ||||||
|  |             await Clipboard.copy(text); | ||||||
|  |         } catch { | ||||||
|  |             // Use HTML Copy command.
 | ||||||
|  |             const virtualInput = document.createElement('textarea'); | ||||||
|  |             virtualInput.innerHTML = text; | ||||||
|  |             virtualInput.select(); | ||||||
|  |             virtualInput.setSelectionRange(0, 99999); | ||||||
|  |             document.execCommand('copy'); // eslint-disable-line deprecation/deprecation
 | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Show toast using ionicLoading.
 | ||||||
|  |         CoreDomUtils.showToast('core.copiedtoclipboard', true); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user