Skip to content

Commit

Permalink
🚀 1.3.23
Browse files Browse the repository at this point in the history
  • Loading branch information
rodionovd committed Aug 18, 2022
1 parent 6c09d01 commit b672111
Show file tree
Hide file tree
Showing 53 changed files with 299 additions and 249 deletions.
179 changes: 83 additions & 96 deletions Sympli.sketchplugin/Contents/Sketch/Sympli.cocoascript
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 not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
<integer>0</integer>
<key>io.sympli.exportSymbolsUsingCanvasFrame</key>
<false/>
<key>io.sympli.exportArtboardsFromAllPagesOnEmptySelection</key>
<false/>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.3.22</string>
<string>1.3.23</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit b672111

Please sign in to comment.