forked from mzeryck/Weather-Cal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather-cal.js
91 lines (67 loc) · 2.15 KB
/
weather-cal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-purple; icon-glyph: calendar;
/*
~
Welcome to Weather Cal. Run this script to set up your widget.
Add or remove items from the widget in the layout section below.
You can duplicate this script to create multiple widgets. Make sure to change the name of the script each time.
Happy scripting!
~
*/
// Specify the layout of the widget items.
const layout = `
row
column
date
sunset
battery
space
events
column(90)
current
future
space
`
/*
* CODE
* Be more careful editing this section.
* =====================================
*/
// Names of Weather Cal elements.
const codeFilename = "weather-cal-code"
const gitHubUrl = "https://raw.githubusercontent.com/mzeryck/Weather-Cal/main/weather-cal-code.js"
// Determine if the user is using iCloud.
let files = FileManager.local()
const iCloudInUse = files.isFileStoredIniCloud(module.filename)
// If so, use an iCloud file manager.
files = iCloudInUse ? FileManager.iCloud() : files
// Determine if the Weather Cal code exists and download if needed.
const pathToCode = files.joinPath(files.documentsDirectory(), codeFilename + ".js")
if (!files.fileExists(pathToCode)) {
const req = new Request(gitHubUrl)
const codeString = await req.loadString()
files.writeString(pathToCode, codeString)
}
// Import the code.
if (iCloudInUse) { await files.downloadFileFromiCloud(pathToCode) }
const code = importModule(codeFilename)
const custom = {
// Custom items and backgrounds can be added here.
}
// Run the initial setup or settings menu.
let preview
if (config.runsInApp) {
preview = await code.runSetup(Script.name(), iCloudInUse, codeFilename, gitHubUrl)
if (!preview) return
}
// Set up the widget.
const widget = await code.createWidget(layout, Script.name(), iCloudInUse, custom)
Script.setWidget(widget)
// If we're in app, display the preview.
if (config.runsInApp) {
if (preview == "small") { widget.presentSmall() }
else if (preview == "medium") { widget.presentMedium() }
else { widget.presentLarge() }
}
Script.complete()