Skip to content

Commit

Permalink
Modified URLs for Feature Suggestion #170 (#172)
Browse files Browse the repository at this point in the history
* Added check for cache files existing but being blank

* Modified urls for Feature #170

* Incorporated feature request #169

* Incorporated feature #151

* Incorporated feature request #107
  • Loading branch information
epizzarello authored Jul 27, 2022
1 parent dbbe684 commit 2bff7cf
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions weather-cal-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,8 @@ const weatherCal = {
if (event.title.startsWith("Canceled:")) { return false }
if (event.isAllDay) { return eventSettings.showAllDay }

const minutesAfter = parseInt(eventSettings.minutesAfter) * 60000 || 0
// If they leave it blank, set minutes after to the duration of the event
const minutesAfter = parseInt(eventSettings.minutesAfter) >= 0 ? parseInt(eventSettings.minutesAfter) * 60000 : event.endDate - event.startDate
return (event.startDate.getTime() + minutesAfter > this.now.getTime())

}).slice(0,parseInt(eventSettings.numberOfEvents))
Expand Down Expand Up @@ -999,17 +1000,22 @@ const weatherCal = {
async date(column) {
const dateSettings = this.settings.date
if (!this.data.events && dateSettings.dynamicDateSize) { await this.setupEvents() }

const secondsForToday = Math.floor(new Date().getTime() / 1000) - 978307200
const defaultUrl = "calshow:" + secondsForToday
const settingUrl = dateSettings.url || ""
if (settingUrl.trim() != "none") { dateSettings.url = (settingUrl.length > 0) ? settingUrl : defaultUrl }

if (dateSettings.dynamicDateSize ? this.data.events.length : dateSettings.staticDateSize == "small") {
this.provideText(this.formatDate(this.now,dateSettings.smallDateFormat), column, this.format.smallDate, true)
this.provideText(this.formatDate(this.now,dateSettings.smallDateFormat), column, this.format.smallDate, true, dateSettings.url)

} else {
const dateOneStack = this.align(column)
const dateOne = this.provideText(this.formatDate(this.now,dateSettings.largeDateLineOne), dateOneStack, this.format.largeDate1)
const dateOne = this.provideText(this.formatDate(this.now,dateSettings.largeDateLineOne), dateOneStack, this.format.largeDate1, false, dateSettings.url)
dateOneStack.setPadding(this.padding/2, this.padding, 0, this.padding)

const dateTwoStack = this.align(column)
const dateTwo = this.provideText(this.formatDate(this.now,dateSettings.largeDateLineTwo), dateTwoStack, this.format.largeDate2)
const dateTwo = this.provideText(this.formatDate(this.now,dateSettings.largeDateLineTwo), dateTwoStack, this.format.largeDate2, false, dateSettings.url)
dateTwoStack.setPadding(0, this.padding, this.padding, this.padding)
}
},
Expand All @@ -1033,15 +1039,16 @@ const weatherCal = {
if (!this.data.events) { await this.setupEvents() }
const eventSettings = this.settings.events

const settingUrlExists = (eventSettings.url || "").length > 0
if (this.data.events.length == 0) {
if (eventSettings.noEventBehavior == "message" && this.localization.noEventMessage.length) { return this.provideText(this.localization.noEventMessage, column, this.format.noEvents, true) }
const secondsForToday = Math.floor(new Date().getTime() / 1000) - 978307200
if (eventSettings.noEventBehavior == "message" && this.localization.noEventMessage.length) { return this.provideText(this.localization.noEventMessage, column, this.format.noEvents, true, settingUrlExists ? eventSettings.url : "calshow:" + secondsForToday) }
if (this[eventSettings.noEventBehavior]) { return await this[eventSettings.noEventBehavior](column) }
}

let currentStack
let currentDiff = 0
const numberOfEvents = this.data.events.length
const settingUrlExists = (eventSettings.url || "").length > 0
const showCalendarColor = eventSettings.showCalendarColor
const colorShape = showCalendarColor.includes("circle") ? "circle" : "rectangle"

Expand Down Expand Up @@ -1166,7 +1173,7 @@ const weatherCal = {
colorItem.textColor = reminder.calendar.color
}

if (reminder.isOverdue) { title.textColor = Color.red() }
if (reminder.isOverdue) { title.textColor = new Color(reminderSettings.overdueColor || "ff3b30") }
if (reminder.isOverdue || !reminder.dueDate) { continue }

let timeText
Expand Down Expand Up @@ -1208,7 +1215,7 @@ const weatherCal = {
currentWeatherStack.layoutVertically()
currentWeatherStack.setPadding(0, 0, 0, 0)

const defaultUrl = "https://weather.com/" + this.locale + "/weather/today/l/" + locationData.latitude + "," + locationData.longitude
const defaultUrl = "weather://"
const settingUrl = weatherSettings.urlCurrent || ""
if (settingUrl.trim() != "none") { currentWeatherStack.url = (settingUrl.length > 0) ? settingUrl : defaultUrl }

Expand Down Expand Up @@ -1276,7 +1283,7 @@ const weatherCal = {

const showNextHour = (this.now.getHours() < parseInt(weatherSettings.tomorrowShownAtHour))

const defaultUrl = "https://weather.com/" + this.locale + "/weather/" + (showNextHour ? "today" : "tenday") +"/l/" + locationData.latitude + "," + locationData.longitude
const defaultUrl = "weather://"
const settingUrl = showNextHour ? (weatherSettings.urlFuture || "") : (weatherSettings.urlForecast || "")
if (settingUrl != "none") { futureWeatherStack.url = (settingUrl.length > 0) ? settingUrl : defaultUrl }

Expand Down Expand Up @@ -1338,7 +1345,7 @@ const weatherCal = {

// Set up the container stack and overall spacing.
const weatherStack = this.align(column)
const defaultUrl = "https://weather.com/" + this.locale + "/weather/" + (hourly ? "today" : "tenday") + "/l/" + locationData.latitude + "," + locationData.longitude
const defaultUrl = "weather://"
const settingUrl = hourly ? (weatherSettings.urlFuture || "") : (weatherSettings.urlForecast || "")
weatherStack.url = (settingUrl.length > 0) ? settingUrl : defaultUrl

Expand Down Expand Up @@ -1779,7 +1786,7 @@ const weatherCal = {
},

// Add formatted text to a container.
provideText(string, stack, format, standardize = false) {
provideText(string, stack, format, standardize = false, url) {
let container = stack
if (standardize) {
container = this.align(stack)
Expand Down Expand Up @@ -1810,6 +1817,9 @@ const weatherCal = {
const textSize = (format && format.size && parseInt(format.size)) ? format.size : this.format.defaultText.size
textItem.font = this.provideFont(textFont, parseInt(textSize))
textItem.textColor = this.provideColor(format)
if (url) {
textItem.url = url
}

return textItem
},
Expand Down Expand Up @@ -2131,7 +2141,12 @@ const weatherCal = {
largeDateLineTwo: {
val: "MMMM d",
name: "Large date format, line 2",
},
},
url: {
val: "",
name: "URL to open when tapped",
description: "Optionally provide a URL to open when this item is tapped. Leave blank to open the built-in Calendar app.",
},
},
events: {
name: "Events",
Expand All @@ -2142,7 +2157,7 @@ const weatherCal = {
minutesAfter: {
val: "5",
name: "Minutes after event begins",
description: "Number of minutes after an event begins that it should still be shown.",
description: "Number of minutes after an event begins that it should still be shown. Leave blank for an event to show for its duration.",
},
showAllDay: {
val: false,
Expand Down Expand Up @@ -2223,6 +2238,11 @@ const weatherCal = {
name: "Show overdue reminders",
type: "bool",
},
overdueColor: {
val: "ff3b30",
name: "Overdue Color",
description: "The hex code color value for overdue reminders. Leave blank for the default red.",
},
todayOnly: {
val: false,
name: "Hide reminders due after today",
Expand Down Expand Up @@ -2345,17 +2365,17 @@ const weatherCal = {
urlCurrent: {
val: "",
name: "URL to open when current weather is tapped",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the default.",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the weather app.",
},
urlFuture: {
val: "",
name: "URL to open when hourly weather is tapped",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the default.",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the weather app.",
},
urlForecast: {
val: "",
name: "URL to open when daily weather is tapped",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the default.",
description: "Optionally provide a URL to open when this item is tapped. Leave blank for the weather app.",
},
},
covid: {
Expand Down

0 comments on commit 2bff7cf

Please sign in to comment.