Skip to content

Commit

Permalink
Added clear keyboard cache button
Browse files Browse the repository at this point in the history
  • Loading branch information
ginsudev committed Jan 29, 2023
1 parent 203320f commit 6412171
Show file tree
Hide file tree
Showing 12 changed files with 614 additions and 22 deletions.
28 changes: 20 additions & 8 deletions WDBFontOverwrite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
4F4E64A7295F9AB600D4F04D /* CustomFontsScene.ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F4E64A6295F9AB600D4F04D /* CustomFontsScene.ViewModel.swift */; };
4FD690952986367C00B751B2 /* grant_full_disk_access.m in Sources */ = {isa = PBXBuildFile; fileRef = 4FD690942986367C00B751B2 /* grant_full_disk_access.m */; };
4FD690992986395B00B751B2 /* helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 4FD690982986395B00B751B2 /* helpers.m */; };
4FE5EF312963E460003384EC /* NoticeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE5EF302963E460003384EC /* NoticeView.swift */; };
4FE5EF3329640075003384EC /* WDBImportCustomFontPickerViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE5EF3229640075003384EC /* WDBImportCustomFontPickerViewControllerDelegate.swift */; };
4FE5EF3529653188003384EC /* FontMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE5EF3429653188003384EC /* FontMap.swift */; };
Expand All @@ -22,7 +24,7 @@
4FF28A0E2967955400143640 /* PresetFontsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A0D2967955400143640 /* PresetFontsScene.swift */; };
4FF28A102967956300143640 /* PresetFontsScene.ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A0F2967956300143640 /* PresetFontsScene.ViewModel.swift */; };
4FF28A1229679EEC00143640 /* ExplanationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A1129679EEC00143640 /* ExplanationView.swift */; };
4FF28A142967AA2D00143640 /* RespringButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A132967AA2D00143640 /* RespringButton.swift */; };
4FF28A142967AA2D00143640 /* ActionButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A132967AA2D00143640 /* ActionButtons.swift */; };
4FF28A162967B77800143640 /* _UIKeyboardCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 4FF28A152967B77800143640 /* _UIKeyboardCache.m */; };
C55CF776295BA9B1000DE71C /* BrotliPadding.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55CF775295BA9B1000DE71C /* BrotliPadding.swift */; };
C5A95F46295964AE00C58FDB /* PreviewFonts in Resources */ = {isa = PBXBuildFile; fileRef = C5A95F45295964AE00C58FDB /* PreviewFonts */; };
Expand All @@ -37,6 +39,10 @@

/* Begin PBXFileReference section */
4F4E64A6295F9AB600D4F04D /* CustomFontsScene.ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFontsScene.ViewModel.swift; sourceTree = "<group>"; };
4FD690942986367C00B751B2 /* grant_full_disk_access.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = grant_full_disk_access.m; sourceTree = "<group>"; };
4FD69096298637D400B751B2 /* grant_full_disk_access.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = grant_full_disk_access.h; sourceTree = "<group>"; };
4FD690972986394200B751B2 /* helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = helpers.h; sourceTree = "<group>"; };
4FD690982986395B00B751B2 /* helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = helpers.m; sourceTree = "<group>"; };
4FE5EF302963E460003384EC /* NoticeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeView.swift; sourceTree = "<group>"; };
4FE5EF3229640075003384EC /* WDBImportCustomFontPickerViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WDBImportCustomFontPickerViewControllerDelegate.swift; sourceTree = "<group>"; };
4FE5EF3429653188003384EC /* FontMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontMap.swift; sourceTree = "<group>"; };
Expand All @@ -51,7 +57,7 @@
4FF28A0D2967955400143640 /* PresetFontsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetFontsScene.swift; sourceTree = "<group>"; };
4FF28A0F2967956300143640 /* PresetFontsScene.ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresetFontsScene.ViewModel.swift; sourceTree = "<group>"; };
4FF28A1129679EEC00143640 /* ExplanationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExplanationView.swift; sourceTree = "<group>"; };
4FF28A132967AA2D00143640 /* RespringButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RespringButton.swift; sourceTree = "<group>"; };
4FF28A132967AA2D00143640 /* ActionButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionButtons.swift; sourceTree = "<group>"; };
4FF28A152967B77800143640 /* _UIKeyboardCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = _UIKeyboardCache.m; sourceTree = "<group>"; };
4FF28A172967B78600143640 /* _UIKeyboardCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _UIKeyboardCache.h; sourceTree = "<group>"; };
C55CF775295BA9B1000DE71C /* BrotliPadding.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = BrotliPadding.swift; sourceTree = "<group>"; tabWidth = 4; usesTabs = 0; };
Expand Down Expand Up @@ -109,7 +115,7 @@
4FF28A0F2967956300143640 /* PresetFontsScene.ViewModel.swift */,
4FE5EF302963E460003384EC /* NoticeView.swift */,
4FF28A1129679EEC00143640 /* ExplanationView.swift */,
4FF28A132967AA2D00143640 /* RespringButton.swift */,
4FF28A132967AA2D00143640 /* ActionButtons.swift */,
);
path = MainInterface;
sourceTree = "<group>";
Expand Down Expand Up @@ -165,6 +171,10 @@
C5C9A7962959261200466D87 /* Assets.xcassets */,
4FF28A152967B77800143640 /* _UIKeyboardCache.m */,
4FF28A172967B78600143640 /* _UIKeyboardCache.h */,
4FD690942986367C00B751B2 /* grant_full_disk_access.m */,
4FD69096298637D400B751B2 /* grant_full_disk_access.h */,
4FD690982986395B00B751B2 /* helpers.m */,
4FD690972986394200B751B2 /* helpers.h */,
C5C9A7A92959417100466D87 /* vm_unaligned_copy_switch_race.c */,
C5C9A7AB2959438600466D87 /* vm_unaligned_copy_switch_race.h */,
C5C9A7A82959417100466D87 /* WDBFontOverwrite-Bridging-Header.h */,
Expand Down Expand Up @@ -261,13 +271,15 @@
C55CF776295BA9B1000DE71C /* BrotliPadding.swift in Sources */,
4FE5EF3E29664537003384EC /* ProgressManager.swift in Sources */,
4FE5EF452966AD87003384EC /* FontDiscoveryScene.swift in Sources */,
4FD690992986395B00B751B2 /* helpers.m in Sources */,
4FF28A1229679EEC00143640 /* ExplanationView.swift in Sources */,
C5C9A7932959261000466D87 /* WDBFontOverwriteApp.swift in Sources */,
4FE5EF38296561A5003384EC /* FileEditorView.swift in Sources */,
4FD690952986367C00B751B2 /* grant_full_disk_access.m in Sources */,
4FF28A162967B77800143640 /* _UIKeyboardCache.m in Sources */,
4FE5EF472966AD98003384EC /* FontDiscoveryScene.ViewModel.swift in Sources */,
C5C9A7AA2959417100466D87 /* vm_unaligned_copy_switch_race.c in Sources */,
4FF28A142967AA2D00143640 /* RespringButton.swift in Sources */,
4FF28A142967AA2D00143640 /* ActionButtons.swift in Sources */,
4FE5EF4129668C9C003384EC /* AlignedRowContentView.swift in Sources */,
4FE5EF492966AE1A003384EC /* FontDiscoveryCard.swift in Sources */,
4FE5EF3529653188003384EC /* FontMap.swift in Sources */,
Expand Down Expand Up @@ -414,7 +426,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -423,7 +435,7 @@
"$(inherited)",
"$(PROJECT_DIR)/WDBFontOverwrite",
);
MARKETING_VERSION = 1.10.4;
MARKETING_VERSION = 1.10.6;
PRODUCT_BUNDLE_IDENTIFIER = com.ginsu.WDBFontOverwrite;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -452,7 +464,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -461,7 +473,7 @@
"$(inherited)",
"$(PROJECT_DIR)/WDBFontOverwrite",
);
MARKETING_VERSION = 1.10.4;
MARKETING_VERSION = 1.10.6;
PRODUCT_BUNDLE_IDENTIFIER = com.ginsu.WDBFontOverwrite;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
2 changes: 2 additions & 0 deletions WDBFontOverwrite/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
</dict>
</dict>
</array>
<key>NSAppleMusicUsageDescription</key>
<string>WDBFontOverwrite</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
//
// RespringButton.swift
// ActionButtons.swift
// WDBFontOverwrite
//
// Created by Noah Little on 6/1/2023.
//

import SwiftUI

struct RespringButton: View {
struct ActionButtons: View {
var body: some View {
if #available(iOS 15, *) {
Button {
clearKBCache()
} label: {
AlignedRowContentView(
imageName: "trash",
text: "Clear keyboard cache"
)
}
}
Button {
respring()
} label: {
Expand All @@ -19,6 +29,16 @@ struct RespringButton: View {
}
}

private func clearKBCache() {
grant_full_disk_access { error in
if error != nil {
print("can't get disk access")
} else {
_UIKeyboardCache.purge()
}
}
}

private func respring() {
let sharedApplication = UIApplication.shared
let windows = sharedApplication.windows
Expand All @@ -30,8 +50,8 @@ struct RespringButton: View {
}
}

struct RespringButton_Previews: PreviewProvider {
struct ActionButtons_Previews: PreviewProvider {
static var previews: some View {
RespringButton()
ActionButtons()
}
}
2 changes: 1 addition & 1 deletion WDBFontOverwrite/MainInterface/CustomFontsScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct CustomFontsScene: View {
text: "Manage imported fonts"
)
}
RespringButton()
ActionButtons()
} header: {
Text("Actions")
} footer: {
Expand Down
2 changes: 1 addition & 1 deletion WDBFontOverwrite/MainInterface/PresetFontsScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private extension PresetFontsScene {

private var actionSection: some View {
Section {
RespringButton()
ActionButtons()
} header: {
Text("Actions")
} footer: {
Expand Down
1 change: 1 addition & 0 deletions WDBFontOverwrite/WDBFontOverwrite-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#import "vm_unaligned_copy_switch_race.h"
#import "_UIKeyboardCache.h"
#import "grant_full_disk_access.h"
17 changes: 10 additions & 7 deletions WDBFontOverwrite/WDBFontOverwriteApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ struct WDBFontOverwriteApp: App {
}
}
.environmentObject(progressManager)
.alert("Import log", isPresented: $progressManager.isPresentedResultsAlert, actions: {
Button("Dismiss", role: .cancel) { }
}, message: {
Text(logMessage)
})
.alert(
isPresented: $progressManager.isPresentedResultsAlert,
content: {
Alert(
title: Text("Import log"),
message: Text(logMessage),
dismissButton: .cancel(Text("Dismiss"))
)
}
)
}
}

private var logMessage: String {
var message = ""

for result in progressManager.importResults {
switch result {
case .success:
Expand All @@ -47,7 +51,6 @@ struct WDBFontOverwriteApp: App {
message += "\(string)\n"
}
}

return message
}
}
1 change: 0 additions & 1 deletion WDBFontOverwrite/_UIKeyboardCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@implementation _UIKeyboardCache

+ (void)purge {
// TODO: - Find a way to make this work when sanbox is no longer a problem...
void *handle = dlopen("/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore", RTLD_NOW);
if (handle) {
NSObject *kbCache = [objc_getClass("UIKeyboardCache") performSelector:@selector(sharedInstance)];
Expand Down
13 changes: 13 additions & 0 deletions WDBFontOverwrite/grant_full_disk_access.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// grant_full_disk_access.h
// WDBFontOverwrite
//
// Created by Noah Little on 29/1/2023.
//
@import Foundation;
#ifndef grant_full_disk_access_h
#define grant_full_disk_access_h

void grant_full_disk_access(void (^completion)(NSError* _Nullable));

#endif /* grant_full_disk_access_h */
Loading

0 comments on commit 6412171

Please sign in to comment.