• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6517266969

14 Oct 2023 11:05AM UTC coverage: 12.469% (+0.2%) from 12.308%
6517266969

push

github

web-flow
Implementing plugins for better separation (#39)

* Start implementing plugins for better separation
* massive refactor in attempt to split appdomains for plugins
* (breaks old mapping profiles)
* Fix error when switching from mouse button trigger to keyboard trigger and clicking in the combobox where the mouse button capture textbox is.
* Simplify code by removing legacy
* SImplify grouping actions
* Fix profile and add helpful opposite mapping generator tool
* Change solution hierarchy
* Restrict AppDomain plugins went from Zone.MyComputer -> .Internet
* create keypair in ci
* Install the .NET framework tools
* Run command in workflow
* Plugin permissions. Plugins disabled by default
* update readme (icon is no longer used)
* Plugin action runs in seperated process
* Remove unused dependencies.
* Fix action name display for mapping
* Fix Lua plugin script calls (NOTE: laggy when using MessageBox)
* convert project to sdk style
* Add editorconfig and start cleaning up
* Fix documentation. Update namespaces to match files (breaks profiles)
* Include all projects in tests, disable building docs on debug
* Add messagebox script action
* Add tests for pluginhost
* Remove administrator from window title test
* add some icons to ui
* Add enabling/disabling plugins
* Close plugins when Key2Joy shuts down
* Fix appcommand failing
* Fix plugin permission form crashing. Fix plugin load exception not showing warning
* Handle plugin host closing better when app has crashed
* Seperate host and client logic in remote event subscriber
* Ensure the PluginHost shuts down if the app crashes
* Better error output for plugins
* Fix cmd interop not working, add some tests
* also generate docs on plugins
* Fix build order with docs
* Fix enum script parameters and ensure actions share environment scopes
* Fix _wpftmp folders being created dotnet/wpf#2930
* Fix sequence action. Add disabled trigger/action for unloaded plugins on start... (continued)

180 of 1703 branches covered (0.0%)

Branch coverage included in aggregate %.

6419 of 6419 new or added lines in 207 files covered. (100.0%)

1035 of 8041 relevant lines covered (12.87%)

8445.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.47
/Core/Key2Joy.Core/Mapping/Actions/Scripting/BaseScriptActionWithEnvironment.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Threading.Tasks;
4
using Key2Joy.Contracts.Mapping.Actions;
5
using Key2Joy.Contracts.Mapping.Triggers;
6

7
namespace Key2Joy.Mapping.Actions.Scripting;
8

9
public abstract class BaseScriptActionWithEnvironment<TEnvironment> : BaseScriptAction
10
{
11
    protected TEnvironment Environment;
12
    protected Guid EnvironmentId { get; private set; }
1✔
13
    protected bool IsRetired { get; private set; }
1✔
14

15
    public BaseScriptActionWithEnvironment(string name)
16
        : base(name)
1✔
17
    { }
2✔
18

19
    public TEnvironment SetupEnvironment()
20
    {
1✔
21
        if (this.Environment is not null and IDisposable disposableEnvironment)
1!
22
        {
×
23
            disposableEnvironment.Dispose();
×
24
        }
×
25

26
        this.EnvironmentId = Guid.NewGuid();
1✔
27
        this.Environment = this.MakeEnvironment();
1✔
28
        this.RegisterEnvironmentObjects();
1✔
29

30
        // If we're started, find other actions with the same scripting environment and set their environment to this one
31
        if (this.IsStarted)
1!
32
        {
×
33
            foreach (var otherAction in this.OtherActions)
×
34
            {
×
35
                if (otherAction is BaseScriptActionWithEnvironment<TEnvironment> scriptAction)
×
36
                {
×
37
                    scriptAction.IsRetired = false;
×
38
                    scriptAction.Environment = this.Environment;
×
39
                    scriptAction.EnvironmentId = this.EnvironmentId;
×
40
                }
×
41
            }
×
42
        }
×
43

44
        return this.Environment;
1✔
45
    }
1✔
46

47
    public void RetireEnvironment() => this.IsRetired = true;
×
48

49
    public override async Task Execute(AbstractInputBag inputBag)
50
    {
1✔
51
        if (this.IsRetired)
1!
52
        {
×
53
            this.IsRetired = false;
×
54
            this.SetupEnvironment();
×
55
        }
×
56
    }
1✔
57

58
    public abstract TEnvironment MakeEnvironment();
59

60
    public virtual void RegisterEnvironmentObjects()
61
    {
1✔
62
        var actionTypes = ActionsRepository.GetAllActions();
1✔
63
        this.cachedFile = null;
1✔
64

65
        // Register all scripting available action methods and enumerations
66
        foreach (var pair in actionTypes)
63✔
67
        {
30✔
68
            var actionFactory = pair.Value;
30✔
69

70
            foreach (var exposedEnumeration in ExposedEnumerationRepository.GetAllExposedEnumerations())
510✔
71
            {
210✔
72
                this.RegisterScriptingEnum(exposedEnumeration);
210✔
73
            }
210✔
74

75
            foreach (var exposedMethods in actionFactory.ExposedMethods)
148✔
76
            {
29✔
77
                var instance = this.IsStarted ?
29!
78
                    this.MakeStartedAction(actionFactory)
29✔
79
                    : MakeAction(actionFactory);
29✔
80

81
                this.RegisterScriptingMethod(
29✔
82
                    exposedMethods,
29✔
83
                    instance);
29✔
84
            }
29✔
85
        }
30✔
86
    }
1✔
87

88
    public override void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions)
89
    {
×
90
        base.OnStartListening(listener, ref otherActions);
×
91

92
        foreach (var otherAction in otherActions)
×
93
        {
×
94
            if (otherAction is BaseScriptActionWithEnvironment<TEnvironment> scriptAction
×
95
                && scriptAction.IsStarted)
×
96
            {
×
97
                // Use an existing environment if it exists
98
                // This is so multiple actions all share the same scripting environment (and thus global variables).
99
                this.Environment = scriptAction.Environment;
×
100
                this.EnvironmentId = scriptAction.EnvironmentId;
×
101

102
                if (this.Environment != null)
×
103
                {
×
104
                    return;
×
105
                }
106
            }
×
107
        }
×
108

109
        this.SetupEnvironment();
×
110
    }
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc