Skip to content

Commit 552819b

Browse files
committed
Code cleanup
1 parent 4bc816b commit 552819b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Translit/src/AppDelegate.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ -(void) setVariant:(NSString *)variant forLanguage:(NSString *)language {
8686
auto variantKey = [language stringByAppendingString:@"_variant"];
8787
[defs setObject:variant forKey:variantKey];
8888

89-
if (id<InputControllerProtocol> __strong inputController = _inputController; inputController) {
89+
if (auto inputController = makeStrong(_inputController)) {
9090
auto currentLanguage = inputController.currentLanguage;
9191
if (currentLanguage && [currentLanguage isEqualToString:language])
9292
[inputController changeVariant:variant];
@@ -113,7 +113,7 @@ -(void) deactivateUI {
113113
[_mappingsController close];
114114
_mappingsController = nil;
115115
}
116-
if (NSWindowController * __strong aboutController = _aboutController; aboutController) {
116+
if (auto aboutController = makeStrong(_aboutController)) {
117117
[aboutController close];
118118
}
119119
}

Translit/src/MappingsWindowController.mm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,19 @@ -(void) updateTable {
8181
-(void) webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
8282
[webView evaluateJavaScript:@"document.getElementById('table-holder').scrollHeight"
8383
completionHandler:^(id result, NSError * err){
84-
dispatch_async(dispatch_get_main_queue(), ^{
85-
if (err)
84+
if (err) {
85+
os_log_error(OS_LOG_DEFAULT, "Javascript failed: %{public}@", err);
86+
return;
87+
}
88+
dispatch_async(dispatch_get_main_queue(), [weakSelf = makeWeak(self),result]() {
89+
auto self = makeStrong(weakSelf);
90+
if (!self)
8691
return;
8792
auto height = (NSNumber *)result;
8893
auto contentRect = self.window.contentLayoutRect;
8994
auto textFrame = self->_text.frame;
9095
auto minSize = self.window.contentMinSize;
9196
minSize.height = (contentRect.size.height - textFrame.size.height) + height.doubleValue;
92-
os_log_info(OS_LOG_DEFAULT, "HAHAHA %{public}lf %{public}lf", contentRect.size.height, minSize.height);
9397
[self.window setContentMinSize:minSize];
9498
if (self->_firstLoad || contentRect.size.height < minSize.height)
9599
[self.window setContentSize:{contentRect.size.width, minSize.height}];

Translit/src/pch.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define TRANSLIT_HEADER_PCH_HPP_INCLUDED
66

77
#include <objc-helpers/NSStringUtil.h>
8+
#include <objc-helpers/BlockUtil.h>
89

910
#include <memory>
1011
#include <array>

0 commit comments

Comments
 (0)