-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构 截图2/n 修复 搜索框激活后未取得焦点
- Loading branch information
Showing
8 changed files
with
138 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
namespace Core.SDKs.Services; | ||
using PluginCore; | ||
|
||
namespace Core.SDKs.Services; | ||
|
||
public interface IScreenCaptureWindow | ||
{ | ||
public void CaptureScreen(); | ||
public Task<ScreenCaptureInfo> GetScreenCaptureInfo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,94 @@ | ||
using Core.SDKs.Services; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Media; | ||
using Core.SDKs.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using PluginCore; | ||
|
||
namespace KitopiaAvalonia.Services; | ||
|
||
public class ScreenCaptureWindow : IScreenCaptureWindow | ||
{ | ||
public void CaptureScreen() | ||
{ | ||
Tools.ScreenCapture.StartUserManualCapture(); | ||
var captureAllScreen = ServiceManager.Services.GetService<IScreenCapture>()!.CaptureAllScreen(); | ||
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
var screens = desktop.MainWindow.Screens; | ||
for (var index = 0; index < screens.All.Count; index++) | ||
{ | ||
var screen = screens.All[index]; | ||
var rect = screen.Bounds; | ||
var window = new Windows.ScreenCaptureWindow(index) | ||
{ | ||
Position = new PixelPoint(rect.X, rect.Y), | ||
WindowState = WindowState.FullScreen, | ||
SystemDecorations = SystemDecorations.None, | ||
Background = new SolidColorBrush(Colors.Black), | ||
ShowInTaskbar = false, | ||
Topmost = false, | ||
CanResize = false, | ||
IsVisible = true, | ||
}; | ||
window.MosaicImage.Source = captureAllScreen.Item2.Count > 0 ? captureAllScreen.Item2.Dequeue() : null; | ||
window.Image.Source = captureAllScreen.Item1.Count > 0 ? captureAllScreen.Item1.Dequeue() : null; | ||
window.Show(); | ||
} | ||
} | ||
|
||
captureAllScreen.Item2.Clear(); | ||
captureAllScreen.Item1.Clear(); | ||
GC.Collect(2, GCCollectionMode.Aggressive); | ||
} | ||
|
||
public async Task<ScreenCaptureInfo> GetScreenCaptureInfo() | ||
{ | ||
ScreenCaptureInfo screenCaptureInfo = new ScreenCaptureInfo() | ||
{ | ||
Index = -1 | ||
}; | ||
SemaphoreSlim semaphore = new SemaphoreSlim(1, 1); | ||
Action<ScreenCaptureInfo> action = (info) => { | ||
screenCaptureInfo = info; | ||
semaphore.Release(); | ||
}; | ||
await semaphore.WaitAsync(); | ||
var captureAllScreen = ServiceManager.Services.GetService<IScreenCapture>()!.CaptureAllScreen(); | ||
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
var screens = desktop.MainWindow.Screens; | ||
for (var index = 0; index < screens.All.Count; index++) | ||
{ | ||
var screen = screens.All[index]; | ||
var rect = screen.Bounds; | ||
var window = new Windows.ScreenCaptureWindow(index) | ||
{ | ||
Position = new PixelPoint(rect.X, rect.Y), | ||
WindowState = WindowState.FullScreen, | ||
SystemDecorations = SystemDecorations.None, | ||
Background = new SolidColorBrush(Colors.Black), | ||
ShowInTaskbar = false, | ||
Topmost = false, | ||
CanResize = false, | ||
IsVisible = true, | ||
}; | ||
window.MosaicImage.Source = captureAllScreen.Item2.Count > 0 ? captureAllScreen.Item2.Dequeue() : null; | ||
window.Image.Source = captureAllScreen.Item1.Count > 0 ? captureAllScreen.Item1.Dequeue() : null; | ||
window.SetToSelectMode(action); | ||
window.Show(); | ||
} | ||
} | ||
|
||
await semaphore.WaitAsync(); | ||
captureAllScreen.Item2.Clear(); | ||
captureAllScreen.Item1.Clear(); | ||
semaphore.Dispose(); | ||
GC.Collect(2, GCCollectionMode.Aggressive); | ||
|
||
return screenCaptureInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters