From c3cc8f96e28be6c9de571157a8dc402511031adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=80=9D?= Date: Thu, 11 Jun 2020 23:46:41 +0800 Subject: [PATCH] Add files via upload --- .../hookSublimeText.xcodeproj/project.pbxproj | 383 ++++++++++++++++++ hookSublimeText/hookSublimeText/Info.plist | 24 ++ hookSublimeText/hookSublimeText/Main.h | 38 ++ hookSublimeText/hookSublimeText/Main.m | 173 ++++++++ .../hookSublimeText/hookSublimeText.h | 31 ++ 5 files changed, 649 insertions(+) create mode 100644 hookSublimeText/hookSublimeText.xcodeproj/project.pbxproj create mode 100644 hookSublimeText/hookSublimeText/Info.plist create mode 100644 hookSublimeText/hookSublimeText/Main.h create mode 100644 hookSublimeText/hookSublimeText/Main.m create mode 100644 hookSublimeText/hookSublimeText/hookSublimeText.h diff --git a/hookSublimeText/hookSublimeText.xcodeproj/project.pbxproj b/hookSublimeText/hookSublimeText.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4aaf47d --- /dev/null +++ b/hookSublimeText/hookSublimeText.xcodeproj/project.pbxproj @@ -0,0 +1,383 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + F61114702491D33C005724ED /* hookSublimeText.h in Headers */ = {isa = PBXBuildFile; fileRef = F611146E2491D33C005724ED /* hookSublimeText.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F61114A92491D449005724ED /* JRSwizzle.h in Headers */ = {isa = PBXBuildFile; fileRef = F61114772491D449005724ED /* JRSwizzle.h */; }; + F61114BC2491D449005724ED /* JRSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = F611148E2491D449005724ED /* JRSwizzle.m */; }; + F61114C02491D4A4005724ED /* Main.h in Headers */ = {isa = PBXBuildFile; fileRef = F61114BE2491D4A4005724ED /* Main.h */; }; + F61114C12491D4A4005724ED /* Main.m in Sources */ = {isa = PBXBuildFile; fileRef = F61114BF2491D4A4005724ED /* Main.m */; }; + F61114C52491D7EE005724ED /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F61114C42491D7EE005724ED /* AppKit.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + F611146B2491D33B005724ED /* hookSublimeText.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = hookSublimeText.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + F611146E2491D33C005724ED /* hookSublimeText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = hookSublimeText.h; sourceTree = ""; }; + F611146F2491D33C005724ED /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + F61114772491D449005724ED /* JRSwizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JRSwizzle.h; sourceTree = ""; }; + F611148E2491D449005724ED /* JRSwizzle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JRSwizzle.m; sourceTree = ""; }; + F61114BE2491D4A4005724ED /* Main.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Main.h; sourceTree = ""; }; + F61114BF2491D4A4005724ED /* Main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Main.m; sourceTree = ""; }; + F61114C42491D7EE005724ED /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + F61114682491D33B005724ED /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + F61114C52491D7EE005724ED /* AppKit.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + F61114612491D33B005724ED = { + isa = PBXGroup; + children = ( + F611146D2491D33B005724ED /* hookSublimeText */, + F611146C2491D33B005724ED /* Products */, + F61114C32491D7EE005724ED /* Frameworks */, + ); + sourceTree = ""; + }; + F611146C2491D33B005724ED /* Products */ = { + isa = PBXGroup; + children = ( + F611146B2491D33B005724ED /* hookSublimeText.framework */, + ); + name = Products; + sourceTree = ""; + }; + F611146D2491D33B005724ED /* hookSublimeText */ = { + isa = PBXGroup; + children = ( + F61114762491D449005724ED /* jrswizzle */, + F611146E2491D33C005724ED /* hookSublimeText.h */, + F611146F2491D33C005724ED /* Info.plist */, + F61114BE2491D4A4005724ED /* Main.h */, + F61114BF2491D4A4005724ED /* Main.m */, + ); + path = hookSublimeText; + sourceTree = ""; + }; + F61114762491D449005724ED /* jrswizzle */ = { + isa = PBXGroup; + children = ( + F61114772491D449005724ED /* JRSwizzle.h */, + F611148E2491D449005724ED /* JRSwizzle.m */, + ); + name = jrswizzle; + path = ../../jrswizzle; + sourceTree = ""; + }; + F61114C32491D7EE005724ED /* Frameworks */ = { + isa = PBXGroup; + children = ( + F61114C42491D7EE005724ED /* AppKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + F61114662491D33B005724ED /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + F61114702491D33C005724ED /* hookSublimeText.h in Headers */, + F61114C02491D4A4005724ED /* Main.h in Headers */, + F61114A92491D449005724ED /* JRSwizzle.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + F611146A2491D33B005724ED /* hookSublimeText */ = { + isa = PBXNativeTarget; + buildConfigurationList = F61114732491D33C005724ED /* Build configuration list for PBXNativeTarget "hookSublimeText" */; + buildPhases = ( + F61114662491D33B005724ED /* Headers */, + F61114672491D33B005724ED /* Sources */, + F61114682491D33B005724ED /* Frameworks */, + F61114692491D33B005724ED /* Resources */, + F61114C22491D57A005724ED /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = hookSublimeText; + productName = hookSublimeText; + productReference = F611146B2491D33B005724ED /* hookSublimeText.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + F61114622491D33B005724ED /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1140; + ORGANIZATIONNAME = "mll"; + TargetAttributes = { + F611146A2491D33B005724ED = { + CreatedOnToolsVersion = 11.4; + }; + }; + }; + buildConfigurationList = F61114652491D33B005724ED /* Build configuration list for PBXProject "hookSublimeText" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = F61114612491D33B005724ED; + productRefGroup = F611146C2491D33B005724ED /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + F611146A2491D33B005724ED /* hookSublimeText */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + F61114692491D33B005724ED /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + F61114C22491D57A005724ED /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\n\n\ncp -r \"${BUILT_PRODUCTS_DIR}/hookSublimeText.framework\" \"/Users/${USER}/bin/tweak/hookSublimeText\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + F61114672491D33B005724ED /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + F61114C12491D4A4005724ED /* Main.m in Sources */, + F61114BC2491D449005724ED /* JRSwizzle.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + F61114712491D33C005724ED /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + F61114722491D33C005724ED /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + F61114742491D33C005724ED /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = JNWZR4N8A7; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = hookSublimeText/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.lovecode666.hookSublimeText; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + F61114752491D33C005724ED /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = JNWZR4N8A7; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = hookSublimeText/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.lovecode666.hookSublimeText; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + F61114652491D33B005724ED /* Build configuration list for PBXProject "hookSublimeText" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F61114712491D33C005724ED /* Debug */, + F61114722491D33C005724ED /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F61114732491D33C005724ED /* Build configuration list for PBXNativeTarget "hookSublimeText" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F61114742491D33C005724ED /* Debug */, + F61114752491D33C005724ED /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = F61114622491D33B005724ED /* Project object */; +} diff --git a/hookSublimeText/hookSublimeText/Info.plist b/hookSublimeText/hookSublimeText/Info.plist new file mode 100644 index 0000000..9263ac8 --- /dev/null +++ b/hookSublimeText/hookSublimeText/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright © 2020 52developer.com. All rights reserved. + + diff --git a/hookSublimeText/hookSublimeText/Main.h b/hookSublimeText/hookSublimeText/Main.h new file mode 100644 index 0000000..879acc6 --- /dev/null +++ b/hookSublimeText/hookSublimeText/Main.h @@ -0,0 +1,38 @@ +// +// Main.h +// hookSublimeText +// +// Created by lovecode666 on 2020/6/11. +// Copyright © 2020 mll All rights reserved. +// + +#import +#import + +@interface PXWindowDelegate : NSObject + +- (void)windowWillEnterFullScreen:(id)arg1; +- (void)windowWillExitFullScreen:(id)arg1; +- (BOOL)acceptsFirstResponder; +- (void)windowDidChangeBackingProperties:(id)arg1; +- (void)commandLine:(id)arg1; + +@end + +@interface PXWindow : NSWindow + +- (void)update; + +@end + +@interface PXApplication : NSApplication + +- (void)terminate:(id)arg1; + +@end + +@interface PXView : NSView + +- (void)paste:(id)arg1; + +@end diff --git a/hookSublimeText/hookSublimeText/Main.m b/hookSublimeText/hookSublimeText/Main.m new file mode 100644 index 0000000..aa6c241 --- /dev/null +++ b/hookSublimeText/hookSublimeText/Main.m @@ -0,0 +1,173 @@ +// +// Main.m +// hookSublimeText +// +// Created by lovecode666 on 2020/6/11. +// Copyright © 2020 mll. All rights reserved. +// +#import +#import "Main.h" +#import "hookSublimeText.h" + +@implementation NSObject (SublimeText) + +// - PXWindowDelegate + +- (void)m_st_windowWillExitFullScreen:(id)arg1 { + NSLog(@"SublimeText m_st_windowWillExitFullScreen"); + [self m_st_windowWillExitFullScreen:arg1]; + [self m_hidden_registerMarkView]; +} + +- (void)m_st_windowWillEnterFullScreen:(id)arg1 { + NSLog(@"SublimeText m_st_windowWillEnterFullScreen"); + [self m_st_windowWillEnterFullScreen:arg1]; + [self m_hidden_registerMarkView]; +} + +- (void)m_st_commandLine:(id)arg1 { + NSLog(@"SublimeText m_st_commandLine"); + [self m_st_commandLine:arg1]; + [self m_hidden_registerMarkView]; +} + +// - PXWindow +- (void)m_st_update { + // NSLog(@"SublimeText m_st_update"); + [self m_st_update]; + [self m_hidden_registerMarkView]; +} + +- (void)m_hidden_registerMarkView { + NSDictionary *mark = [[NSUserDefaults standardUserDefaults] objectForKey:@"removedMark"]; + if (mark) { + if ([[mark allKeys] containsObject:[self m_set_key]]) { + return; + } + } + + NSArray *titleBars = [self ns_title_bar_views]; + if (!titleBars) { + return; + } + + for (id item in titleBars) { + [self m_hidden_registerMarkView:item]; + } +} + +// Sublime Text 里有一个同名的c函数🐶 +- (NSArray *)ns_title_bar_views { + NSMutableArray *bars = @[].mutableCopy; + + NSArray *windows = [[NSApplication sharedApplication] windows]; + + for (NSWindow *win in windows) { + id titleBarView = [self ns_title_bar_view:win]; + + if (!titleBarView) { + continue; + } + + [bars addObject:titleBarView]; + } + + return bars.copy; +} + +- (id)ns_title_bar_view:(NSWindow *)win { + id res = nil; + NSView *contenView = [win contentView]; + NSArray *views = [[contenView superview] subviews]; + + Class titleBarClass = NSClassFromString(@"NSTitlebarContainerView"); + for (id item in views) { + if ([item isKindOfClass:titleBarClass]) { + res = item; + break; + + } + } + + if (res) { + NSArray *views = [res subviews]; + for (id item in views) { + if ([item isKindOfClass:NSClassFromString(@"NSTitlebarView")]) { + res = item; + break; + } + } + } + + return res; +} + +- (void)m_hidden_registerMarkView:(id)titleBarView { + NSLog(@"-- hidden --"); + if (!titleBarView) { + return; + } + + NSArray *views = [titleBarView subviews]; + + for (id item in views) { + if ([item isKindOfClass:NSClassFromString(@"NSTextField")]) { + NSTextField *txtView = (NSTextField *)item; + + if ([txtView.stringValue isEqualToString:@"UNREGISTERED"]) { + [txtView removeFromSuperview]; + } + } + } + + [self m_set_removeMark]; +} + +- (NSString *)m_set_key { + NSString *key = [NSString stringWithFormat:@"removed_%ld", [[NSApplication sharedApplication] windows].count]; + return key; +} + +- (void)m_set_removeMark { + + NSMutableDictionary *mark = @{}.mutableCopy; + [mark setValue:@"1" forKey:[self m_set_key]]; + + [[NSUserDefaults standardUserDefaults] setObject:mark forKey:@"removedMark"]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + +// - PXApplication +- (void)m_st_terminate:(id)arg1 { + NSLog(@"SublimeText m_st_terminate"); + [self m_st_terminate:arg1]; +} + +// - PXView +- (void)m_st_paste:(id)arg1 { + NSLog(@"SublimeText m_st_paste"); + [self m_st_paste:arg1]; + [self m_hidden_registerMarkView]; +} + +@end + +static void __attribute__((constructor)) initialize(void) { + + NSLog(@"++++++++ hookSublimeText loaded ++++++++"); + + // 每次 hook 复位 + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"removedMark"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + CBHookInstanceMethod(PXWindowDelegate, @selector(windowWillEnterFullScreen:), @selector(m_st_windowWillEnterFullScreen:)); + CBHookInstanceMethod(PXWindowDelegate, @selector(windowWillExitFullScreen:), @selector(m_st_windowWillExitFullScreen:)); + + // CBHookInstanceMethod(PXWindowDelegate, @selector(commandLine:), @selector(m_st_commandLine:)); + + CBHookInstanceMethod(PXWindow, @selector(update), @selector(m_st_update)); + + CBHookInstanceMethod(PXApplication, @selector(terminate:), @selector(m_st_terminate:)); + + CBHookInstanceMethod(PXView, @selector(paste:), @selector(m_st_paste:)); +} diff --git a/hookSublimeText/hookSublimeText/hookSublimeText.h b/hookSublimeText/hookSublimeText/hookSublimeText.h new file mode 100644 index 0000000..f1848e7 --- /dev/null +++ b/hookSublimeText/hookSublimeText/hookSublimeText.h @@ -0,0 +1,31 @@ +// +// hookSublimeText.h +// hookSublimeText +// +// Created by lovecode666 on 2020/6/11. +// Copyright © 2020 mll. All rights reserved. +// + +#import +#import "JRSwizzle.h" + +//! Project version number for hookSublimeText. +FOUNDATION_EXPORT double hookSublimeTextVersionNumber; + +//! Project version string for hookSublimeText. +FOUNDATION_EXPORT const unsigned char hookSublimeTextVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + +#define CBGetClass(classname) objc_getClass(#classname) + +#define CBRegisterClass(superclassname, subclassname) { Class class = objc_allocateClassPair(CBGetClass(superclassname), #subclassname, 0);objc_registerClassPair(class); } + +#define CBHookInstanceMethod(classname, ori_sel, new_sel) { NSError *error; [CBGetClass(classname) jr_swizzleMethod:ori_sel withMethod:new_sel error:&error]; if(error) NSLog(@"%@", error); } + +#define CBHookClassMethod(classname, ori_sel, new_sel) { NSError *error; [CBGetClass(classname) jr_swizzleClassMethod:ori_sel withClassMethod:new_sel error:&error]; if(error) NSLog(@"%@", error); } + +#define CBGetInstanceValue(obj, valuename) object_getIvar(obj, class_getInstanceVariable([obj class], #valuename)) + +#define CBSetInstanceValue(obj, valuename, value) object_setIvar(obj, class_getInstanceVariable([obj class], #valuename), value) +