Skip to content

Delegating #15

Description

@agsh

Hi! I'm trying to find all scan devices using ImageCaptureCore, but the code below doesn't call the delegate's methods. And the similar Objective-C code does.
Maybe I'm wrong somewhere because header file(https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10.7.sdk/System/Library/Frameworks/ImageCaptureCore.framework/Versions/A/Headers/ICDeviceBrowser.h) is slight different from your example with NSFileManager

const objc = require('../src/index');

const ICDeviceLocationTypeMaskLocal     = 0x00000100;
const ICDeviceLocationTypeMaskShared    = 0x00000200;
const ICDeviceLocationTypeMaskBonjour   = 0x00000400;
const ICDeviceLocationTypeMaskBluetooth = 0x00000800;
const ICDeviceLocationTypeMaskRemote    = 0x0000FE00;
const ICDeviceTypeMaskCamera            = 0x00000001;
const ICDeviceTypeMaskScanner           = 0x00000002;

objc.import('ImageCaptureCore');

const {
    ICDeviceBrowser
} = objc;

const DeviceBrowserDelegate = objc.createClass('DeviceBrowserDelegate', 'NSObject', {
    "deviceBrowser:didAddDevice:moreComing:": (self, cmd, fileManager, srcPath, dstPath) => {
        console.log("deviceBrowser:didAddDevice:moreComing:");
        return 1;
    },
    "deviceBrowser:didRemoveDevice:moreGoing:": (self, cmd, fileManager, srcPath, dstPath) => {
        console.log("deviceBrowser:didAddDevice:moreComing:");
        return 1;
    },
    _encodings: {
        "deviceBrowser:didAddDevice:moreComing:": ['v', ['@', ':', '@', '@', 'c']],
        "deviceBrowser:didRemoveDevice:moreGoing:": ['v', ['@', ':', '@', '@', 'c']]
    }
});

const deviceBrowser = ICDeviceBrowser.alloc().init();
const delegate = DeviceBrowserDelegate.new();
deviceBrowser.setDelegate_(delegate);


const mask = ICDeviceTypeMaskScanner | ICDeviceLocationTypeMaskLocal | ICDeviceLocationTypeMaskShared | ICDeviceLocationTypeMaskBonjour | ICDeviceLocationTypeMaskRemote;
deviceBrowser.setBrowsedDeviceTypeMask_(mask);


deviceBrowser.start();

setInterval(() => {
    console.log(deviceBrowser.isBrowsing());
}, 2000);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions