Skip to content

Commit

Permalink
Merge pull request #9 from ipuppet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ipuppet authored Dec 19, 2021
2 parents 031e4b0 + fc107bb commit 425c687
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"info": {
"name": "WAIO",
"version": "1.5.3",
"version": "1.5.4",
"author": "ipuppet",
"module": false
},
Expand Down
24 changes: 7 additions & 17 deletions scripts/widget/MyDays/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,10 @@ class MyDaysWidget extends Widget {
props: {
padding: 0,
spacing: 0,
frame: {
alignment: $widget.alignment.topLeading,
maxWidth: Infinity,
maxHeight: Infinity
}
alignment: $widget.verticalAlignment.top
},
views: [
this.mainContentTemplate(weekInfo.week, {
frame: {
alignment: $widget.alignment.topTrailing,
maxWidth: this.dateFontSize / 1.5, // 字体大小和布局宽度之间存在某种比例
maxHeight: Infinity
}
}),
this.mainContentTemplate(weekInfo.week, { frame: {} }),
this.mainContentTemplate(weekInfo.day, {
font: $font(this.dateFontSize / 2),
offset: $point(5, this.dateFontSize - this.dateFontSize / 2)
Expand All @@ -106,7 +96,7 @@ class MyDaysWidget extends Widget {
}
break;
case 1: // 只显示周
view = view = this.mainContentTemplate(weekInfo.week)
view = this.mainContentTemplate(weekInfo.week)
break;
case 2: // 显示小数
view = this.mainContentTemplate(`${weekInfo.week}.${weekInfo.day}`)
Expand Down Expand Up @@ -136,12 +126,12 @@ class MyDaysWidget extends Widget {
type: "text",
props: { text: $l10n("NONE") }
}
let mainView = []
let mainView = {}
if (this.displayMode) { // 周数
const weekInfo = this.getWeekInfo(this.remainingDays)
mainView.push(this.weekTemplate(weekInfo, family))
mainView = this.weekTemplate(weekInfo, family)
} else { //天数
mainView.push(this.mainContentTemplate(this.dateSpanToString(this.remainingDays)))
mainView = this.mainContentTemplate(this.dateSpanToString(this.remainingDays))
}
const view = {
type: "vstack",
Expand All @@ -157,7 +147,7 @@ class MyDaysWidget extends Widget {
link: this.setting.settingUrlScheme,
widgetURL: this.setting.settingUrlScheme
},
views: mainView.concat([
views: [mainView].concat([
{
type: "text",
props: {
Expand Down
38 changes: 19 additions & 19 deletions scripts/widget/Schedule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ const Schedule = require("./schedule")
class ScheduleWidget extends Widget {
constructor(kernel) {
super(kernel, new ScheduleSetting(kernel))
this.schedule = new Schedule(this.kernel, this.setting)
this.timeSpan = this.setting.get("timeSpan")
}

async getCalendar(startDate, endDate) {
async getCalendar(startDate, hours) {
const nowDate = Date.now()
const res = []
const calendar = await $calendar.fetch({
startDate: startDate,
endDate: endDate
hours: hours,
})
// 未过期日程
calendar.events.forEach(item => {
if (item.endDate >= nowDate) {
const endDate = item.endDate instanceof Date ? item.endDate.getTime() : item.endDate
if (endDate >= nowDate) {
res.push(item)
}
})
return res
}

async getReminder(startDate, endDate) {
async getReminder(startDate, hours) {
// TODO 用于暂时解决提醒事项的一个多线程 bug
// https://github.com/cyanzhong/jsbox-issues/issues/117#issuecomment-996780241
$reminder.fetch = async (args) => {
Expand Down Expand Up @@ -100,7 +100,7 @@ class ScheduleWidget extends Widget {
const res = []
const reminder = await $reminder.fetch({
startDate: startDate,
endDate: endDate
hours: hours
})
// 未完成提醒事项
reminder.events.forEach(item => {
Expand All @@ -111,25 +111,25 @@ class ScheduleWidget extends Widget {
return res
}

async joinView(mode) {
// 获取数据
const startDate = new Date(Date.now() - 1000 * 60 * 60 * 24 * parseInt(this.timeSpan / 2)) // 以今天为中心的前后时间跨度。单位:天
const endDate = new Date(Date.now() + this.timeSpan * 1000 * 60 * 60 * 24)
const calendar = await this.getCalendar(startDate, endDate)
const reminder = await this.getReminder(startDate, endDate)
async initSchedule() {
this.schedule = new Schedule(this.kernel, this.setting)
// 存在长时间跨度的日程,因此不能从今天开始取。以今天为中心的前后时间跨度。
const startDate = new Date(Date.now() - 1000 * 60 * 60 * 24 * parseInt(this.timeSpan / 2))
const hours = this.timeSpan * 24 // 此处不用除 2,因为开始日期为今天往前数半个 this.timeSpan
const calendar = await this.getCalendar(startDate, hours)
const reminder = await this.getReminder(startDate, hours)
this.schedule.setData(calendar, reminder)
}

async joinView(mode) {
await this.initSchedule() // 获取数据
return this.schedule.scheduleView(mode)
}

async render() {
const nowDate = Date.now()
const expireDate = new Date(nowDate + 1000 * 60 * 10)// 每十分钟切换
// 获取数据
const startDate = new Date(nowDate - 1000 * 60 * 60 * 24 * parseInt(this.timeSpan / 2)) // 以今天为中心的前后时间跨度。单位:天
const endDate = new Date(Date.now() + this.timeSpan * 1000 * 60 * 60 * 24)
const calendar = await this.getCalendar(startDate, endDate)
const reminder = await this.getReminder(startDate, endDate)
this.schedule.setData(calendar, reminder)
const expireDate = new Date(nowDate + 1000 * 60 * 5) // 每五分钟切换
await this.initSchedule() // 获取数据
$widget.setTimeline({
entries: [
{
Expand Down

0 comments on commit 425c687

Please sign in to comment.