Esri / Trek2There

Trek2There™
Apache License 2.0
10 stars 5 forks source link

Clipboard not working on UWP #83

Closed marikavertzonis closed 6 years ago

marikavertzonis commented 6 years ago

-89.44454,-179.34343433

   {
    "latitude":55.434323,
    "longitude":-33.23533
  }
SidoPillai commented 6 years ago

@marikavertzonis I can reproduce this error. But this can be handled in the app due to the nature of UWP.

Ref: https://github.com/ArcGIS/MyUSNG/issues/15#issuecomment-395583510

Adding the following in Trek2There.qml solves the issue on my UWP app. And I see the dialog

image

Connections {
       id: appClipboard
       target: AppFramework.clipboard

       property string inLat: ""
       property string inLon: ""

       onDataChanged: {

           console.log('there is data on the clipboard');

           checkClip()

       }
   }

   Connections {
      target: Qt.application
      onStateChanged: {
         if(Qt.application.state === Qt.ApplicationActive)
         {
            // Application go in active state
             console.log("CALLING checkClip() when the app is active");
             checkClip();
         }
         else
         {
            // Application go in suspend state
         }
      }
   }

   function checkClip() {
       var lat = "";
       var lon = "";

       if (AppFramework.clipboard.dataAvailable && listenToClipboard) {
           try {
               var inJson = JSON.parse(AppFramework.clipboard.text);
               if (inJson.hasOwnProperty("latitude") && inJson.hasOwnProperty("longitude")) {
                   lat = inJson.latitude.toString().trim();
                   lon = inJson.longitude.toString().trim();
               }
           }
           catch(e) {
               if (e.toString().indexOf("JSON.parse: Parse error") > -1) {
                   var incoords = AppFramework.clipboard.text.split(',');
                   if (incoords.length === 2) {
                       lat = incoords[0].toString().trim();
                       lon = incoords[1].toString().trim();
                   }
               }
           }
           finally {
               if (lat !== "" && lon !== "") {
                   if (validCoordinates(lat, lon)) {
                       appClipboard.inLat = lat;
                       appClipboard.inLon = lon;
                       clipboardDialog.clipLat = lat;
                       clipboardDialog.clipLon = lon;
                       clipboardDialog.open();
                   }
               }
           }
       }
   }

@defiantgoat Can you try this approach and let me know if this works?

marikavertzonis commented 6 years ago

@dominikargast - can you please try this and see if this is a viable option for T2T?

dominikargast commented 6 years ago

@marikavertzonis test with build 3.0.34

marikavertzonis commented 6 years ago

with 3.0.34 clipboard now working the same on uwp and windows.

note that when you change focus from T2T to another app and then return to T2T, the paste message will appear again with the previously offered coordinates. this this was observed on windows, uwp and mac, and is annoying. its expected that you should only see this offering after you have copied coordinates ready for pasting.

dominikargast commented 6 years ago

@marikavertzonis test with 3.0.35

marikavertzonis commented 6 years ago

with 3.0.35 windows and uwp both show the paste dialog when expected, and once you've pasted (or said no in the dialog dismissing the value) you dont get the prompt again (until you next copy something to clipboard).