Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra authored and Alexandra committed Dec 8, 2022
0 parents commit bba0f7f
Show file tree
Hide file tree
Showing 60 changed files with 3,149 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: traurige
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Bug report
about: Report a bug to help improve Kayoko
title: ''
labels: bug
assignees: Traurige

---

**Describe the bug:**

**Steps to reproduce the behavior:**

**System information:**
- iOS version:
- Jailbreak:
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Feature request
about: Suggest a feature that can help make Kayoko even better
title: ''
labels: enhancement
assignees: Traurige

---

**Describe the requested feature:**

**System information:**
- iOS version:
- Jailbreak:
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.theos
packages/
.vscode
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Daemon/KayokoDaemon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <Foundation/Foundation.h>
#import <notify.h>

@interface KayokoDaemon : NSObject {
int _token;
}
@end
27 changes: 27 additions & 0 deletions Daemon/KayokoDaemon.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#import "KayokoDaemon.h"

@implementation KayokoDaemon
- (instancetype)init {
self = [super init];

if (self) {
notify_register_dispatch("com.apple.pasteboard.notify.changed", &(_token), dispatch_get_main_queue(), ^(int _) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.daemon.pasteboard.changed", nil, nil, YES);
});
}

return self;
}

- (void)dealloc {
notify_cancel(_token);
[super dealloc];
}
@end

int main(int argc, char** argv, char** envp) {
[[KayokoDaemon alloc] init];
[[NSRunLoop currentRunLoop] run];

return 0;
}
7 changes: 7 additions & 0 deletions Daemon/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TOOL_NAME = kayokod
kayokod_FILES = KayokoDaemon.m
kayokod_INSTALL_PATH = /usr/libexec
kayokod_CODESIGN_FLAGS = -Sentitlements.plist

include $(THEOS)/makefiles/common.mk
include $(THEOS_MAKE_PATH)/tool.mk
7 changes: 7 additions & 0 deletions Daemon/entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.springboard.launchapplications</key>
<true/>
</dict>
</plist>
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export ARCHS = arm64 arm64e
export TARGET = iphone:clang:14.4:13.0
export SYSROOT = $(THEOS)/sdks/iPhoneOS14.4.sdk
export PREFIX = $(THEOS)/toolchain/Xcode.xctoolchain/usr/bin/

INSTALL_TARGET_PROCESSES = SpringBoard
SUBPROJECTS = Tweak/Core Tweak/Helper Daemon Preferences

include $(THEOS)/makefiles/common.mk
include $(THEOS_MAKE_PATH)/aggregate.mk
15 changes: 15 additions & 0 deletions Manager/PasteboardItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <UIKit/UIKit.h>

@interface PasteboardItem : NSObject
@property(atomic, assign)NSString* bundleIdentifier;
@property(atomic, assign)NSString* displayName;
@property(atomic, assign)NSString* content;
@property(atomic, assign)NSString* imageName;
@property(atomic, assign)BOOL hasPlainText;
@property(atomic, assign)BOOL hasLink;
@property(atomic, assign)BOOL hasMusicLink;
@property(atomic, assign)BOOL hasColor;
@property(atomic, assign)BOOL hasImage;
- (instancetype)initWithBundleIdentifier:(NSString *)bundleIdentifier andContent:(NSString *)content withImageNamed:(NSString *)imageName;
+ (PasteboardItem *)itemFromDictionary:(NSDictionary *)dictionary;
@end
63 changes: 63 additions & 0 deletions Manager/PasteboardItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#import "PasteboardItem.h"

@implementation PasteboardItem
- (instancetype)initWithBundleIdentifier:(NSString *)bundleIdentifier andContent:(NSString *)content withImageNamed:(NSString *)imageName {
self = [super init];

if (self) {
[self setBundleIdentifier:bundleIdentifier];
[self setContent:content];
[self setImageName:imageName];
[self setHasLink:[content hasPrefix:@"http://"] || [content hasPrefix:@"https://"]];
[self setHasMusicLink:[self contentHasMusicLink:content]];
[self setHasColor:![self hasLink] && ![self hasMusicLink] && [self contentHasColor:content]];
[self setHasImage:imageName && ![imageName isEqualToString:@""]];
[self setHasPlainText:![self hasLink] && ![self hasMusicLink] && ![self hasColor] && ![self hasImage]];
}

return self;
}

+ (PasteboardItem *)itemFromDictionary:(NSDictionary *)dictionary {
return [[PasteboardItem alloc] initWithBundleIdentifier:dictionary[@"bundleIdentifier"] andContent:dictionary[@"content"] withImageNamed:dictionary[@"imageName"]];
}

- (BOOL)contentHasMusicLink:(NSString *)content {
NSArray* linkPrefixes = @[
@"https://music.apple.com/",
@"https://open.spotify.com/",
@"https://music.youtube.com/",
@"https://soundcloud.com/",
@"https://music.amazon.com/",
@"https://www.pandora.com/",
@"https://www.deezer.com/",
@"https://napster.com/",
@"https://listen.tidal.com/",
@"https://music.yandex.ru/"
];

for (NSString* prefix in linkPrefixes) {
if ([content hasPrefix:prefix]) {
return YES;
}
}

return NO;
}

- (BOOL)contentHasColor:(NSString *)content {
NSString* hexRegex = @"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$";
NSString* rgbRegex = @"^rgb\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*\\)$";
NSString* rgbaRegex = @"^rgba\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3}|[0-9]{1,3}\\.[0-9]{1,3})\\s*\\)$";
NSArray* regexes = @[hexRegex, rgbRegex, rgbaRegex];

for (NSString* regex in regexes) {
NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:0 error:nil];
if ([expression firstMatchInString:content options:0 range:NSMakeRange(0, [content length])]) {
return YES;
}
}

return NO;
}
@end
44 changes: 44 additions & 0 deletions Manager/PasteboardManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// PasteboardManager.h
// Kayoko
//
// Created by Alexandra (@Traurige)
//

#import <UIKit/UIKit.h>
#import "PasteboardItem.h"
#import "../Utils/CommonUtil.h"
#import "../Utils/ImageUtil.h"
#import "../Preferences/PreferenceKeys.h"

static NSString* const kHistoryPath = @"/var/mobile/Documents/dev.traurige/Kayoko/history.json";
static NSString* const kHistoryImagesPath = @"/var/mobile/Documents/dev.traurige/Kayoko/images/";
static NSString* const kHistoryKeyHistory = @"history";
static NSString* const kHistoryKeyFavorites = @"favorites";

@interface PasteboardManager : NSObject {
UIPasteboard* _pasteboard;
NSUInteger _lastChangeCount;
NSFileManager* _fileManager;
}
@property(atomic, assign)NSUInteger maximumHistoryAmount;
@property(atomic, assign)BOOL saveText;
@property(atomic, assign)BOOL saveImages;
@property(atomic, assign)BOOL automaticallyPaste;
+ (instancetype)sharedInstance;
- (void)pullPasteboardChanges;
- (void)addPasteboardItem:(PasteboardItem *)item toHistoryWithKey:(NSString *)historyKey;
- (void)addSongDotLinkItemFromItem:(PasteboardItem *)item;
- (void)addTranslateItemFromItem:(PasteboardItem *)item;
- (void)updatePasteboardWithItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldAutoPaste:(BOOL)shouldAutoPaste;
- (void)removePasteboardItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldRemoveImage:(BOOL)shouldRemoveImage;
- (NSMutableArray *)itemsFromHistoryWithKey:(NSString *)historyKey;
@end

@interface SBApplication : NSObject
@property(nonatomic, readonly)NSString* bundleIdentifier;
@end

@interface UIApplication (Private)
- (SBApplication *)_accessibilityFrontMostApplication;
@end
Loading

0 comments on commit bba0f7f

Please sign in to comment.