OSDN Git Service

fd62d698bd99e3c80d2e603d8e74cb3c8ce9f6c1
[letter-fix/LetterFix.git] / LFApp.m
1 //
2 //  LFApp.m
3 //  LetterFix2
4 //
5 //  Created by kuri on 10/02/26.
6 //  Copyright 2010-2020 kuri. All rights reserved.
7 //
8
9 #import "LFApp.h"
10 #import "LFMenu.h"
11
12 @implementation LFApp
13
14 - (instancetype) init
15 {
16     self = [super init];
17     
18     if (self != nil) {
19         userDefaults = [NSUserDefaults standardUserDefaults];
20         
21         infodict       = [NSBundle mainBundle].infoDictionary;
22         mailVersion    = infodict[@"CFBundleVersion"];
23         lastknow       = [userDefaults stringForKey:@"LetterFixLastKnownBundleVersion"];
24         
25         if (lastknow && [mailVersion compare:lastknow] != NSOrderedSame) {
26             NSAlert *alert = [[NSAlert alloc] init];
27             [alert setMessageText:@"LetterFix plug-in"];
28             [alert setInformativeText:@"Mail.app が変更されました。\n"
29              @"Mail.app のアップデート等により,プラグインの動作に問題が発生する場合は,アンインストールしてください。\n"
30              @"このプラグインは通常 ~/Library/Mail/Bundles/ にインストールされています。"];
31             [alert setAlertStyle:NSInformationalAlertStyle];
32             [alert runModal];
33             [alert release];
34         }
35         
36         SInt32 systemVersionMajor, systemVersionMinor;
37         if ((Gestalt(gestaltSystemVersionMajor, &systemVersionMajor) == noErr) &&
38             (Gestalt(gestaltSystemVersionMinor, &systemVersionMinor) == noErr)) {
39             if (systemVersionMajor == 10) {
40                 switch (systemVersionMinor) {
41                     case 9:
42                         version = LF_Mavericks;
43                         break;
44                     case 10:
45                         version = LF_Yosemite;
46                         break;
47                     case 11:
48                         version = LF_ElCapitan;
49                         break;
50                     case 12:
51                         version = LF_Sierra;
52                         break;
53                     case 13:
54                         version = LF_HighSierra;
55                         break;
56                     case 14:
57                         version = LF_Mojave;
58                         break;
59                     case 15:
60                         version = LF_Catalina;
61                         break;
62                     default:
63                         version = LF_Unknown;
64                         break;
65                 }
66             } else {
67                 version = LF_Unknown;
68             }
69         } else {
70             version = LF_Unknown;
71         }
72         
73         if (version != LF_Unknown) {
74             [userDefaults setObject:mailVersion forKey:@"LetterFixLastKnownBundleVersion"];
75         
76             self.isActive = ![userDefaults boolForKey:@"LetterFixDisabled"];
77             self.shouldFixOsDependents = ![userDefaults boolForKey:@"LetterFixOsDependentFixDisabled"];
78             self.shouldFixParenSymbols = ![userDefaults boolForKey:@"LetterFixParenSymbolFixDisabled"];
79             self.shouldNotFixSomeParenSymbols = [userDefaults boolForKey:@"LetterFixSomeParenSymbolFixEnabled"];
80             self.shouldFixAllLetters = ![userDefaults boolForKey:@"LetterFixAllLetterFixDisabled"];
81             self.shouldAppendCodeInfo = [userDefaults boolForKey:@"LetterFixDoAppendCodeInfo"];
82             self.operationModeOnLoad = (int)[userDefaults integerForKey:@"LetterFixOperationAtOpen"];
83             if (version == LF_HighSierra || version == LF_Mojave || version == LF_Catalina)
84                 self.shouldCheckSubject = [userDefaults integerForKey:@"LetterFixCheckSubjectEnabled"];
85             else
86                 self.shouldCheckSubject = ![userDefaults integerForKey:@"LetterFixCheckSubjectDisabled"];
87             self.shouldCheckOnSave = [userDefaults integerForKey:@"LetterFixCheckOnSaveEnabled"];
88             self.shouldIgnoreZeroWidthSpace = [userDefaults boolForKey:@"LetterFixIgnoreZeroWidthSpace"];
89             menu = [[LFMenu alloc] initWithApp:self];
90             [menu inject];
91
92             if (^{
93                 for (NSString *lang in [NSLocale preferredLanguages])
94                     if ([lang hasPrefix:@"ja"]) return NO;
95                 return YES;
96             }()) {
97                 NSAlert *alert = [[NSAlert alloc] init];
98                 [alert setMessageText:@"LetterFix plug-in"];
99                 [alert setInformativeText:@"システム環境設定>言語とテキスト(Language & Text)内の言語リストに"
100                  @"「日本語」が存在しません。この状態では Letter-fix は動作せず、すべての日本語メールはUTF-8で送信されます。"
101                  @"言語リストに日本語を加えてください。なお順序は問いません。"];
102                 [alert setAlertStyle:NSInformationalAlertStyle];
103                 [alert runModal];
104                 [alert release];
105                 isActive = FALSE;
106                 [[menu onoffMenuItem] setState:FALSE];
107             }
108         } else {
109             NSAlert *alert = [[NSAlert alloc] init];
110             [alert setMessageText:@"LetterFix plug-in"];
111             [alert setInformativeText:@"このバージョンのmacOSには対応していません。アンインストールしてください。"];
112             [alert setAlertStyle:NSInformationalAlertStyle];
113             [alert runModal];
114             [alert release];
115         }
116     }
117     return self;
118 }
119
120 - (BOOL) isActive
121 {
122     return (isActive);
123 }
124
125 - (void) setIsActive:(BOOL)active
126 {
127     [userDefaults setBool:!active forKey:@"LetterFixDisabled"];
128     isActive = active;
129 }
130
131 - (BOOL) shouldFixOsDependents
132 {
133     return (flagFixOsDependents);
134 }
135
136 - (void) setShouldFixOsDependents:(BOOL)active
137 {
138     [userDefaults setBool:!active forKey:@"LetterFixOsDependentFixDisabled"];
139     flagFixOsDependents = active;
140 }
141
142 - (BOOL) shouldFixParenSymbols
143 {
144     return (flagFixParenSymbols);
145 }
146
147 - (void) setShouldFixParenSymbols:(BOOL)active
148 {
149     [userDefaults setBool:!active forKey:@"LetterFixParenSymbolFixDisabled"];
150     flagFixParenSymbols = active;
151 }
152
153 - (BOOL) shouldNotFixSomeParenSymbols
154 {
155     return (flagNotFixSomeParenSymbols);
156 }
157
158 - (void) setShouldNotFixSomeParenSymbols:(BOOL)active
159 {
160     [userDefaults setBool:active forKey:@"LetterFixSomeParenSymbolFixEnabled"];
161     flagNotFixSomeParenSymbols = active;
162 }
163
164 - (BOOL) shouldFixAllLetters
165 {
166     return (flagFixAllLetters);
167 }
168
169 - (void) setShouldFixAllLetters:(BOOL)active
170 {
171     [userDefaults setBool:!active forKey:@"LetterFixAllLetterFixDisabled"];
172     flagFixAllLetters = active;
173 }
174
175 - (BOOL) shouldAppendCodeInfo
176 {
177     return (flagAppendCodeInfo);
178 }
179
180 - (void) setShouldAppendCodeInfo:(BOOL)active
181 {
182     [userDefaults setBool:active forKey:@"LetterFixDoAppendCodeInfo"];
183     flagAppendCodeInfo = active;
184 }
185
186 - (int) operationModeOnLoad
187 {
188     return (operationModeOnLoad);
189 }
190
191 - (void) setOperationModeOnLoad:(int)value
192 {
193     [userDefaults setInteger:value forKey:@"LetterFixOperationAtOpen"];
194     operationModeOnLoad = value;
195 }
196
197 - (BOOL) shouldCheckSubject
198 {
199     return (flagCheckSubject);
200 }
201
202 - (void) setShouldCheckSubject:(BOOL)active
203 {
204     [userDefaults setBool:active forKey:@"LetterFixCheckSubjectEnabled"];
205     [userDefaults setBool:!active forKey:@"LetterFixCheckSubjectDisabled"];
206     flagCheckSubject = active;
207 }
208
209 - (BOOL) shouldCheckOnSave
210 {
211     return (flagCheckOnSave);
212 }
213
214 - (void) setShouldCheckOnSave:(BOOL)active
215 {
216     [userDefaults setBool:active forKey:@"LetterFixCheckOnSaveEnabled"];
217     flagCheckOnSave = active;
218 }
219
220 - (BOOL) shouldIgnoreZeroWidthSpace
221 {
222     return (flagIgnoreZeroWidthSpace);
223 }
224
225 - (void) setShouldIgnoreZeroWidthSpace:(BOOL)active
226 {
227     [userDefaults setBool:active forKey:@"LetterFixIgnoreZeroWidthSpace"];
228     flagIgnoreZeroWidthSpace = active;
229 }
230
231 @synthesize version;
232 @synthesize mailVersion;
233
234 @end