mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
launching works for profiles
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CmdPal.Ext.WindowsTerminal.Helpers;
|
||||
using Microsoft.CmdPal.Extensions;
|
||||
using Microsoft.CmdPal.Extensions.Helpers;
|
||||
using Windows.UI;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.WindowsTerminal.Commands;
|
||||
|
||||
internal sealed partial class LaunchProfileCommand : InvokableCommand
|
||||
{
|
||||
private readonly string _id;
|
||||
private readonly string _profile;
|
||||
private readonly bool _openNewTab;
|
||||
private readonly bool _openQuake;
|
||||
|
||||
internal LaunchProfileCommand(string id, string profile, bool openNewTab, bool openQuake)
|
||||
{
|
||||
this._id = id;
|
||||
this._profile = profile;
|
||||
this._openNewTab = openNewTab;
|
||||
this._openQuake = openQuake;
|
||||
|
||||
this.Name = "Launch Profile";
|
||||
}
|
||||
|
||||
private void Launch(string id, string profile)
|
||||
{
|
||||
var appManager = new ApplicationActivationManager();
|
||||
const ActivateOptions noFlags = ActivateOptions.None;
|
||||
var queryArguments = TerminalHelper.GetArguments(profile, _openNewTab, _openQuake);
|
||||
try
|
||||
{
|
||||
appManager.ActivateApplication(id, queryArguments, noFlags, out var unusedPid);
|
||||
}
|
||||
#pragma warning disable IDE0059, CS0168
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: We need to figure out some logging
|
||||
// var name = "Plugin: " + Resources.plugin_name;
|
||||
// var message = Resources.run_terminal_failed;
|
||||
// Log.Exception("Failed to open Windows Terminal", ex, GetType());
|
||||
// _context.API.ShowMsg(name, message, string.Empty);
|
||||
}
|
||||
}
|
||||
#pragma warning restore IDE0059, CS0168
|
||||
|
||||
public override CommandResult Invoke()
|
||||
{
|
||||
try
|
||||
{
|
||||
Launch(_id, _profile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: We need to figure out some logging
|
||||
}
|
||||
|
||||
return CommandResult.KeepOpen();
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,9 @@ public static class TerminalHelper
|
||||
profileElement.TryGetProperty("guid", out JsonElement guidElement);
|
||||
var guid = guidElement.ValueKind == JsonValueKind.String ? Guid.Parse(guidElement.GetString()) : null as Guid?;
|
||||
|
||||
return new TerminalProfile(terminal, name, guid, hidden);
|
||||
profileElement.TryGetProperty("icon", out JsonElement iconElement);
|
||||
var icon = iconElement.ValueKind == JsonValueKind.String ? iconElement.GetString() : null;
|
||||
|
||||
return new TerminalProfile(terminal, name, guid, hidden, icon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,12 @@ using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.CmdPal.Ext.WindowsTerminal.Commands;
|
||||
using Microsoft.CmdPal.Ext.WindowsTerminal.Helpers;
|
||||
using Microsoft.CmdPal.Extensions;
|
||||
using Microsoft.CmdPal.Extensions.Helpers;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace Microsoft.CmdPal.Ext.WindowsTerminal;
|
||||
@@ -24,11 +26,12 @@ namespace Microsoft.CmdPal.Ext.WindowsTerminal;
|
||||
internal sealed partial class ProfilesListPage : ListPage
|
||||
{
|
||||
private readonly TerminalQuery _terminalQuery = new();
|
||||
private readonly Dictionary<string, BitmapImage> _logoCache = new();
|
||||
|
||||
public ProfilesListPage()
|
||||
{
|
||||
Icon = new(string.Empty);
|
||||
Name = "Find and launch your Windows Terminal profiles";
|
||||
Name = "Windows Terminal Profiles";
|
||||
}
|
||||
|
||||
#pragma warning disable SA1108
|
||||
@@ -45,10 +48,11 @@ internal sealed partial class ProfilesListPage : ListPage
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(new ListItem(new NoOpCommand())
|
||||
result.Add(new ListItem(new LaunchProfileCommand(profile.Terminal.AppUserModelId, profile.Name, true, false))
|
||||
{
|
||||
Title = profile.Name,
|
||||
Subtitle = profile.Terminal.DisplayName,
|
||||
Icon = new(profile.Icon),
|
||||
|
||||
// Icon = () => GetLogo(profile.Terminal),
|
||||
// Action = _ =>
|
||||
@@ -74,4 +78,17 @@ internal sealed partial class ProfilesListPage : ListPage
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
private BitmapImage GetLogo(TerminalPackage terminal)
|
||||
{
|
||||
var aumid = terminal.AppUserModelId;
|
||||
|
||||
if (!_logoCache.TryGetValue(aumid, out BitmapImage value))
|
||||
{
|
||||
value = terminal.GetLogo();
|
||||
_logoCache.Add(aumid, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,14 @@ public class TerminalProfile
|
||||
|
||||
public bool Hidden { get; }
|
||||
|
||||
public TerminalProfile(TerminalPackage terminal, string name, Guid? identifier, bool hidden)
|
||||
public string Icon { get; }
|
||||
|
||||
public TerminalProfile(TerminalPackage terminal, string name, Guid? identifier, bool hidden, string icon)
|
||||
{
|
||||
Terminal = terminal;
|
||||
Name = name;
|
||||
Identifier = identifier;
|
||||
Hidden = hidden;
|
||||
Icon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user