Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Release Beta version of Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunmangukiya committed Jul 9, 2017
1 parent 6d2a6c0 commit 5e1e88c
Show file tree
Hide file tree
Showing 31 changed files with 442 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Logodrop.sketchplugin/Contents/Resources/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"main.css": "static/css/main.e55939ff.css",
"main.css.map": "static/css/main.e55939ff.css.map",
"main.js": "static/js/main.4a03090d.js",
"main.js.map": "static/js/main.4a03090d.js.map",
"static\\media\\Lato-Black.ttf": "static/media/Lato-Black.77d35374.ttf",
"static\\media\\Lato-BlackItalic.ttf": "static/media/Lato-BlackItalic.6c522f09.ttf",
"static\\media\\Lato-Bold.ttf": "static/media/Lato-Bold.44dfe8cc.ttf",
"static\\media\\Lato-BoldItalic.ttf": "static/media/Lato-BoldItalic.1ba4767e.ttf",
"static\\media\\Lato-Hairline.ttf": "static/media/Lato-Hairline.db15ac79.ttf",
"static\\media\\Lato-HairlineItalic.ttf": "static/media/Lato-HairlineItalic.a567f4a8.ttf",
"static\\media\\Lato-Italic.ttf": "static/media/Lato-Italic.56c4cb26.ttf",
"static\\media\\Lato-Light.ttf": "static/media/Lato-Light.5b761f2d.ttf",
"static\\media\\Lato-LightItalic.ttf": "static/media/Lato-LightItalic.3d747d8b.ttf",
"static\\media\\Lato-Regular.ttf": "static/media/Lato-Regular.7f690e50.ttf",
"static\\media\\no-results.svg": "static/media/no-results.e43118a5.svg"
}
16 changes: 16 additions & 0 deletions Logodrop.sketchplugin/Contents/Resources/common/PlatformAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var app = app || {};

app.performAction = (action, data) => {
window.data = JSON.stringify(data);
window.location.hash = action;
window.location.hash = '#';
}

app.insertLogo = (logo) => {
app.performAction('INSERT_LOGO', logo);
}

app.showError = (error) => {
console.log(error);
alert("Error while fetching response from Internet. Please try again!");
}
Binary file not shown.
1 change: 1 addition & 0 deletions Logodrop.sketchplugin/Contents/Resources/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="./manifest.json"><link rel="shortcut icon" href="./favicon.ico"><title>React App</title><script type="text/javascript" src="./common/PlatformAPI.js"></script><script type="text/javascript">document.addEventListener('contextmenu', event => event.preventDefault());</script><link href="./static/css/main.e55939ff.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="./static/js/main.4a03090d.js"></script></body></html>
15 changes: 15 additions & 0 deletions Logodrop.sketchplugin/Contents/Resources/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
1 change: 1 addition & 0 deletions Logodrop.sketchplugin/Contents/Resources/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/appcast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Nudged</title>
<link>https://raw.githubusercontent.com/Iconscout/sketch-logos/master/appcast.xml</link>
<description>A Sketch plugin to easily edit your nudge distance settings.</description>
<language>en</language>
<item>
<title>2.0</title>
<description>
<![CDATA[
<ul>
<li>Changed Plugin Shortcut to Ctrl + Alt + n</li>
<li>Added Custom Nudge input</li>
<li>Added smarter UI with a number of usability enhancements</li>
<li>Added 'Reset' button to settings window</li>
<li>Added Quick Reset Shortcut Ctrl + Alt + 0</li>
<li>Added integration with Sketch App's Update System</li>
</ul>
]]>
</description>
<pubDate>Sat, Jun 3 2017 11:54:08 +0100</pubDate>
<enclosure url="https://github.com/KevinWoodhouse/sketch-nudged/archive/v2.0.zip" type="application/octet-stream" sparkle:version="2.0"/>
</item>
<item>
<title>1.0.1</title>
<description>
<![CDATA[
<ul>
<li>Added integration with Sketch Runner</li>
</ul>
]]>
</description>
<pubDate>Fri, 17 Mar 2017 12:02:53 +0000</pubDate>
<enclosure url="https://github.com/KevinWoodhouse/sketch-nudged/archive/v1.0.1.zip" type="application/octet-stream" sparkle:version="1.0.1"/>
</item>
<item>
<title>1.0</title>
<description>
<![CDATA[
<ul>
<li>First release of Sketch Nudged</li>
</ul>
]]>
</description>
<pubDate>Mon, 9 Jan 2017 12:10:42 +0000</pubDate>
<enclosure url="https://github.com/KevinWoodhouse/sketch-nudged/archive/v1.0.zip" type="application/octet-stream" sparkle:version="1.0"/>
</item>
</channel>
</rss>
80 changes: 80 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/common/MochaJSDelegate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// MochaJSDelegate.js
// MochaJSDelegate
//
// Created by Matt Curtis
// Copyright (c) 2015. All rights reserved.
//

var MochaJSDelegate = function(selectorHandlerDict){
var uniqueClassName = "MochaJSDelegate_DynamicClass_" + NSUUID.UUID().UUIDString();

var delegateClassDesc = MOClassDescription.allocateDescriptionForClassWithName_superclass_(uniqueClassName, NSObject);

delegateClassDesc.registerClass();

// Handler storage

var handlers = {};

// Define interface

this.setHandlerForSelector = function(selectorString, func){
var handlerHasBeenSet = (selectorString in handlers);
var selector = NSSelectorFromString(selectorString);

handlers[selectorString] = func;

if(!handlerHasBeenSet){
/*
For some reason, Mocha acts weird about arguments:
https://github.com/logancollins/Mocha/issues/28
We have to basically create a dynamic handler with a likewise dynamic number of predefined arguments.
*/

var dynamicHandler = function(){
var functionToCall = handlers[selectorString];

if(!functionToCall) return;

return functionToCall.apply(delegateClassDesc, arguments);
};

var args = [], regex = /:/g;
while(match = regex.exec(selectorString)) args.push("arg"+args.length);

dynamicFunction = eval("(function("+args.join(",")+"){ return dynamicHandler.apply(this, arguments); })");

delegateClassDesc.addInstanceMethodWithSelector_function_(selector, dynamicFunction);
}
};

this.removeHandlerForSelector = function(selectorString){
delete handlers[selectorString];
};

this.getHandlerForSelector = function(selectorString){
return handlers[selectorString];
};

this.getAllHandlers = function(){
return handlers;
};

this.getClass = function(){
return NSClassFromString(uniqueClassName);
};

this.getClassInstance = function(){
return NSClassFromString(uniqueClassName).new();
};

// Conveience

if(typeof selectorHandlerDict == "object"){
for(var selectorString in selectorHandlerDict){
this.setHandlerForSelector(selectorString, selectorHandlerDict[selectorString]);
}
}
};
69 changes: 69 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/common/Panel.cocoascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function showPanel(options) {
var context = options.context;
var webviewResource = options.webviewResource;
var panelSettings = options.panelSettings;
var delegateListeners = options.delegateListeners;

try {
var resourcePath = context.plugin.urlForResourceNamed(webviewResource).path();
var timestamp = Date.now();
var url = encodeURI('file://' + resourcePath + '#' + timestamp);

// Main window
var title = "Logodrop by Iconscout";
var identifier = "com.iconscout.logodrop";
var threadDictionary = NSThread.mainThread().threadDictionary();

if (threadDictionary[identifier]) {
return;
}

var frame = NSMakeRect(0, 0, panelSettings.width, panelSettings.height);

var panel = NSPanel.alloc().init();
panel.setTitle(title);
panel.setTitlebarAppearsTransparent(true);

panel.standardWindowButton(NSWindowCloseButton).setHidden(false);
panel.standardWindowButton(NSWindowMiniaturizeButton).setHidden(true);
panel.standardWindowButton(NSWindowZoomButton).setHidden(true);

panel.setFrame_display(frame, false);
panel.setStyleMask(NSTexturedBackgroundWindowMask | NSTitledWindowMask | NSClosableWindowMask);
panel.setBackgroundColor(panelSettings.backgroundColor);

threadDictionary[identifier] = panel;
COScript.currentCOScript().setShouldKeepAround_(true);

var contentView = panel.contentView();
var webView = WebView.alloc().initWithFrame(NSMakeRect(0, 0, panelSettings.width, panelSettings.height));

var delegate = new MochaJSDelegate(delegateListeners);

contentView.setWantsLayer(true);
contentView.layer().setFrame( contentView.frame() );
contentView.layer().setMasksToBounds(true);

webView.setBackgroundColor(panelSettings.backgroundColor);
webView.setFrameLoadDelegate_(delegate.getClassInstance());
webView.setMainFrameURL_(url);

contentView.addSubview(webView);

var closeButton = panel.standardWindowButton(NSWindowCloseButton);
closeButton.setCOSJSTargetFunction(function(sender) {
COScript.currentCOScript().setShouldKeepAround(false);
threadDictionary.removeObjectForKey(identifier);
panel.close();
});
closeButton.setAction("callAction:");

panel.becomeKeyWindow();
panel.setLevel(NSFloatingWindowLevel);
panel.center();
panel.makeKeyAndOrderFront(nil);

} catch(e) {
log(e);
}
}
37 changes: 37 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/common/PlaceLogo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function placeLogo(logo, context) {
var logoUrl = logo.svg_file;
var selection = context.selection;
var selectedShape = [selection objectAtIndex:0];
var doc = context.document;
var selectedFrame = selectedShape.frame();
var svgImporter = MSSVGImporter.svgImporter();

var fileURL = NSURL.URLWithString(logoUrl);
svgImporter.prepareToImportFromURL(fileURL);
var importedSVGLayer = svgImporter.importAsLayer();
importedSVGLayer.name = logo.name;

// Scale SVG to selection frame
var svgFrame = importedSVGLayer.frame();
var ratio = svgFrame.width() / svgFrame.height();
var newWidth = selectedFrame.width();
var newHeight = newWidth / ratio;
if (newHeight > selectedFrame.height()) {
newHeight = selectedFrame.height();
newWidth = newHeight * ratio;
}

// Center in selection frame
[svgFrame setX:selectedFrame.x() + selectedFrame.width() / 2 - newWidth / 2];
[svgFrame setY:selectedFrame.y() + selectedFrame.height() / 2 - newHeight / 2];
[svgFrame setWidth:newWidth];
[svgFrame setHeight:newHeight];

// Add label layer
var page = doc.currentPage();
var canvas = page.currentArtboard() || page;
canvas.addLayers([importedSVGLayer]);

// Remove selection frame
selectedShape.removeFromParent();
}
16 changes: 16 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/common/SelectedShape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function selectedShape(context) {
var selection = context.selection;
var doc = context.document;

if (selection.count() != 1) {
[doc showMessage:'Please select a layer with a single shape'];
}

var selectedShape = [selection objectAtIndex:0];
if (! [selectedShape isKindOfClass:[MSShapeGroup class]]) {
[doc showMessage:'Selected layer is not a shape layer'];
return;
}

return selectedShape;
}
36 changes: 36 additions & 0 deletions Logodrop.sketchplugin/Contents/Sketch/main.cocoascript
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@import 'common/MochaJSDelegate.js';
@import 'common/Panel.cocoascript';
@import 'common/PlaceLogo.js';
@import 'common/SelectedShape.js';

function searchLogos(context) {
var webviewResource = 'index.html';
var panelSettings = {
width: 390,
height: 498,
backgroundColor: NSColor.whiteColor()
};

var delegateListeners = {
"webView:didChangeLocationWithinPageForFrame:": function(webView, webFrame) {
var panel = webView.superview().window();
var windowObject = webView.windowScriptObject();
var request = NSURL.URLWithString(webView.mainFrameURL()).fragment();

var data = windowObject.valueForKey("data");

var logo = JSON.parse(data);

placeLogo(logo, context);

log(data);
}
}

showPanel({
context: context,
webviewResource: webviewResource,
panelSettings: panelSettings,
delegateListeners: delegateListeners
});
}
Loading

0 comments on commit 5e1e88c

Please sign in to comment.