Skip to content

Commit 1071b91

Browse files
committed
Removed custom commands to update the plugin
1 parent e704117 commit 1071b91

File tree

3 files changed

+5
-91
lines changed

3 files changed

+5
-91
lines changed

Google sheets content sync.sketchplugin/Contents/Sketch/defaults.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@
55
var defaultsKey = "com.davidwilliames.sketch-plugins.google-sheets-content-sync"
66

77
var defaultsURL = ''
8-
var defaultsLastUpdateCheckDay = 0
98

109
function fetchDefaults(documentID) {
1110
var allDefaults = NSUserDefaults.standardUserDefaults().dictionaryForKey(defaultsKey)
1211

13-
if (allDefaults) {
14-
if (allDefaults.lastUpdateCheckDay) {
15-
defaultsLastUpdateCheckDay = allDefaults.lastUpdateCheckDay
16-
}
17-
if (allDefaults[documentID]) {
18-
defaultsURL = allDefaults[documentID]
19-
}
12+
if (allDefaults && allDefaults[documentID]) {
13+
defaultsURL = allDefaults[documentID]
2014
}
2115
}
2216

2317
function saveDefaults(documentID) {
2418
var allDefaults = NSUserDefaults.standardUserDefaults().dictionaryForKey(defaultsKey)
2519

2620
var newDefaults = {
27-
lastUpdateCheckDay: defaultsLastUpdateCheckDay,
2821
[documentID]: defaultsURL
2922
}
3023

Google sheets content sync.sketchplugin/Contents/Sketch/main.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@import 'utilities.js'
33

44
var selection, doc, scriptPath, scriptFolder, app
5-
var manifestJSON, iconImage, sheetValues
5+
var iconImage, sheetValues
66

77
// Setup variables based on the context
88
function setup(context) {
@@ -12,36 +12,25 @@ function setup(context) {
1212
scriptFolder = scriptPath.stringByDeletingLastPathComponent()
1313
app = NSApplication.sharedApplication()
1414

15-
manifestJSON = getJSONFromFile(scriptFolder + "/manifest.json")
1615
iconImage = NSImage.alloc().initByReferencingFile(context.plugin.urlForResourceNamed("icon.png").path())
1716

1817
fetchDefaults(doc.hash())
19-
20-
// Return the opposite of if it was updated
21-
return !updateIfNeeded()
2218
}
2319

2420
// ****************************
2521
// Plugin command handler
2622
// ****************************
2723

2824
function run(context) {
29-
// If the user opted to update the plugin, then return
30-
if (!setup(context)) {
31-
return
32-
}
25+
setup(context)
3326

3427
// Ask the user to update their URL, then sync the content
3528
if (updateSheetURL())
3629
syncContent()
37-
3830
}
3931

4032
function importContent(context) {
41-
// If the user opted to update the plugin, then return
42-
if (!setup(context)) {
43-
return
44-
}
33+
setup(context)
4534

4635
// If there's currently no valid URL — ask the user to update it, then import it
4736
if (!validateURL()) {
@@ -50,7 +39,6 @@ function importContent(context) {
5039
} else {
5140
syncContent()
5241
}
53-
5442
}
5543

5644
function updateSheetURL() {
Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,5 @@
1-
// ****************************
2-
// Checking for updates
3-
// ****************************
4-
5-
// If an update is available - alert the user
6-
// return 'if the user opted to download an update'
7-
function updateIfNeeded() {
8-
9-
if (isTodayNewDay() && checkPluginUpdate()) {
10-
var alert = NSAlert.alloc().init()
11-
alert.setIcon(iconImage)
12-
alert.setMessageText("New Update available 🔥")
13-
alert.setInformativeText("There's a new update available for '" + manifestJSON.name + "'. Please download and install the new version.")
14-
alert.addButtonWithTitle("Download")
15-
alert.addButtonWithTitle("Cancel")
16-
if (alert.runModal() == '1000') {
17-
NSWorkspace.sharedWorkspace().openURL(NSURL.URLWithString(manifestJSON.homepage))
18-
return true
19-
}
20-
}
21-
22-
return false
23-
}
24-
25-
// Return if an update has not been checked for today yet
26-
function isTodayNewDay() {
27-
28-
var lastUpdateCheckDay = defaultsLastUpdateCheckDay
29-
var formatter = NSDateFormatter.alloc().init()
30-
formatter.setDateStyle(NSDateFormatterShortStyle)
31-
var today = formatter.stringFromDate(NSDate.date())
32-
33-
defaultsLastUpdateCheckDay = today
34-
35-
saveDefaults(doc.hash())
36-
37-
if (lastUpdateCheckDay) {
38-
return lastUpdateCheckDay != today
39-
} else {
40-
return true
41-
}
42-
}
43-
44-
// Check the remote repository for the manifest verion number
45-
// Return whether there is a new update available
46-
function checkPluginUpdate() {
47-
var newUpdateAvailable = false
48-
try {
49-
var response = getJSONFromURL('https://raw.githubusercontent.com/DWilliames/Google-sheets-content-sync-sketch-plugin/master/Google%20sheets%20content%20sync.sketchplugin/Contents/Sketch/manifest.json')
50-
if (response && response.version) {
51-
if (response.version.toString() != manifestJSON.version.toString()) {
52-
newUpdateAvailable = true
53-
}
54-
}
55-
} catch (e) {
56-
return false
57-
}
58-
return newUpdateAvailable
59-
}
60-
611
// Return a JSON object from a file path
622
function getJSONFromFile(filePath) {
633
var data = NSData.dataWithContentsOfFile(filePath)
644
return NSJSONSerialization.JSONObjectWithData_options_error(data, 0, nil)
655
}
66-
67-
// Return a json object from a URL
68-
function getJSONFromURL(url) {
69-
var request = NSURLRequest.requestWithURL(NSURL.URLWithString(url))
70-
var response = NSURLConnection.sendSynchronousRequest_returningResponse_error(request, nil, nil)
71-
return NSJSONSerialization.JSONObjectWithData_options_error(response, 0, nil)
72-
}

0 commit comments

Comments
 (0)