Code Monkey home page Code Monkey logo

dynamic's People

Contributors

mhdhejazi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dynamic's Issues

Hide close/minimize/maximize button in NSWindow

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?

Missing License

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).

NSWindow in macCatalyst.

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)) 
} 

WARNING: Trying to access an unrecognized member: NSWorkspace.shared

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:

Screen Shot 2021-01-12 at 9 45 32 AM

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

Logging properties

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
    }
}

mouse tracking using NSView in Catalyst

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?

resize NSWindow after it is created

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.

Catalyst track scrollWheel with NSApp.publisher(for: \.currentEvent)

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

Mac Catalyst applicationShouldTerminateAfterLastWindowClosed

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

Big Sur breaks code

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:

Can I somehow use it for CLBeacon init method?

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

Making a C# binding from Dynamic Swift framework

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?

How do I access the NSWindow.styleMask

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.

Does not compile on watchOS

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

Dynamic KeyPath

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

Catalyst NSStatusBar with NSStatusBar not working

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?

Mac Catalyst with menu-bar app in NSPopover

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:

Screen Shot 2021-01-29 at 20 21 27

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

Problem with M1

Screenshot 2023-05-09 at 12 26 53

I have this issue when I try to run in my Macbook Pro with M1 Pro.

What can I do?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.