Yesterday, 07:06 AM
// script "Tray icon region.cs"
using (var tir_ = new trayIconRegion()) {
dialog.show("test", "with tray icon");
}
dialog.show("test", "without tray icon");
/// <summary>
/// Adds tray icon like <see cref="script.trayIcon"/>.
/// Removes it when disposing the variable.
/// </summary>
/// <remarks>
/// Use this in a script instead of <see cref="script.setup"/> if you want to remove the icon earlier than when the script process ends. If you need <c>script.setup</c> for other purposes, make sure its first argument is omitted or <c>false</c>.
/// </remarks>
/// <example>
/// <code><![CDATA[
/// using (var tir_ = new trayIconRegion()) {
/// dialog.show("test", "with tray icon");
/// }
/// dialog.show("test", "without tray icon");
/// ]]></code>
/// </example>
class trayIconRegion : IDisposable {
trayIcon _ti;
bool _disposed;
/// <inheritdoc cref="script.trayIcon"/>
public trayIconRegion(int delay = 500, Action<trayIcon> init = null, Action<trayIcon, popupMenu> menu = null, string f_ = null) {
script.trayIcon(delay, t => {
if (!_disposed) {
_ti = t;
init?.Invoke(t);
} else {
timer.after(1, _ => { t.Dispose(); });
}
}, menu, f_);
}
/// <summary>
/// Removes the tray icon.
/// </summary>
public void Dispose() {
if (!_disposed) {
_disposed = true;
if (_ti is { } ti) {
ti.Dispose();
_ti = null;
}
}
}
}In next LA will not need this class. Instead:
