@@ -50,8 +50,8 @@ public class ClipboardPlus : IAsyncPlugin, IAsyncReloadable, IContextMenu, IPlug
50
50
// Clipboard retry times
51
51
private const int ClipboardRetryTimes = 5 ;
52
52
53
- // Clipboard retry interval
54
- private const int ClipboardRetryInterval = 100 ;
53
+ // Retry interval
54
+ private const int RetryInterval = 100 ;
55
55
56
56
#region Scores
57
57
@@ -646,7 +646,7 @@ private async Task WaitWindowHideAndSimulatePaste()
646
646
{
647
647
while ( Context . API . IsMainWindowVisible ( ) )
648
648
{
649
- await Task . Delay ( 100 ) ;
649
+ await Task . Delay ( RetryInterval ) ;
650
650
}
651
651
new InputSimulator ( ) . Keyboard . ModifiedKeyStroke (
652
652
VirtualKeyCode . CONTROL ,
@@ -747,7 +747,7 @@ private async void CopyToClipboard(ClipboardData clipboardData)
747
747
{
748
748
return e ;
749
749
}
750
- await Task . Delay ( ClipboardRetryInterval ) ;
750
+ await Task . Delay ( RetryInterval ) ;
751
751
}
752
752
}
753
753
return null ;
@@ -807,7 +807,7 @@ private async void CopyAsPlainTextToClipboard(ClipboardData clipboardData)
807
807
{
808
808
return e ;
809
809
}
810
- await Task . Delay ( ClipboardRetryInterval ) ;
810
+ await Task . Delay ( RetryInterval ) ;
811
811
}
812
812
}
813
813
return null ;
@@ -848,10 +848,31 @@ private async void ReQuery()
848
848
{
849
849
// TODO: Ask Flow-Launcher for a better way to exit the context menu.
850
850
new InputSimulator ( ) . Keyboard . KeyPress ( VirtualKeyCode . ESCAPE ) ;
851
- await Task . Delay ( 100 ) ;
851
+ await Task . Delay ( RetryInterval ) ;
852
852
Context . API . ReQuery ( false ) ;
853
853
}
854
854
855
+ private static async Task < Exception ? > FlushClipboard ( )
856
+ {
857
+ for ( int i = 0 ; i < ClipboardRetryTimes ; i ++ )
858
+ {
859
+ try
860
+ {
861
+ Clipboard . Flush ( ) ;
862
+ break ;
863
+ }
864
+ catch ( Exception e )
865
+ {
866
+ if ( i == ClipboardRetryTimes - 1 )
867
+ {
868
+ return e ;
869
+ }
870
+ await Task . Delay ( RetryInterval ) ;
871
+ }
872
+ }
873
+ return null ;
874
+ }
875
+
855
876
#endregion
856
877
857
878
#region IClipboardPlus Interface
@@ -890,7 +911,7 @@ public void Dispose()
890
911
GC . SuppressFinalize ( this ) ;
891
912
}
892
913
893
- protected virtual void Dispose ( bool disposing )
914
+ protected async void Dispose ( bool disposing )
894
915
{
895
916
if ( disposing )
896
917
{
@@ -899,21 +920,24 @@ protected virtual void Dispose(bool disposing)
899
920
{
900
921
DatabaseHelper ? . Dispose ( ) ;
901
922
DatabaseHelper = null ! ;
902
- Context . API . LogInfo ( ClassName , $ "Disposed DatabaseHelper") ;
923
+ Context . API . LogDebug ( ClassName , $ "Disposed DatabaseHelper") ;
903
924
}
904
925
ClipboardMonitor . ClipboardChanged -= OnClipboardChangeW ;
905
926
ClipboardMonitor . Dispose ( ) ;
906
927
ClipboardMonitor = null ! ;
907
- Context . API . LogInfo ( ClassName , $ "Disposed ClipboardMonitor") ;
928
+ Context . API . LogDebug ( ClassName , $ "Disposed ClipboardMonitor") ;
908
929
CultureInfoChanged = null ;
909
930
Settings = null ! ;
910
931
RecordsList = null ! ;
911
- try
932
+ var exception = await FlushClipboard ( ) ;
933
+ if ( exception == null )
912
934
{
913
- Clipboard . Flush ( ) ;
914
- Context . API . LogInfo ( ClassName , $ "Flushed Clipboard") ;
935
+ Context . API . LogDebug ( ClassName , $ "Flushed Clipboard") ;
936
+ }
937
+ else
938
+ {
939
+ Context . API . LogException ( ClassName , $ "Flushed Clipboard failed", exception ) ;
915
940
}
916
- catch ( Exception ) { }
917
941
Context . API . LogWarn ( ClassName , $ "Finish dispose") ;
918
942
_disposed = true ;
919
943
}
0 commit comments