-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
299 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,113 @@ | ||
var loadFramework = function(context) { | ||
var pluginRoot = context.scriptPath.stringByDeletingLastPathComponent(); | ||
log("Plugin root:" + pluginRoot); | ||
// | ||
// Sympli.cocoascript | ||
// Copyright © 2015-2022 Sympli. All rights reserved. | ||
// | ||
|
||
if ([pluginRoot rangeOfString:"Containers"].length != 0) { | ||
doc.showMessage("Mac App Store version of Sketch is unsupported. Please update Sketch to the latest version from official site."); | ||
return false; | ||
// MARK: - User Commands | ||
|
||
var exportArtboards = function(context) { | ||
run(context, "export"); | ||
} | ||
|
||
var exportDesignSystem = function(context) { | ||
run(context, "exportDesignSystem"); | ||
} | ||
|
||
var showTags = function(context) { | ||
run(context, "manageTags"); | ||
} | ||
|
||
var hideTags = function(context) { | ||
run(context, "hideTags"); | ||
} | ||
|
||
// MARK: - | ||
|
||
var run = function(context, mode) | ||
{ | ||
if (!validateSketchCompatibility()) { | ||
return; | ||
} | ||
|
||
if (NSClassFromString('Sympli') == null) { | ||
var framework = pluginRoot.stringByAppendingPathComponent("SympliSketchPlugin.framework") | ||
removeQuarantineFlag(framework) | ||
return [[NSBundle bundleWithPath:framework] load]; | ||
} else { | ||
return true; | ||
const document = context.document; | ||
const selection = context.selection; | ||
const installedPluginVersion = runningSympliPluginVersion(context); | ||
|
||
const loaded = loadNativeCodeBundle(context); | ||
if (!loaded) { | ||
document.showMessage("⚠️ Sympli: Unable to start the plugin (" + (installedPluginVersion || "unknown version") + "). Please update Sympli to the latest version and try again."); | ||
return; | ||
} | ||
|
||
const loadedPluginVersions = Sympli.sharedInstance().version(); | ||
if (![loadedPluginVersions isEqualToString:installedPluginVersion]) { | ||
document.showMessage("⚠️ Sympli: Please restart Sketch to finish the plugin update process."); | ||
return; | ||
} | ||
} | ||
|
||
var removeQuarantineFlag = function(path) { | ||
var xattr = "/usr/bin/xattr"; | ||
var args = ["-r", "-d", "com.apple.quarantine", path]; | ||
var task = [NSTask launchedTaskWithLaunchPath:xattr arguments:args]; | ||
task.waitUntilExit(); | ||
[[Sympli sharedInstance] invokeInMode:mode document:document selectedLayers:selection]; | ||
} | ||
|
||
var launchSympliPlugin = function(context, mode) { | ||
var doc = context.document; | ||
// MARK: - Utils | ||
|
||
var loadNativeCodeBundle = function(context) | ||
{ | ||
if (NSClassFromString('Sympli')) { | ||
return true | ||
} | ||
|
||
var removeQuarantineFlag = function(path) { | ||
const xattr = "/usr/bin/xattr"; | ||
const args = ["-r", "-d", "com.apple.quarantine", path]; | ||
const task = [NSTask launchedTaskWithLaunchPath:xattr arguments:args]; | ||
task.waitUntilExit(); | ||
} | ||
|
||
const root = context.scriptPath.stringByDeletingLastPathComponent(); | ||
const frameworkPath = root.stringByAppendingPathComponent("SympliSketchPlugin.framework") | ||
|
||
removeQuarantineFlag(frameworkPath) | ||
return [[NSBundle bundleWithPath:frameworkPath] load]; | ||
} | ||
|
||
// Show a warning when running on an unsupported version of Sketch | ||
var validateSketchCompatibility = function() | ||
{ | ||
var build = Number.MAX_VALUE; | ||
var appVersion = "Unknown"; | ||
|
||
if (NSClassFromString("MSApplicationMetadata") != null) { | ||
build = parseInt(MSApplicationMetadata.metadata().build); | ||
appVersion = MSApplicationMetadata.metadata().appVersion; | ||
} else if (NSClassFromString("BCSketchInfo") != null) { | ||
if (NSClassFromString("BCSketchInfo") != null) { | ||
// Sketch 72+ | ||
build = parseInt(BCSketchInfo.shared().metadata().build); | ||
appVersion = BCSketchInfo.shared().metadata().appVersion; | ||
} else if (NSClassFromString("MSApplicationMetadata") != null) { | ||
build = parseInt(MSApplicationMetadata.metadata().build); | ||
appVersion = MSApplicationMetadata.metadata().appVersion; | ||
} | ||
|
||
var hasntBeenActivatedYet = (NSClassFromString('Sympli') == null); | ||
var incompatible = (build < /* Sketch 46.2 build number */44496); | ||
const hasntBeenActivatedYet = (NSClassFromString('Sympli') == null); | ||
const incompatible = (build < /* Sketch 46.2 build number, see SMP-12358 */44496); | ||
|
||
if (hasntBeenActivatedYet && incompatible) { | ||
var alert = NSAlert.new() | ||
const alert = NSAlert.new() | ||
alert.alertStyle = NSCriticalAlertStyle; | ||
alert.setMessageText("Sympli requires Sketch 46.2, you are using Sketch " + appVersion); | ||
alert.setMessageText("Sympli requires Sketch 46.2, but you have Sketch " + appVersion); | ||
alert.setInformativeText("Sympli is incompatible with your version of Sketch. We recommend you to upgrade to a newer version if possible."); | ||
[alert addButtonWithTitle:@"Continue Anyway"]; | ||
[alert addButtonWithTitle:@"Cancel"]; | ||
if ([alert runModal] != NSAlertFirstButtonReturn) { | ||
return; | ||
return false; | ||
} | ||
} | ||
|
||
try { | ||
|
||
if ((doc.isDraft() || doc.fileURL()==nil)) { | ||
doc.showMessage("Sympli: Please save the document, so we have all your changes."); | ||
return; | ||
} | ||
|
||
var selectedArtboards = context.selection; | ||
if (![selectedArtboards count]) { | ||
selectedArtboards = [[doc currentPage] artboards]; | ||
} | ||
|
||
if (![selectedArtboards count]) { | ||
var app = [NSApplication sharedApplication]; | ||
[app displayDialog:"Please create an artboard for export." withTitle:"Sympli"] | ||
return; | ||
} | ||
|
||
var selectedArtboardsSelf = [selectedArtboards valueForKeyPath:@"[email protected]"]; | ||
if(selectedArtboardsSelf) { | ||
var notNSNullPredicate = [NSPredicate predicateWithFormat:@"self!=nil AND NOT self isKindOfClass: %@", [NSNull class]]; | ||
selectedArtboardsSelf = [selectedArtboardsSelf filteredArrayUsingPredicate:notNSNullPredicate]; | ||
} | ||
var selectedArtboardsIds = [selectedArtboardsSelf valueForKeyPath:@"@distinctUnionOfObjects.objectID"]; | ||
if (![selectedArtboardsIds count]) { | ||
doc.showMessage("Please select artboard to export."); | ||
return; | ||
} | ||
|
||
var loadFrameworkResult = loadFramework(context); | ||
log("Framework loaded: " + loadFrameworkResult); | ||
|
||
if (loadFrameworkResult) { | ||
var filePath = doc.fileURL().path(); | ||
log("Processing file: " + filePath); | ||
var plugin = context.plugin; | ||
var sympli = [[Sympli alloc] init]; | ||
if (![[sympli version] isEqualToString:[plugin version]]) { | ||
doc.showMessage("Please restart Sketch to finish plugin update."); | ||
return; | ||
} | ||
log("Initialized Sympli"); | ||
|
||
var artboards = [[selectedArtboards valueForKeyPath:@"[email protected]"] mutableCopy]; | ||
[artboards removeObjectIdenticalTo:[NSNull null]]; | ||
|
||
[sympli process:filePath withPath:"<this option is not used anymore and can be deleted>" andArtboards:selectedArtboardsIds document:doc artboards:artboards selection:context.selection mode:mode context: context]; | ||
log("call sympli: " + loadFrameworkResult); | ||
} | ||
} catch (err) { | ||
doc.showMessage("Sympli: Unknown error."); | ||
log(err); | ||
} | ||
} | ||
|
||
var exportDesignSystem = function(context) { | ||
launchSympliPlugin(context, "showLoginIfNeededThenRedirectToDSExportFlow"); | ||
return true; | ||
} | ||
|
||
var manageTags = function(context) { | ||
launchSympliPlugin(context, "manageTags"); | ||
} | ||
|
||
var hideTags = function(context) { | ||
launchSympliPlugin(context, "hideTags"); | ||
} | ||
var runningSympliPluginVersion = function(context) | ||
{ | ||
const plugin = context.plugin | ||
if ((plugin) && [plugin respondsToSelector:NSSelectorFromString("version")]) { | ||
return plugin.version(); | ||
} | ||
|
||
var onRun = function(context) { | ||
launchSympliPlugin(context, "export"); | ||
return null; | ||
} |
Binary file modified
BIN
+15 Bytes
(100%)
...liSketchPlugin.framework/Versions/A/Resources/AnalyticsWindow.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+5.47 KB
(100%)
...sketchplugin/Contents/Sketch/SympliSketchPlugin.framework/Versions/A/Resources/Assets.car
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+8 Bytes
(100%)
...lugin.framework/Versions/A/Resources/DisclosureViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...lugin.framework/Versions/A/Resources/DuplicatesViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+552 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/7sS-wL-dwK-view-VpR-e5-kbj.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+714 Bytes
(100%)
...ources/ExportDesignSystemFlow.storyboardc/7sS-wL-dwK-view-VpR-e5-kbj.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
-9 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/9DN-0r-01p-view-hkf-2n-OEd.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ources/ExportDesignSystemFlow.storyboardc/9DN-0r-01p-view-hkf-2n-OEd.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+141 Bytes
(110%)
...SketchPlugin.framework/Versions/A/Resources/ExportDesignSystemFlow.storyboardc/Info.plist
Binary file not shown.
Binary file modified
BIN
-14 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/JdM-QU-zyq-view-ch5-0K-Gli.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+244 Bytes
(100%)
...rtDesignSystemFlow.storyboardc/NSTabViewController-cpg-Q4-7Bm.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+374 Bytes
(100%)
...es/ExportDesignSystemFlow.storyboardc/NSTabViewController-cpg-Q4-7Bm.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...xportDesignSystemFlow.storyboardc/NSViewController-9DN-0r-01p.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...urces/ExportDesignSystemFlow.storyboardc/NSViewController-9DN-0r-01p.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...xportDesignSystemFlow.storyboardc/NSViewController-JdM-QU-zyq.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...urces/ExportDesignSystemFlow.storyboardc/NSViewController-JdM-QU-zyq.nib/keyedobjects.nib
Binary file not shown.
Binary file added
BIN
+1.31 KB
...xportDesignSystemFlow.storyboardc/NSViewController-pWS-zf-abd.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file added
BIN
+1.76 KB
...urces/ExportDesignSystemFlow.storyboardc/NSViewController-pWS-zf-abd.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...xportDesignSystemFlow.storyboardc/NSViewController-sFN-NY-OPa.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...urces/ExportDesignSystemFlow.storyboardc/NSViewController-sFN-NY-OPa.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+1 Byte
(100%)
...ortDesignSystemFlow.storyboardc/NSWindowController-3JF-DA-jHg.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ces/ExportDesignSystemFlow.storyboardc/NSWindowController-3JF-DA-jHg.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
-1 Byte
(100%)
...ExportDesignSystemFlow.storyboardc/Pf6-3G-vtK-view-Xp6-wB-h8G.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+2 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/QQP-Xq-sFp-view-Vd9-Hk-5Y2.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
-6 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/cwn-3l-dk0-view-BW8-0D-zTD.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+9 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/jXr-RO-nKu-view-aTt-qL-Nyx.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file added
BIN
+8.59 KB
...ExportDesignSystemFlow.storyboardc/pWS-zf-abd-view-teK-Cn-gWv.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file added
BIN
+10.3 KB
...ources/ExportDesignSystemFlow.storyboardc/pWS-zf-abd-view-teK-Cn-gWv.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+9 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/s3X-zw-EDC-view-Jb6-d6-bgL.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...ources/ExportDesignSystemFlow.storyboardc/s3X-zw-EDC-view-Jb6-d6-bgL.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
+4 Bytes
(100%)
...ExportDesignSystemFlow.storyboardc/sFN-NY-OPa-view-uL9-if-rME.nib/keyedobjects-101300.nib
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-6 Bytes
(100%)
...liSketchPlugin.framework/Versions/A/Resources/LoginController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+10 Bytes
(100%)
...chPlugin.framework/Versions/A/Resources/ProjectViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...pliSketchPlugin.framework/Versions/A/Resources/SAMLController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
-11 Bytes
(100%)
...lugin.framework/Versions/A/Resources/ScreenTagsViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+3 Bytes
(100%)
...ketchPlugin.framework/Versions/A/Resources/SettingsController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+13 Bytes
(100%)
...etchPlugin.framework/Versions/A/Resources/ShareViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+10 Bytes
(100%)
...ramework/Versions/A/Resources/SimpleBaselineChooserController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+796 Bytes
(100%)
...hPlugin.framework/Versions/A/Resources/SympliExportController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+1.2 KB
(100%)
...liSketchPlugin.framework/Versions/A/Resources/SympliExportController.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
-2 Bytes
(100%)
...framework/Versions/A/Resources/SympliFlowLayoutViewController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
-20 Bytes
(100%)
...gin.framework/Versions/A/Resources/SympliProcessingController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+991 Bytes
(100%)
...lugin.framework/Versions/A/Resources/SympliProjectsController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+1005 Bytes
(100%)
...lugin.framework/Versions/A/Resources/SympliProjectsController.nib/keyedobjects-110000.nib
Binary file not shown.
Binary file modified
BIN
+1.55 KB
(100%)
...SketchPlugin.framework/Versions/A/Resources/SympliProjectsController.nib/keyedobjects.nib
Binary file not shown.
Binary file modified
BIN
-9 Bytes
(100%)
...in.framework/Versions/A/Resources/SympliShareBundleController.nib/keyedobjects-101300.nib
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...tchplugin/Contents/Sketch/SympliSketchPlugin.framework/Versions/A/Resources/tools/optipng
Binary file not shown.
Binary file modified
BIN
+2.95 KB
(100%)
...i.sketchplugin/Contents/Sketch/SympliSketchPlugin.framework/Versions/A/SympliSketchPlugin
Binary file not shown.
Oops, something went wrong.