@@ -48,11 +48,6 @@ let cliArgs, cliCWD, singleInstanceCLIHandler, quitTimeAppUpdateHandler;
4848const PHOENIX_WINDOW_PREFIX = 'phcode-' ;
4949const PHOENIX_EXTENSION_WINDOW_PREFIX = 'extn-' ;
5050
51- // this shared a copy of the text that was most recently copied to clipboard. This is used as a fallback for
52- // clipboardReadText when clipboardReadText fails in the browser(browser disables clipboard
53- // apis when page is not in focus)
54- let copiedClipboardText = "" ;
55-
5651async function _getTauriWindowLabel ( prefix ) {
5752 // cannot use tauri sync api here as it returns stale window list window.__TAURI__.window.getAll();
5853 const tauriWindowLabels = await window . __TAURI__ . invoke ( '_get_window_labels' ) ;
@@ -275,20 +270,13 @@ Phoenix.app = {
275270 } ) ;
276271 }
277272 } ,
278- clipboardReadText : async function ( ) {
279- try {
280- let textRead ;
281- if ( Phoenix . isNativeApp ) {
282- textRead = await window . __TAURI__ . clipboard . readText ( ) ;
283- } else if ( window . navigator && window . navigator . clipboard ) {
284- textRead = await window . navigator . clipboard . readText ( ) ;
285- }
286- return textRead ;
287- } catch ( e ) {
288- // we silently bail out with fallback text. see `copyToClipboard` on why we do this.
289- console . error ( "Error while reading clipboard: " , e ) ;
273+ clipboardReadText : function ( ) {
274+ if ( Phoenix . isNativeApp ) {
275+ return window . __TAURI__ . clipboard . readText ( ) ;
276+ } else if ( window . navigator && window . navigator . clipboard ) {
277+ return window . navigator . clipboard . readText ( ) ;
290278 }
291- return copiedClipboardText ;
279+ return Promise . reject ( new Error ( "clipboardReadText: Not supported." ) ) ;
292280 } ,
293281 clipboardReadFiles : function ( ) {
294282 return new Promise ( ( resolve , reject ) => {
@@ -310,30 +298,19 @@ Phoenix.app = {
310298 }
311299 } ) ;
312300 } ,
313- copyToClipboard : async function ( textToCopy ) {
314- try {
315- copiedClipboardText = textToCopy ;
316- if ( Phoenix . isNativeApp ) {
317- await window . __TAURI__ . clipboard . writeText ( textToCopy ) ;
318- return ;
319- } else if ( window . navigator && window . navigator . clipboard ) {
320- await window . navigator . clipboard . writeText ( textToCopy ) ;
321- return ;
322- }
323- const textArea = document . createElement ( "textarea" ) ;
324- textArea . value = textToCopy ;
325- document . body . appendChild ( textArea ) ;
326- textArea . select ( ) ;
327- document . execCommand ( "copy" ) ;
328- document . body . removeChild ( textArea ) ;
329- } catch ( e ) {
330- // we silently bail out as we will fallback to copiedClipboardText local variable.
331- // in browsers, when tab is not in focus, the clipboard apis can fail as its expected browser behavior.
332- // in popped out live previews, it may edit the clipboard for copy-paste operations which is normal
333- // behavior which should work with fallback text. Since this is normal behavior, we dont want to
334- // report the errors upstream but just log for now.
335- console . error ( "Error while copying to clipboard: " , e ) ;
336- }
301+ copyToClipboard : function ( textToCopy ) {
302+ if ( Phoenix . isNativeApp ) {
303+ return window . __TAURI__ . clipboard . writeText ( textToCopy ) ;
304+ } else if ( window . navigator && window . navigator . clipboard ) {
305+ return window . navigator . clipboard . writeText ( textToCopy ) ;
306+ }
307+ const textArea = document . createElement ( "textarea" ) ;
308+ textArea . value = textToCopy ;
309+ document . body . appendChild ( textArea ) ;
310+ textArea . select ( ) ;
311+ document . execCommand ( "copy" ) ;
312+ document . body . removeChild ( textArea ) ;
313+ return Promise . resolve ( ) ;
337314 } ,
338315 isFullscreen : function ( ) {
339316 if ( ! Phoenix . isNativeApp ) {
0 commit comments