1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.BrowserClipboardService = void 0;
|
28 | const inversify_1 = require("inversify");
|
29 | const browser_1 = require("./browser");
|
30 | const logger_1 = require("../common/logger");
|
31 | const message_service_1 = require("../common/message-service");
|
32 | const nls_1 = require("../common/nls");
|
33 | let BrowserClipboardService = class BrowserClipboardService {
|
34 | async readText() {
|
35 | let permission;
|
36 | try {
|
37 | permission = await this.queryPermission('clipboard-read');
|
38 | }
|
39 | catch (e1) {
|
40 | this.logger.error('Failed checking a clipboard-read permission.', e1);
|
41 |
|
42 | try {
|
43 | return await this.getClipboardAPI().readText();
|
44 | }
|
45 | catch (e2) {
|
46 | this.logger.error('Failed reading clipboard content.', e2);
|
47 | if (browser_1.isFirefox) {
|
48 | this.messageService.warn(nls_1.nls.localize('theia/navigator/clipboardWarnFirefox',
|
49 |
|
50 | "Clipboard API is not available. It can be enabled by '{0}' preference on '{1}' page. Then reload Theia. Note, it will allow FireFox getting full access to the system clipboard.", 'dom.events.testing.asyncClipboard', 'about:config'));
|
51 | }
|
52 | return '';
|
53 | }
|
54 | }
|
55 | if (permission.state === 'denied') {
|
56 |
|
57 | this.messageService.warn(nls_1.nls.localize('theia/navigator/clipboardWarn', "Access to the clipboard is denied. Check your browser's permission."));
|
58 | return '';
|
59 | }
|
60 | return this.getClipboardAPI().readText();
|
61 | }
|
62 | async writeText(value) {
|
63 | let permission;
|
64 | try {
|
65 | permission = await this.queryPermission('clipboard-write');
|
66 | }
|
67 | catch (e1) {
|
68 | this.logger.error('Failed checking a clipboard-write permission.', e1);
|
69 |
|
70 | try {
|
71 | await this.getClipboardAPI().writeText(value);
|
72 | return;
|
73 | }
|
74 | catch (e2) {
|
75 | this.logger.error('Failed writing to the clipboard.', e2);
|
76 | if (browser_1.isFirefox) {
|
77 | this.messageService.warn(nls_1.nls.localize('theia/core/navigator/clipboardWarnFirefox',
|
78 |
|
79 | "Clipboard API is not available. It can be enabled by '{0}' preference on '{1}' page. Then reload Theia. Note, it will allow FireFox getting full access to the system clipboard.", 'dom.events.testing.asyncClipboard', 'about:config'));
|
80 | }
|
81 | return;
|
82 | }
|
83 | }
|
84 | if (permission.state === 'denied') {
|
85 |
|
86 | this.messageService.warn(nls_1.nls.localize('theia/core/navigator/clipboardWarn', "Access to the clipboard is denied. Check your browser's permission."));
|
87 | return;
|
88 | }
|
89 | return this.getClipboardAPI().writeText(value);
|
90 | }
|
91 | async queryPermission(name) {
|
92 | if ('permissions' in navigator) {
|
93 | return navigator['permissions'].query({ name: name });
|
94 | }
|
95 | throw new Error('Permissions API unavailable');
|
96 | }
|
97 | getClipboardAPI() {
|
98 | if ('clipboard' in navigator) {
|
99 | return navigator['clipboard'];
|
100 | }
|
101 | throw new Error('Async Clipboard API unavailable');
|
102 | }
|
103 | };
|
104 | __decorate([
|
105 | (0, inversify_1.inject)(message_service_1.MessageService),
|
106 | __metadata("design:type", message_service_1.MessageService)
|
107 | ], BrowserClipboardService.prototype, "messageService", void 0);
|
108 | __decorate([
|
109 | (0, inversify_1.inject)(logger_1.ILogger),
|
110 | __metadata("design:type", Object)
|
111 | ], BrowserClipboardService.prototype, "logger", void 0);
|
112 | BrowserClipboardService = __decorate([
|
113 | (0, inversify_1.injectable)()
|
114 | ], BrowserClipboardService);
|
115 | exports.BrowserClipboardService = BrowserClipboardService;
|
116 |
|
\ | No newline at end of file |