166 lines
5.3 KiB
C#
166 lines
5.3 KiB
C#
using Microsoft.UI;
|
|
using Microsoft.UI.Windowing;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
|
using Microsoft.UI.Xaml.Data;
|
|
using Microsoft.UI.Xaml.Input;
|
|
using Microsoft.UI.Xaml.Media;
|
|
using System.Threading;
|
|
using Windows.ApplicationModel;
|
|
using System.Collections;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
|
|
// To learn more about WinUI, the WinUI project structure,
|
|
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
|
|
|
namespace SAPRecorderApp
|
|
{
|
|
/// <summary>
|
|
/// An empty window that can be used on its own or navigated to within a Frame.
|
|
/// </summary>
|
|
///
|
|
public sealed partial class MainWindow : Window
|
|
{
|
|
|
|
public MainWindow()
|
|
{
|
|
this.InitializeComponent();
|
|
|
|
Activated += MainWindow_Activated;
|
|
|
|
this.AppWindow.MoveAndResize(new Windows.Graphics.RectInt32(1600, 100, 600, 1000));
|
|
|
|
|
|
//var m_AppWindow = GetAppWindowForCurrentWindow();
|
|
//var titleBar = m_AppWindow.TitleBar;
|
|
//// Hide system title bar.
|
|
//titleBar.ExtendsContentIntoTitleBar = true;
|
|
var m_AppWindow = this.AppWindow;
|
|
ExtendsContentIntoTitleBar = true;
|
|
if (ExtendsContentIntoTitleBar == true)
|
|
{
|
|
m_AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall;
|
|
}
|
|
|
|
TitleBarTextBlock.Text = AppInfo.Current.DisplayInfo.DisplayName;
|
|
|
|
SystemBackdrop = new DesktopAcrylicBackdrop();
|
|
|
|
|
|
Task.Run(() =>
|
|
{
|
|
foreach (var item in Globals.recordTextQueue.GetConsumingEnumerable())
|
|
{
|
|
SetTextBox(item + "\n");
|
|
}
|
|
});
|
|
}
|
|
|
|
private void SetTextBox(string text)
|
|
{
|
|
this.DispatcherQueue.TryEnqueue(() =>
|
|
{
|
|
this.recordTextBox.Text += text;
|
|
});
|
|
}
|
|
|
|
private void RecordButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var sapGui = new SapGui();
|
|
|
|
sapGui.textBox = recordTextBox;
|
|
sapGui.Session.Record = true;
|
|
|
|
if (recordButton.Content == "Record")
|
|
{
|
|
if (sapGui.Session != null)
|
|
{
|
|
recordButton.Content = "Stop";
|
|
recordInfoBar.IsOpen = false;
|
|
recordInfoBar.Message = "";
|
|
recordInfoBar.Title = "";
|
|
recordInfoBar.Severity = InfoBarSeverity.Informational;
|
|
sapGui.BeginRecord();
|
|
recordProgressBar.IsIndeterminate = true;
|
|
}
|
|
else
|
|
{
|
|
recordInfoBar.IsOpen = true;
|
|
recordInfoBar.Message = "Please login SAP First";
|
|
recordInfoBar.Title = "";
|
|
recordInfoBar.Severity = InfoBarSeverity.Warning;
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
recordButton.Content = "Record";
|
|
recordButtonIcon.Glyph = "\uE7C8";
|
|
recordProgressBar.IsIndeterminate = false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void CopyButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
//Clipboard.SetContent(recordTextBox.Text);
|
|
}
|
|
|
|
|
|
private void ClearButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
recordTextBox.Text = "";
|
|
}
|
|
|
|
|
|
//private async Task SizeWindow(AppWindow appWindow)
|
|
//{
|
|
// var displayList = await DeviceInformation.FindAllAsync(DisplayMonitor.GetDeviceSelector());
|
|
// if (!displayList.Any()) return;
|
|
|
|
// var monitorInfo = await DisplayMonitor.FromIdAsync(displayList[0].Id);
|
|
|
|
// var winSize = new SizeInt32();
|
|
// winSize.Height = Convert.ToInt32(monitorInfo.NativeResolutionInRawPixels.Height / 10);
|
|
// winSize.Width = Convert.ToInt32(monitorInfo.NativeResolutionInRawPixels.Width / 10);
|
|
|
|
// AppWindow.Move(new PointInt32(Convert.ToInt32(monitorInfo.NativeResolutionInRawPixels.Height / 5),10));
|
|
|
|
|
|
// //appWindow.ResizeClient(winSize);
|
|
//}
|
|
|
|
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
|
{
|
|
//if (args.WindowActivationState == WindowActivationState.Deactivated)
|
|
//{
|
|
// TitleBarTextBlock.Foreground =
|
|
// (SolidColorBrush)App.Current.Resources["WindowCaptionForegroundDisabled"];
|
|
//}
|
|
//else
|
|
//{
|
|
// TitleBarTextBlock.Foreground =
|
|
// (SolidColorBrush)App.Current.Resources["WindowCaptionForeground"];
|
|
//}
|
|
}
|
|
|
|
//private AppWindow GetAppWindowForCurrentWindow()
|
|
//{
|
|
// IntPtr hWnd = WindowNative.GetWindowHandle(this);
|
|
// WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
|
|
// return AppWindow.GetFromWindowId(wndId);
|
|
//}
|
|
}
|
|
|
|
public static class Globals
|
|
{
|
|
//public static Queue recordTextQueue = new Queue();
|
|
public static BlockingCollection<string> recordTextQueue = new BlockingCollection<string>();
|
|
}
|
|
}
|