mhdhejazi / dynamic Goto Github PK
View Code? Open in Web Editor NEWCall hidden/private API in style! The Swift way.
Home Page: https://medium.com/@mhdhejazi/calling-ios-and-macos-hidden-api-in-style-1a924f244ad1
License: Apache License 2.0
Call hidden/private API in style! The Swift way.
Home Page: https://medium.com/@mhdhejazi/calling-ios-and-macos-hidden-api-in-style-1a924f244ad1
License: Apache License 2.0
UIKit WKWebView has lots of issues which AppKit's WKWebView don't. So I want to use AppKit WKWebView in UIKit my project is macatalyst.
Is this possible with your library ?
I wanna call method beginSheetModalForWindow:completionHandler:
in NSOpenPanel object, but app crashed in Invocation.swift
file at line 139.
How to pass object?
I've been trying to remove/hide the 3 top-left buttons of the view (close, minimize and maximize, but I stuck.
This is my current code, not working ...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
#if targetEnvironment(macCatalyst)
Dynamic(self.view.window?.nsWindow).standardWindowButton(0).isHidden = true
Dynamic(self.view.window?.nsWindow).standardWindowButton(1).isHidden = true
Dynamic(self.view.window?.nsWindow).standardWindowButton(2).isHidden = true
#endif
}
Did anyone manage to solve this?
Could not find any mention of license anywhere?
I hope the license is Apache 2.0 (cause does not need me to mention contribution, I think).
Hello, Just used your dynamic repo it is amazing i appreciate your work.
But whenever i try to access NSWindow i get error "unexpectedly found nil while unwrapping an optional value".
Here is my code :
extension UIWindow {
var nsWindow: NSObject? {
Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self)
}
}
func setScreen(){
let ns = self.window?.nsWindow
Dynamic(ns!).setFrame(CGRect(250,200,1200,800), display: true)
let frame = Dynamic(ns!).frame.asCGRect!
let size = frame.size
Dynamic(ns!).setAspectRatio(CGSize(1.0, size.height/size.width))
}
I have your package installed and imported into my project, and I'm trying to use it to open a folder in Finder from a new SwiftUI app. I tried hooking it up to a menu item like so:
The menu and button appears just fine, but when I click it this appears in the console:
WARNING: Trying to access an unrecognized member: NSWorkspace.shared
This is on macOS 11.1 with Xcode 12.3
thank you for coming up with such a novel way of exploring / calling APIs. When searching for the right API to call, it's sometimes useful to log an object's properties. Is this something you'd consider adding to the framework?
extension NSObject {
var properties: [String] {
var count : UInt32 = 0
let typeOf = type(of: self)
guard let properties: UnsafeMutablePointer<objc_property_t> = class_copyPropertyList(typeOf, &count) else { return [] }
var names: [String] = []
for i in 0..<Int(count) {
let property : objc_property_t = properties[i]
guard let name = NSString(utf8String: property_getName(property)) as String? else { continue }
names.append(name as String)
}
free(properties)
return names
}
}
I want to check whether the window is in full screen or not in mac Catalyst. How can I do that using dynamic?
Can one get at a UIView's underlying NSVIew? (assuming that this is the case) using dynamics. Want to trigger an event if the mouse is moved at all using NSTrackingArea. Or is there something simpler?
How can I interact with menu bar in catalyst with Dynamic framework?
I'm working on an app that opens the app on a fixed frame window size, but i want to let the user to resize the window after it is created. the problem is that i don't have access to styleMask.
This is the code I use for tracking scrollWheel:
NSApp.publisher(for: \.currentEvent)
.filter { event in event?.type == .scrollWheel }
.throttle(for: .milliseconds(1), scheduler: DispatchQueue.main, latest: true)
.sink { event in
guard let event = event else {
return
}
}
.store(in: &bag)
for catalyst I've tried smth like that:
Dynamic.NSApp.publisher(for: \Dynamic.NSApplication.currentEvent).sink { v in
gives error Segmentation fault: 11
or like that:
Dynamic.NSApp.publisher(for: \NSApplication.currentEvent).sink { v in
gives 'currentEvent' is unavailable in Mac Catalyst
Hi guys,
I've got another question, with Dynamic on Mac Catalyst is it possible to include applicationShouldTerminateAfterLastWindowClosed in the AppDelegate?
#if targetEnvironment(macCatalyst)
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
// ...
}
#endif
Thanks in advance
The following code (use to position and size the main window after launch) now crashes
delay(0.1) {
let ns = self.window?.nsWindow
Dynamic(ns!).setFrame(CGRect(200,200,1200,800), display: true)
let frame = Dynamic(ns!).frame.asCGRect!
let size = frame.size
Dynamic(ns!).setAspectRatio(CGSize(1.0, size.height/size.width))
}
with the following error
2020-11-17 21:42:22.832850-0600 ChordCalc Mac[11229:361126] Metal API Validation Enabled
WARNING: Trying to access an unrecognized member: UINSWindowProxy.setFrame:display:
Just only writing this line:
let task = Dynamic.Process()
my program crash with this debug message in object.
Problem: I need CLBeacon private init method:
-(id)initWithProximityUUID:(id)arg1 major:(id)arg2 minor:(id)arg3 proximity:(long long)arg4 accuracy:(double)arg5 rssi:(long long)arg6 ;
that I have found here
So does not work:
let beacon = Dynamic(className: "CLBeacon").initWithProximityUUID("uuid", major: 1, minor: 1, proximity: 1, accuracy:0.4, rssi: 50)
// use beacon here
Please help
I'm trying to use Dynamic in Visual Studio with C# which involves using a tool called sharpie which consumes a .framework's header files, but in the Dynamic source code i see no header files. I am not used to using swift so i don't know if this is conventional, but i was hoping you could assist by helping my construct the header file or if you could provide the headers or even better a constructed .framework file from the source code?
Thanks for this awesome framework!
I need to detect if the current window is in full screen mode. I used to get this info in AppKit from window.styleMask.contains(.fullScreen)
.
How do I accomplish this using Dynamic?
Thanks in advance.
Hello,
Great library!
The project does not compile for watchOS. There are complaints about certain types that did not exist in watchOS 2.0 (the minimum target), and usage of CATransform3D
, which isnβt exposed on watchOS.
Thanks
Just wondering if you library can help with Swift not supporting a dynamic KeyPath, e.g. below the "key" is not a property of an object so the \key syntax cannot be used:
let dict = NSMutableDictionary(object: "value1", forKey: NSString("key"))
dict.observe(keyPath:KeyPath("key")) { (dict, change) in // compilation error
}
dict.setObject("value2", forKey: NSString("key"))
'KeyPath<Root, Value>' cannot be constructed because it has no accessible initializers
This problem is also mentioned on the Swift Forums:
How can I make KeyPath from String? https://forums.swift.org/t/how-can-i-make-keypath-from-string/19658
Hi guys, I've tried to have the NSStatusBar working with a NSStatusBar on a project developed with React Native and Catalyst, but the icon doesn't appear.
Here is the code, it compiles and the app runs successfully, but no icon appear on the top right corner of the screen
import UIKit
import Dynamic
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bridge: RCTBridge!
let statusItem = Dynamic.NSStatusBar.system.statusItem(withLength:Dynamic.NSStatusItem.squareLength)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "myModule", initialProperties: nil, launchOptions: launchOptions)
let rootViewController = UIViewController()
rootViewController.view = rootView
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
statusItem.button.image = Dynamic.NSImage(named:Dynamic.NSImage.Name("iconbar"))
return true
}
}
Do you have any idea what I'm missing?
Hi, was wondering if/when you would be adding the privacy manifest to the SDK as per https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
I dont have any objects. How do i call this private api method CGSGetNumberOfDisplayModes from core graphics using Dynamic?
Thanks
Hi guys, I'm sorry if I'm flooding the issues here but at least I hope these may serve as reference for the ones to come π
Again with Mac Catalyst and React Native, I was trying to make a Menu-Bar app with Dynamic.NSPopover and Dynamic.NSVireController but it crashes badly:
Here is my AppDelegate
import UIKit
#if targetEnvironment(macCatalyst)
import Dynamic
import Cocoa
#endif
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bridge: RCTBridge!
#if targetEnvironment(macCatalyst)
let statusItem = Dynamic.NSStatusBar.systemStatusBar.statusItemWithLength(-1.0)
let popover = Dynamic.NSPopover()
#endif
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "myApp", initialProperties: nil, launchOptions: launchOptions)
// Code to make it work outside NSPopover
// ################
// let rootViewController = UIViewController()
// rootViewController.view = rootView
// self.window = UIWindow(frame: UIScreen.main.bounds)
// self.window?.rootViewController = rootViewController
// self.window?.makeKeyAndVisible()
// ################
#if targetEnvironment(macCatalyst)
statusItem.button.image = Dynamic.NSImage.imageNamed("iconbar")
statusItem.button.action = #selector(openApp(_:))
let rvc = Dynamic.NSViewController()
rvc.view = rootView
popover.contentViewController = rvc
popover.showRelativeToRect(statusItem.button.bounds, ofView: statusItem.button, preferredEdge: 1) // NSRectEdge.minY = 1
#endif
return true
}
#if targetEnvironment(macCatalyst)
@objc func openApp(_ sender: Any?) {
// Now it does nothing
}
#endif
}
#if targetEnvironment(macCatalyst)
extension UIWindow {
var nsWindow: NSObject? {
var nsWindow = Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self)
if #available(macOS 11, *) {
nsWindow = nsWindow.attachedWindow
}
return nsWindow.asObject
}
}
#endif
Any help would be appreciated. π
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.