SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

APIs Missing: Data supplier

Open matteogratton opened this issue 3 years ago • 0 comments

It is currently pretty hard to add Data Suppliers to Sketch via plugin.

There are several issues:

  1. the path URL of the JSON/TXT file should be managed with NSURL: const url = NSURL.fileURLWithPath(filePath);

  2. the dataSupplyManager should be called with internal code: const dataManager = AppController.sharedInstance().dataSupplierManager();

  3. the script should control if the dataSupplyManager could be added and if so add it with other native funcions:

if (dataManager.canAddLocalDataGroupWithURL(url)) {
    const dataSupplierGroup =
        MSLocalDataSupplierGroup.localDataSupplierGroupFromFileSystemURL_dataSupplierDelegate_error_(
            url,
            dataManager,
            nil
        );
    if (dataSupplierGroup) {
        dataManager.addLocalDataSupplierGroup(dataSupplierGroup);
    }
}

it would be nice to have an API that just need the path of the document to be added and makes all the check and add them. Something like: let dataManager = sketch.DataManager.add(filePath)

Also the option to remove them: sketch.DataManager.remove(filePath) or, if the variable exists: dataManager.remove()

It would also be nice to be abe to add their icon in some ways: sketch.DataManager.add(filePath, iconFilePath) or if already created datamanager.icon = iconfilePath

matteogratton avatar Jun 24 '22 09:06 matteogratton