Skip to content

Commit

Permalink
Merge pull request #11515 from keymanapp/fix/mac/10997-adopt-unified-…
Browse files Browse the repository at this point in the history
…logging

change(mac): adopt unified logging APIs
  • Loading branch information
sgschantz authored May 27, 2024
2 parents 4402971 + 1d5ef91 commit b068f94
Show file tree
Hide file tree
Showing 39 changed files with 514 additions and 359 deletions.
3 changes: 0 additions & 3 deletions mac/Keyman4Mac/Keyman4Mac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "AppDelegate.h"
#import <KeymanEngine4Mac/KeymanEngine4Mac.h>
#import <os/log.h>

static BOOL debugMode = YES;

Expand Down Expand Up @@ -68,8 +67,6 @@ - (void)awakeFromNib {
}

- (void)windowDidResize:(NSNotification *)notification {
os_log_t oskLog = os_log_create("org.sil.keyman", "osk");
os_log_with_type(oskLog, OS_LOG_TYPE_DEBUG, "AppDelegate windowDidResize");
[self.oskView resizeOSKLayout];
}

Expand Down
10 changes: 9 additions & 1 deletion mac/Keyman4MacIM/Keyman4MacIM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
290BC680274B9DB1005CD1C3 /* KMPackageInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 290BC67F274B9DB1005CD1C3 /* KMPackageInfo.m */; };
290BC75E274F3FD7005CD1C3 /* KMKeyboardInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 290BC75D274F3FD7005CD1C3 /* KMKeyboardInfo.m */; };
2915DC512BFE35DB0051FC52 /* KMLogs.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B4A0D32BF7675A00682049 /* KMLogs.m */; };
293EA3E627140D8100545EED /* KMAboutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 293EA3E827140D8100545EED /* KMAboutWindowController.xib */; };
293EA3EB27140DEC00545EED /* preferences.xib in Resources */ = {isa = PBXBuildFile; fileRef = 293EA3ED27140DEC00545EED /* preferences.xib */; };
293EA3F427181FDA00545EED /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 293EA3F627181FDA00545EED /* Localizable.strings */; };
Expand All @@ -27,6 +28,7 @@
299B5E2129126CA20070841D /* keyman-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 299B5E1F29126CA20070841D /* keyman-icon.png */; };
29B42A572728339900EDD5D3 /* KMInfoWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29B42A592728339900EDD5D3 /* KMInfoWindowController.xib */; };
29B42A602728343B00EDD5D3 /* KMKeyboardHelpWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29B42A622728343B00EDD5D3 /* KMKeyboardHelpWindowController.xib */; };
29B4A0D52BF7675A00682049 /* KMLogs.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B4A0D32BF7675A00682049 /* KMLogs.m */; };
29B6FB732BC39DD60074BF7F /* TextApiComplianceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B6FB722BC39DD60074BF7F /* TextApiComplianceTests.m */; };
37A245C12565DFA6000BBF92 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 37A245C02565DFA6000BBF92 /* Assets.xcassets */; };
37AE5C9D239A7B770086CC7C /* qrcode.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 37AE5C9C239A7B770086CC7C /* qrcode.min.js */; };
Expand Down Expand Up @@ -216,6 +218,8 @@
29B42A612728343B00EDD5D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/KMKeyboardHelpWindowController.xib; sourceTree = "<group>"; };
29B42A642728343F00EDD5D3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/KMKeyboardHelpWindowController.strings; sourceTree = "<group>"; };
29B42A682728344600EDD5D3 /* km */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = km; path = km.lproj/KMKeyboardHelpWindowController.strings; sourceTree = "<group>"; };
29B4A0D32BF7675A00682049 /* KMLogs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMLogs.m; sourceTree = "<group>"; };
29B4A0D42BF7675A00682049 /* KMLogs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMLogs.h; sourceTree = "<group>"; };
29B5BC0328169A6300B86A17 /* ff */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ff; path = ff.lproj/KMAboutWindowController.strings; sourceTree = "<group>"; };
29B5BC0428169A6400B86A17 /* ff */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ff; path = ff.lproj/preferences.strings; sourceTree = "<group>"; };
29B5BC0528169A6400B86A17 /* ff */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ff; path = ff.lproj/KMInfoWindowController.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -540,8 +544,10 @@
989C9C0A1A7876DE00A20425 /* Keyman4MacIM */ = {
isa = PBXGroup;
children = (
299ABD7029ECE75B00AA5948 /* KeySender.h */,
29B4A0D42BF7675A00682049 /* KMLogs.h */,
29B4A0D32BF7675A00682049 /* KMLogs.m */,
299ABD6F29ECE75B00AA5948 /* KeySender.m */,
299ABD7029ECE75B00AA5948 /* KeySender.h */,
297A501128DF4D360074EB1B /* Privacy */,
98FE105B1B4DE86300525F54 /* Categories */,
98D6DA791A799EE700B09822 /* Frameworks */,
Expand Down Expand Up @@ -965,6 +971,7 @@
9A3D6C5D221531B0008785A3 /* KMOSVersion.m in Sources */,
989C9C111A7876DE00A20425 /* main.m in Sources */,
290BC680274B9DB1005CD1C3 /* KMPackageInfo.m in Sources */,
29B4A0D52BF7675A00682049 /* KMLogs.m in Sources */,
98BF924F1BF02DC20002126A /* KMBarView.m in Sources */,
E240F599202DED740000067D /* KMPackage.m in Sources */,
984B8F441AF1C3D900E096A8 /* OSKWindowController.m in Sources */,
Expand Down Expand Up @@ -998,6 +1005,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2915DC512BFE35DB0051FC52 /* KMLogs.m in Sources */,
2992F4202A28482800E08929 /* PrivacyWindowController.m in Sources */,
2992F41F2A2847C900E08929 /* TextApiCompliance.m in Sources */,
2992F41E2A2847AF00E08929 /* PrivacyConsent.m in Sources */,
Expand Down
9 changes: 5 additions & 4 deletions mac/Keyman4MacIM/Keyman4MacIM/KMAboutWindow/KMAboutBGView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "KMAboutBGView.h"
#import "KMLogs.h"

@implementation KMAboutBGView

Expand All @@ -20,15 +21,15 @@ - (void)drawRect:(NSRect)rect {
NSRect topFill, botFill;
topFill = rect;
botFill = rect;
// NSLog(@"rect origin x %f y %f size h %f w %f", rect.origin.x, rect.origin.y, rect.size.height, rect.size.width);
//os_log_debug([KMLogs uiLog], "rect origin x %f y %f size h %f w %f", rect.origin.x, rect.origin.y, rect.size.height, rect.size.width);
NSView *topImgView = [self viewWithTag:1];
// NSLog(@"topImgView origin x %f y %f size h %f w %f before", topImgView.frame.origin.x, topImgView.frame.origin.y, topImgView.frame.size.height, topImgView.frame.size.width);
//os_log_debug([KMLogs uiLog], "topImgView origin x %f y %f size h %f w %f before", topImgView.frame.origin.x, topImgView.frame.origin.y, topImgView.frame.size.height, topImgView.frame.size.width);
NSInteger imgOriginHeightDelta = topImgView.frame.origin.y - rect.origin.y;
topFill.origin.y += imgOriginHeightDelta;
topFill.size.height -= imgOriginHeightDelta;
botFill.size.height = imgOriginHeightDelta;
// NSLog(@"topFill origin x %f y %f size h %f w %f after raising to imgHeight %ld", topFill.origin.x, topFill.origin.y, topFill.size.height, topFill.size.width, imgOriginHeightDelta);
// NSLog(@"botFill origin x %f y %f size h %f w %f after reducing by imgHeight %ld", botFill.origin.x, botFill.origin.y, botFill.size.height, botFill.size.width, imgOriginHeightDelta);
//os_log_debug([KMLogs uiLog], "topFill origin x %f y %f size h %f w %f after raising to imgHeight %ld", topFill.origin.x, topFill.origin.y, topFill.size.height, topFill.size.width, imgOriginHeightDelta);
//os_log_debug([KMLogs uiLog], "botFill origin x %f y %f size h %f w %f after reducing by imgHeight %ld", botFill.origin.x, botFill.origin.y, botFill.size.height, botFill.size.width, imgOriginHeightDelta);
[[NSColor whiteColor] setFill];
NSRectFillUsingOperation(topFill, NSCompositingOperationSourceOver);
[[NSColor windowBackgroundColor] setFill];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "KMAboutWindowController.h"
#import "KMInputMethodAppDelegate.h"
#import "KMOSVersion.h"
#import "KMLogs.h"

@interface KMAboutWindowController ()
@property (nonatomic, weak) IBOutlet NSTextField *versionLabel;
Expand Down Expand Up @@ -53,12 +54,12 @@ - (IBAction)configAction:(id)sender {
u_int16_t systemVersion = [KMOSVersion SystemVersion];
if ([KMOSVersion Version_10_13_1] <= systemVersion && systemVersion <= [KMOSVersion Version_10_13_3]) // between 10.13.1 and 10.13.3 inclusive
{
NSLog(@"About Box: calling workaround instead of showPreferences (sys ver %x)", systemVersion);
os_log([KMLogs uiLog], "About Box: calling workaround instead of showPreferences (sys ver %x)", systemVersion);
[self.AppDelegate showConfigurationWindow]; // call our workaround
}
else
{
NSLog(@"About Box: calling Apple's showPreferences (sys ver %x)", systemVersion);
os_log([KMLogs uiLog], "About Box: calling Apple's showPreferences (sys ver %x)", systemVersion);
[self.AppDelegate.inputController showPreferences:sender]; // call Apple API
}
[self close];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "KMConfigurationWindowController.h"
#import "KMDownloadKBWindowController.h"
#import "KMLogs.h"

@interface KMConfigurationWindowController ()
@property (nonatomic, weak) IBOutlet NSTableView *tableView;
Expand Down Expand Up @@ -79,8 +80,7 @@ - (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
NSString* url = [[request URL] absoluteString];
if (self.AppDelegate.debugMode)
NSLog(@"decidePolicyForNavigationAction, navigating to %@", url);
os_log_debug([KMLogs uiLog], "decidePolicyForNavigationAction, navigating to %{public}@", url);

if([url hasPrefix: @"file:"]) {
[listener use];
Expand Down Expand Up @@ -358,14 +358,12 @@ - (void)checkBoxAction:(id)sender {
NSButton *checkBox = (NSButton *)sender;
NSString *kmxFilePath = [self kmxFilePathAtIndex:checkBox.tag];
if (checkBox.state == NSOnState) {
if ([self.AppDelegate debugMode])
NSLog(@"Adding active keyboard: %@", kmxFilePath);
os_log_debug([KMLogs uiLog], "Adding active keyboard: %{public}@", kmxFilePath);
[self.activeKeyboards addObject:kmxFilePath];
[self saveActiveKeyboards];
}
else if (checkBox.state == NSOffState) {
if ([self.AppDelegate debugMode])
NSLog(@"Disabling active keyboard: %@", kmxFilePath);
os_log_debug([KMLogs uiLog], "Disabling active keyboard: %{public}@", kmxFilePath);
[self.activeKeyboards removeObject:kmxFilePath];
[self saveActiveKeyboards];
}
Expand Down Expand Up @@ -443,10 +441,7 @@ - (void)handleRequestToInstallPackage:(KMPackage *) package {
NSString *keyboardInfoString = NSLocalizedString(@"info-install-keyboard-filename", nil);
[self.confirmKmpInstallAlertView setInformativeText:[NSString localizedStringWithFormat:keyboardInfoString, package.getOrigKmpFilename]];

if ([self.AppDelegate debugMode]) {
NSLog(@"Asking user to confirm installation of %@...", package.getOrigKmpFilename);
NSLog(@"KMP - temp file name: %@", package.getTempKmpFilename);
}
os_log_debug([KMLogs uiLog], "Asking user to confirm installation of %{public}@, KMP - temp file name: %{public}@", package.getOrigKmpFilename, package.getTempKmpFilename);

[self.confirmKmpInstallAlertView beginSheetModalForWindow:self.window
modalDelegate:self
Expand All @@ -457,9 +452,7 @@ - (void)handleRequestToInstallPackage:(KMPackage *) package {
- (void)installPackageFile:(NSString *)kmpFile {
// kmpFile could be a temp file (in fact, it always is!), so don't display the name.

if ([self.AppDelegate debugMode]) {
NSLog(@"KMP - Ready to unzip/install Package File: %@", kmpFile);
}
os_log_debug([KMLogs dataLog], "KMP - Ready to unzip/install Package File: %{public}@", kmpFile);

BOOL didUnzip = [self.AppDelegate unzipFile:kmpFile];

Expand All @@ -477,8 +470,8 @@ - (void)installPackageFile:(NSString *)kmpFile {
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
else if ([self.AppDelegate debugMode]) {
NSLog(@"Completed installation of KMP file.");
else {
os_log_debug([KMLogs dataLog], "Completed installation of KMP file.");
}
}

Expand Down Expand Up @@ -555,9 +548,7 @@ - (NSAlert *)confirmKmpInstallAlertView {
}

- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if ([self.AppDelegate debugMode]) {
NSLog(@"User responded to NSAlert");
}
os_log_debug([KMLogs uiLog], "User responded to NSAlert");
if (alert == _deleteAlertView) {
if (returnCode == NSAlertFirstButtonReturn) { // Delete
[self deleteFileAtIndex:(__bridge NSNumber *)contextInfo];
Expand All @@ -567,9 +558,7 @@ - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInf
}
else if (alert == _confirmKmpInstallAlertView) {
KMPackage *package = (__bridge KMPackage *)contextInfo;
if ([self.AppDelegate debugMode]) {
NSLog(@"KMP - Temp file: %@", package.getTempKmpFilename);
}
os_log_debug([KMLogs uiLog], "KMP - Temp file: %{public}@", package.getTempKmpFilename);
if (returnCode == NSAlertFirstButtonReturn) { // Install
[self installPackageFile: package.getTempKmpFilename];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "KMDownloadKBWindowController.h"
#import "KMInputMethodAppDelegate.h"
#import "KMLogs.h"

@interface KMDownloadKBWindowController ()
@property (nonatomic, weak) IBOutlet WebView *webView;
Expand All @@ -29,8 +30,8 @@ - (void)windowDidLoad {
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
KeymanVersionInfo keymanVersionInfo = [[self AppDelegate] versionInfo];
NSString *url = [NSString stringWithFormat:@"https://%@/go/macos/14.0/download-keyboards/?version=%@", keymanVersionInfo.keymanCom, version];
if (self.AppDelegate.debugMode)
NSLog(@"KMDownloadKBWindowController opening url = %@, version = '%@'", url, version);

os_log_debug([KMLogs uiLog], "KMDownloadKBWindowController opening url = %@, version = '%@'", url, version);
[self.webView.mainFrame loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

Expand All @@ -41,9 +42,8 @@ - (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *

- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
NSString* url = [[request URL] absoluteString];
if (self.AppDelegate.debugMode)
NSLog(@"decidePolicyForNavigationAction, navigating to %@", url);

os_log_debug([KMLogs uiLog], "decidePolicyForNavigationAction, navigating to %@", url);

// The pattern for matching links matches work in #3602
NSString* urlPathMatchKeyboardsInstall = @"^http(?:s)?://keyman(?:-staging)?\\.com(?:\\.local)?/keyboards/install/([^?/]+)(?:\\?(.+))?$";
// e.g. https://keyman.com/keyboards/install/foo
Expand All @@ -61,8 +61,7 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary
NSArray* matchesInstall = [regexInstall matchesInString:url options:0 range:range];

if(matchesInstall.count > 0) {
if (self.AppDelegate.debugMode)
NSLog(@"Farming out download to app delegate.");
os_log_debug([KMLogs uiLog], "Delegating download to app delegate.");
[listener ignore];
NSTextCheckingResult* match = (NSTextCheckingResult*) matchesInstall[0];
NSString* matchKeyboardId = [url substringWithRange:[match rangeAtIndex:1]];
Expand All @@ -74,31 +73,27 @@ - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary
[regexGo numberOfMatchesInString:url options:0 range:range] > 0) {
// allow https://keyman.com/keyboards* to go through
// allow https://keyman.com/go/macos/download-keyboards to go through
if (self.AppDelegate.debugMode)
NSLog(@"Accepting link in this browser.");
os_log_debug([KMLogs uiLog], "Accepting link in this browser.");
[listener use];
}
else if([url startsWith:@"keyman:"]) {
if ([url startsWith:@"keyman:link?url="])
{
if (self.AppDelegate.debugMode)
NSLog(@"Opening keyman:link URL in default browser: %@", url);
os_log_debug([KMLogs uiLog], "Opening keyman:link URL in default browser: %@", url);
[listener ignore];
url = [request.URL.absoluteString substringFromIndex:[@"keyman:link?url=" length]];
[[NSWorkspace sharedWorkspace] openURL: [[NSURL alloc] initWithString:url]];
}
else {
if (self.AppDelegate.debugMode)
NSLog(@"Farming out download to app delegate.");
os_log_debug([KMLogs uiLog], "Delegating download to app delegate.");
[listener ignore];
[self.AppDelegate processURL:url];
}
}
else
{
// Open in external browser
if (self.AppDelegate.debugMode)
NSLog(@"Opening URL in default browser: %@", url);
os_log_debug([KMLogs uiLog], "Opening URL in default browser: %@", url);
[listener ignore];
[[NSWorkspace sharedWorkspace] openURL: [[NSURL alloc] initWithString:url]];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "KMInputMethodAppDelegate.h"
#import "KMPackageInfo.h"
#import "KMKeyboardInfo.h"
#import "KMLogs.h"
#import <WebKit/WebKit.h>

@interface KMInfoWindowController ()
Expand Down Expand Up @@ -199,7 +200,7 @@ - (NSString *)detailsHtml {
return htmlStr;
}
@catch (NSException *e) {
NSLog(@"Error = %@", e.description);
os_log_error([KMLogs uiLog], "Error = %@", e.description);
return nil;
}
}
Expand Down
Loading

0 comments on commit b068f94

Please sign in to comment.