예제 #1
0
 /// <summary>
 /// Handles the <see cref="SamplerClearer.IsActiveChanged"/> event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void SamplerClear_StateChanged(StreamDeckAction sender, EventArgs args)
 {
     if (sender.Context != this.Context)
     {
         this.RefreshState();
     }
 }
 private static async Task HandleTitleParametersDidChangeEventAsync(StreamDeckAction actionInstance, TitleParameterDidChangeEvent titleParameterDidChangeEvent)
 {
     actionInstance.Coordinates = titleParameterDidChangeEvent.Payload.Coordinates;
     actionInstance.State       = titleParameterDidChangeEvent.Payload.State;
     actionInstance.Settings    = titleParameterDidChangeEvent.Payload.Settings;
     await actionInstance.TitleParametersDidChangeAsync(titleParameterDidChangeEvent.Payload.Title, titleParameterDidChangeEvent.Payload.TitleParameters);
 }
        /// <summary>
        /// Gets the latest settings for this instance, updates them, and then persists them.
        /// </summary>
        /// <typeparam name="TSettings">The type of the settings.</typeparam>
        /// <param name="action">The action whos settings to update.</param>
        /// <param name="update">The update delegate used to apply changes to the settings.</param>
        /// <returns>The task of updating the settings.</returns>
        public static async Task UpdateSettingsAsync <TSettings>(this StreamDeckAction <TSettings> action, Action <TSettings> update)
            where TSettings : class
        {
            var settings = await action.GetSettingsAsync <TSettings>();

            update(settings);
            await action.SetSettingsAsync(settings);
        }
        private static async Task HandlePropertyInspectorEventAsync(StreamDeckAction actionInstance, PropertyInspectorEvent propertyInspectorEvent)
        {
            switch (propertyInspectorEvent.Event)
            {
            case EventType.PropertyInspectorDidAppear:
                await actionInstance.PropertyInspectorDidAppearAsync();

                break;

            case EventType.PropertyInspectorDidDisappear:
                await actionInstance.PropertyInspectorDidDisappearAsync();

                break;
            }
        }
예제 #5
0
        /// <summary>
        /// Sets <see cref="IsActive"/> and raises the <see cref="IsActiveChanged"/> event.
        /// </summary>
        /// <param name="value">The new value to set <see cref="IsActive"/>.</param>
        /// <param name="sender">The sender setting the value.</param>
        public static void SetIsActive(bool value, StreamDeckAction sender)
        {
            try
            {
                _syncRoot.Wait();

                if (SamplerClearer.IsActive != value)
                {
                    SamplerClearer.IsActive = value;
                    IsActiveChanged?.Invoke(sender, EventArgs.Empty);
                }
            }
            finally
            {
                _syncRoot.Release();
            }
        }
        private static async Task HandleAppearanceEventAsync(StreamDeckAction actionInstance, AppearanceEvent appearanceEvent)
        {
            actionInstance.Coordinates     = appearanceEvent.Payload.Coordinates;
            actionInstance.State           = appearanceEvent.Payload.State;
            actionInstance.IsInMultiAction = appearanceEvent.Payload.IsInMultiAction;
            actionInstance.Settings        = appearanceEvent.Payload.Settings;

            switch (appearanceEvent.Event)
            {
            case EventType.WillAppear:
                await actionInstance.WillAppearAsync();

                break;

            case EventType.WillDisappear:
                await actionInstance.WillDisappearAsync();

                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Invokes the method associated with <see cref="StreamDeckEventArgs{TPayload}.Payload"/>, specifically the property `event`, for the given action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="args">The <see cref="ActionEventArgs{JObject}" /> instance containing the event data.</param>
        public async Task InvokeAsync(StreamDeckAction action, ActionEventArgs <JObject> args)
        {
            // attempt to get the method information
            args.Payload.TryGetString(nameof(PropertyInspectorPayload.Event), out var @event);
            if (string.IsNullOrWhiteSpace(@event) || !this.Methods.TryGetValue(@event, out var piMethodInfo))
            {
                return;
            }

            // invoke and await the method
            var   task = piMethodInfo.InvokeAsync(action, args);
            await task;

            // when the method has a result, send it to the property inspector
            if (piMethodInfo.HasResult)
            {
                args.Payload.TryGetString(nameof(PropertyInspectorPayload.RequestId), out var requestId);
                var result = this.TryGetResultWithContext(task.Result, piMethodInfo, requestId);
                await action.SendToPropertyInspectorAsync(result);
            }
        }
        private static async Task HandleKeyEventAsync(StreamDeckAction actionInstance, KeyEvent keyEvent)
        {
            actionInstance.Coordinates      = keyEvent.Payload.Coordinates;
            actionInstance.State            = keyEvent.Payload.State;
            actionInstance.UserDesiredState = keyEvent.Payload.UserDesiredState;
            actionInstance.IsInMultiAction  = keyEvent.Payload.IsInMultiAction;
            actionInstance.Settings         = keyEvent.Payload.Settings;

            switch (keyEvent.Event)
            {
            case EventType.KeyDown:
                await actionInstance.OnKeyDownAsync();

                break;

            case EventType.KeyUp:
                await actionInstance.OnKeyUpAsync();

                break;
            }
        }
예제 #9
0
 /// <summary>
 /// Invokes the method asynchronously.
 /// </summary>
 /// <param name="action">The source of the event; the Stream Deck action.</param>
 /// <param name="args">The <see cref="ActionEventArgs{JObject}"/> instance containing the event data.</param>
 /// <returns>The result of invoking the <see cref="MethodInfo"/>.</returns>
 public Task <object> InvokeAsync(StreamDeckAction action, ActionEventArgs <JObject> args)
 {
     return(this.ParameterInfo == null
         ? this.InternalInvokeAsync(action, null)
         : this.InternalInvokeAsync(action, new[] { args.Payload.ToObject(this.ParameterInfo.ParameterType) }));
 }