OSDN Git Service

ステータスバーに各タブの更新回数(起動時からの回数)の表示を追加
[opentween/open-tween.git] / OpenTween / ApplicationContainer.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2022 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 #nullable enable
23
24 using System;
25 using OpenTween.Models;
26 using OpenTween.Setting;
27 using OpenTween.SocialProtocol;
28 using OpenTween.Thumbnail;
29 using OpenTween.Thumbnail.Services;
30
31 namespace OpenTween
32 {
33     public sealed class ApplicationContainer : IDisposable
34     {
35         public bool IsDisposed { get; private set; } = false;
36
37         public SettingManager Settings { get; }
38
39         public TabInformations TabInfo { get; } = TabInformations.GetInstance();
40
41         public CultureService CultureService
42             => this.cultureServiceLazy.Value;
43
44         public AccountCollection AccountCollection
45             => this.accountCollectionLazy.Value;
46
47         public ImageCache ImageCache
48             => this.imageCacheLazy.Value;
49
50         public IconAssetsManager IconAssetsManager
51             => this.iconAssetsManagerLazy.Value;
52
53         public ImgAzyobuziNet ImgAzyobuziNet
54             => this.imgAzyobuziNetLazy.Value;
55
56         public ThumbnailGenerator ThumbnailGenerator
57             => this.thumbnailGeneratorLazy.Value;
58
59         public TweenMain MainForm
60             => this.mainFormLazy.Value;
61
62         private readonly Lazy<CultureService> cultureServiceLazy;
63         private readonly DisposableLazy<AccountCollection> accountCollectionLazy;
64         private readonly DisposableLazy<ImageCache> imageCacheLazy;
65         private readonly DisposableLazy<IconAssetsManager> iconAssetsManagerLazy;
66         private readonly DisposableLazy<ImgAzyobuziNet> imgAzyobuziNetLazy;
67         private readonly Lazy<ThumbnailGenerator> thumbnailGeneratorLazy;
68         private readonly DisposableLazy<TweenMain> mainFormLazy;
69
70         public ApplicationContainer(SettingManager settings)
71         {
72             this.Settings = settings;
73             SettingManager.Instance = settings;
74
75             this.cultureServiceLazy = new(this.CreateCultureService);
76             this.accountCollectionLazy = new(this.CreateAccountCollection);
77             this.imageCacheLazy = new(this.CreateImageCache);
78             this.iconAssetsManagerLazy = new(this.CreateIconAssetsManager);
79             this.imgAzyobuziNetLazy = new(this.CreateImgAzyobuziNet);
80             this.thumbnailGeneratorLazy = new(this.CreateThumbnailGenerator);
81             this.mainFormLazy = new(this.CreateTweenMain);
82         }
83
84         private CultureService CreateCultureService()
85             => new(this.Settings.Common);
86
87         private AccountCollection CreateAccountCollection()
88             => new();
89
90         private ImageCache CreateImageCache()
91             => new();
92
93         private IconAssetsManager CreateIconAssetsManager()
94             => new();
95
96         private ImgAzyobuziNet CreateImgAzyobuziNet()
97             => new(autoupdate: false);
98
99         private ThumbnailGenerator CreateThumbnailGenerator()
100             => new(this.ImgAzyobuziNet);
101
102         private TweenMain CreateTweenMain()
103             => new(this.Settings, this.TabInfo, this.AccountCollection, this.ImageCache, this.IconAssetsManager, this.ThumbnailGenerator);
104
105         public void Dispose()
106         {
107             if (this.IsDisposed)
108                 return;
109
110             this.IsDisposed = true;
111             this.mainFormLazy.Dispose();
112             this.imgAzyobuziNetLazy.Dispose();
113             this.accountCollectionLazy.Dispose();
114             this.iconAssetsManagerLazy.Dispose();
115             this.imageCacheLazy.Dispose();
116         }
117     }
118 }