Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/10-Core/Wtq/Configuration/AutoStartMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Wtq.Configuration;

/// <summary>
/// How WTQ should start an app.
/// </summary>
public enum AutoStartMode
{
/// <summary>
/// Used to detect serialization issues.
/// </summary>
[DisplayFlags(IsVisible = false)] // Don't show this in the GUI, it's purely for internal use.
None = 0,

/// <summary>
/// Start app as soon as WTQ starts.
/// </summary>
[Display(Name = "On WTQ start")]
OnWtqStart,

/// <summary>
/// Start app on hotkey press, and it's not running yet.
/// </summary>
[Display(Name = "On hotkey press")]
OnHotkeyPress,
}
8 changes: 8 additions & 0 deletions src/10-Core/Wtq/Configuration/WtqAppOptions.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public static AttachMode GetAttachMode(this WtqAppOptions app)
return OptionUtils.Cascade<AttachMode>(o => o.AttachMode, app, app.Global);
}

/// <inheritdoc cref="WtqSharedOptions.AutoStartMode"/>
public static AutoStartMode GetAutoStartMode(this WtqAppOptions app)
{
Guard.Against.Null(app);

return OptionUtils.Cascade<AutoStartMode>(o => o.AutoStartMode, app, app.Global);
}

/// <inheritdoc cref="WtqSharedOptions.HideOnFocusLost"/>
public static HideOnFocusLost GetHideOnFocusLost(this WtqAppOptions app)
{
Expand Down
8 changes: 8 additions & 0 deletions src/10-Core/Wtq/Configuration/WtqSharedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public abstract class WtqSharedOptions : IValidatableObject
[JsonPropertyOrder(2005)]
public AttachMode? AttachMode { get; set; }

/// <summary>
/// Automatically start app on WTQ start.
/// </summary>
[DefaultValue(Wc.AutoStartMode.OnWtqStart)]
[Display(GroupName = Gn.Process, Name = "Auto start mode")]
[JsonPropertyOrder(2006)]
public AutoStartMode? AutoStartMode { get; set; }

#endregion

#region 3000 - Behavior
Expand Down
8 changes: 3 additions & 5 deletions src/10-Core/Wtq/Services/WtqAppRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public WtqAppRepo(

_ = Task.Run(async () =>
{
// TODO: Make setting for "allowStartNew"? As in, allow starting apps on WTQ first start?
// "StartApps": "OnWtqStart | OnHotkeyPress"
await UpdateAppsAsync(allowStartNew: true).NoCtx();
await UpdateAppsAsync(allowStartNew: null).NoCtx();
});

// When WTQ stops, reset all tracked apps.
Expand Down Expand Up @@ -120,7 +118,7 @@ private WtqApp GetOrCreate(WtqAppOptions opts)
/// <summary>
/// Updates the list of tracked apps (<see cref="WtqApp"/>), to match the list of available option objects (<see cref="WtqAppOptions"/>).
/// </summary>
private async Task UpdateAppsAsync(bool allowStartNew)
private async Task UpdateAppsAsync(bool? allowStartNew)
{
// Make sure this method always runs non-concurrently.
using var l = await _updateLock.WaitAsync(new CancellationTokenSource(TimeSpan.FromSeconds(15)).Token);
Expand All @@ -134,7 +132,7 @@ private async Task UpdateAppsAsync(bool allowStartNew)
var app = GetOrCreate(opt);

// Update the app's local state, which may include starting a new process.
await app.UpdateLocalAppStateAsync(allowStartNew).NoCtx();
await app.UpdateLocalAppStateAsync(allowStartNew ?? opt.GetAutoStartMode() == AutoStartMode.OnWtqStart).NoCtx();
}

// Remove app handles for dropped options.
Expand Down
2 changes: 1 addition & 1 deletion src/10-Core/Wtq/Services/WtqWindowResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class WtqWindowResolver(

private async Task<WtqWindow?> FindOrStartAsync(WtqAppOptions opts, bool allowStartNew)
{
_log.LogInformation("Using find-or-start process attach mode for app with options {Options}, looking for process (allow start new: {AllowStartNew})", opts, allowStartNew);
_log.LogDebug("Using find-or-start process attach mode for app with options {Options}, looking for process (allow start new: {AllowStartNew})", opts, allowStartNew);

// Look for an existing window first.
var window1 = await _windowService.FindWindowAsync(opts, CancellationToken.None).NoCtx();
Expand Down