3
3
using Dalamud . Configuration ;
4
4
using Dalamud . IoC ;
5
5
using Dalamud . Plugin ;
6
+ using Dalamud . Plugin . Services ;
6
7
using Meddle . Plugin . Models ;
7
8
using Meddle . Plugin . Services ;
8
9
using Meddle . Plugin . UI . Layout ;
@@ -20,11 +21,16 @@ public sealed class Plugin : IDalamudPlugin
20
21
{
21
22
public static readonly string DefaultExportDirectory = Path . Combine ( Path . GetTempPath ( ) , "Meddle.Export" ) ;
22
23
private readonly IHost ? app ;
23
- private readonly ILogger < Plugin > ? log ;
24
+ private readonly IPluginLog pluginLog ;
24
25
public static ILogger < Plugin > ? Logger ;
25
26
26
27
public Plugin ( IDalamudPluginInterface pluginInterface )
27
28
{
29
+ var service = new Service ( ) ;
30
+ pluginInterface . Inject ( service ) ;
31
+ pluginLog = service . GetLog ( ) ?? throw new InvalidOperationException ( "Service log is null" ) ;
32
+ pluginLog . Debug ( "Meddle Plugin initializing..." ) ;
33
+
28
34
try
29
35
{
30
36
#if HAS_LOCAL_CS
@@ -52,6 +58,7 @@ public Plugin(IDalamudPluginInterface pluginInterface)
52
58
host . ConfigureServices ( services =>
53
59
{
54
60
services . Configure < ConsoleLifetimeOptions > ( options => options . SuppressStatusMessages = true ) ;
61
+ service . RegisterServices ( services ) ;
55
62
services
56
63
. AddServices ( pluginInterface )
57
64
. AddSingleton ( config )
@@ -60,16 +67,15 @@ public Plugin(IDalamudPluginInterface pluginInterface)
60
67
} ) ;
61
68
62
69
app = host . Build ( ) ;
63
- log = app . Services . GetRequiredService < ILogger < Plugin > > ( ) ;
64
- Logger = log ;
70
+ Logger = app . Services . GetRequiredService < ILogger < Plugin > > ( ) ;
65
71
Meddle . Utils . Global . Logger = app . Services . GetRequiredService < ILogger < Meddle . Utils . Global > > ( ) ;
66
72
NativeDll . Initialize ( app . Services . GetRequiredService < IDalamudPluginInterface > ( ) . AssemblyLocation . DirectoryName ) ;
67
73
68
74
app . Start ( ) ;
69
75
}
70
76
catch ( Exception e )
71
77
{
72
- log ? . LogError ( e , "Failed to initialize plugin" ) ;
78
+ pluginLog . Error ( e , "Failed to initialize plugin" ) ;
73
79
Dispose ( ) ;
74
80
}
75
81
}
@@ -79,7 +85,7 @@ public void Dispose()
79
85
app ? . StopAsync ( ) ;
80
86
app ? . WaitForShutdown ( ) ;
81
87
app ? . Dispose ( ) ;
82
- log ? . LogDebug ( "Plugin disposed" ) ;
88
+ pluginLog ? . Debug ( "Plugin disposed" ) ;
83
89
Alloc . Dispose ( ) ;
84
90
}
85
91
}
0 commit comments