Skip to content

Commit

Permalink
check updates function added
Browse files Browse the repository at this point in the history
  • Loading branch information
keremciu committed Jun 12, 2016
1 parent 55330b6 commit 361afa3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion iconfont.sketchplugin/Contents/Sketch/add_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var onRun = function(context) {
var fonts = [json objectForKey:@"fonts"]

// 1. create a wrapper windows
var wrapper = Library.Widgets.window("Add an icon - ", "Select an icon")
var wrapper = Library.Widgets.window("Add an icon from all", "Select an icon")

// 2. create list properties
var allIcons = [NSMutableArray array];
Expand Down
5 changes: 3 additions & 2 deletions iconfont.sketchplugin/Contents/Sketch/add_grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var handleFont = function(context) {

var onRun = function(context,path,fontname) {

// check updates
tools.checkPluginUpdate(context)

var plugin = context.plugin
var doc = context.document
var selection = context.selection.firstObject()
Expand Down Expand Up @@ -127,6 +130,4 @@ var onRun = function(context,path,fontname) {
Library.create.icon(doc,selection,fontname,name,icon)
}

tools.checkPluginUpdate()

};
21 changes: 15 additions & 6 deletions iconfont.sketchplugin/Contents/Sketch/const/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ var Library = {
};

var tools = {
appVersion: "4.0.1",
versionComponents : function() {
var info = [[NSBundle mainBundle] infoDictionary];
var items = [[(info["CFBundleShortVersionString"]) componentsSeparatedByString:"."] mutableCopy];
Expand All @@ -495,16 +494,26 @@ var tools = {
responseObj = [NSJSONSerialization JSONObjectWithData:response options:nil error:nil]
return responseObj
},
checkPluginUpdate: function(){
try{
checkPluginUpdate: function(context) {
var doc = context.document
var scriptFullPath = context.scriptPath
var directoryPlugin = [scriptFullPath stringByDeletingLastPathComponent]

// 9. Fetch data of manifest.json
var manifestPath = directoryPlugin + "/manifest.json"
var data = [NSData dataWithContentsOfFile:manifestPath]
manifest = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]

try {
var response = this.getJSONFromURL('https://raw.githubusercontent.com/keremciu/sketch-iconfont/master/iconfont.sketchplugin/Contents/Sketch/manifest.json')
var pluginVersion = manifest.version.toString()
if(response && response.version) {
var rgx = new RegExp("\\d","g");
var removeVersion = parseFloat(response.version.match(rgx).join(""))
var installedVersion = parseFloat(this.appVersion.match(rgx).join(""))
if (removeVersion > installedVersion) [doc showMessage:"New plugin update is available! Visit github.com/keremciu/sketch-iconfont"]
var installedVersion = parseFloat(pluginVersion.match(rgx).join(""))
if (removeVersion > installedVersion) [doc showMessage:"New plugin update " + response.version + " is available! Visit github.com/keremciu/sketch-iconfont"]
}
}catch(e){
} catch(e){
log(e);
}
}
Expand Down
3 changes: 3 additions & 0 deletions iconfont.sketchplugin/Contents/Sketch/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

var onRun = function(context) {

// check updates
tools.checkPluginUpdate(context)

var plugin = context.plugin
var doc = context.document
var page = doc.currentPage()
Expand Down
3 changes: 3 additions & 0 deletions iconfont.sketchplugin/Contents/Sketch/learn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

var onRun = function(context) {

// check updates
tools.checkPluginUpdate(context)

// 1. Get selected layer
var plugin = context.plugin
var doc = context.document
Expand Down
5 changes: 3 additions & 2 deletions iconfont.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
{
"script" : "add_all.js",
"handler" : "onRun",
"shortcut" : "cmd ctrl a",
"name" : "All Insert",
"identifier" : "add_all"
}
Expand All @@ -61,8 +62,8 @@
]
},
"identifier" : "com.keremciu.sketch.iconfont",
"version" : "4.0.1",
"version" : "4.0.5",
"description" : "Use icons like a boss.",
"name" : "Icons",
"authorEmail" : "[email protected]"
}
}

0 comments on commit 361afa3

Please sign in to comment.