Skip to content

Commit

Permalink
Merge pull request #25 from ipuppet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ipuppet authored Apr 12, 2022
2 parents 5fdcb31 + 990a017 commit 4c71e16
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 31 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.6.3",
"version": "1.6.4",
"author": "ipuppet",
"module": false
},
Expand Down
22 changes: 12 additions & 10 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,19 @@ function widgetInstance(widget, that) {
class AppKernel extends Kernel {
constructor() {
super()
this.query = $context.query
this.setting = new Setting()
this.setting.loadConfig()
this.initSettingMethods()
// FileStorage
this.fileStorage = fileStorage
// setting
this.setting = new Setting({ fileStorage: this.fileStorage })
this.setting.loadConfig()
this.initSettingMethods()

// 小组件根目录
this.widgetRootPath = widgetRootPath
this.widgetDataPath = widgetDataPath
// backup
this.backupPath = backupPath
this.initComponents()
// 检查是否携带URL scheme
if (this.query["url-scheme"]) {
// 延时500ms后跳转
setTimeout(() => { $app.openURL(this.query["url-scheme"]) }, 500)
}
}

initComponents() {
Expand Down Expand Up @@ -302,6 +298,12 @@ class WidgetKernel extends Kernel {

class AppUI {
static renderMainUI() {
// 检查是否携带 URL scheme
if ($context.query["url-scheme"]) {
$delay(0, () => { $app.openURL($context.query["url-scheme"]) })
return
}

const kernel = new AppKernel()
const buttons = {
home: {
Expand Down Expand Up @@ -404,7 +406,7 @@ module.exports = {
run: () => {
if ($app.env === $env.widget) {
Widget.render()
} else if ($app.env === $env.app || $app.env === $env.today) {
} else if ($app.env === $env.app) {
AppUI.renderMainUI()
} else {
AppUI.renderUnsupported()
Expand Down
7 changes: 4 additions & 3 deletions scripts/lib/easy-jsbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ class Matrix extends View {
this.setEvent("itemSize", (sender, indexPath) => {
const info = sender.object(indexPath)?.__title?.info
if (info?.title) {
return $size(Math.max(UIKit.windowSize.width, UIKit.windowSize.height), 0)
return $size(Math.max($device.info.screen.width, $device.info.screen.height), 0)
}
const columns = this.props.columns ?? 2
const spacing = this.props.spacing ?? 15
Expand Down Expand Up @@ -1890,6 +1890,7 @@ class Kernel {

debug(print) {
this.debugMode = true
$app.idleTimerDisabled = true
if (typeof print === "function") {
this.debugPrint = print
}
Expand Down Expand Up @@ -2127,7 +2128,7 @@ class Setting extends Controller {
// 存储数据
setting = {}
// fileStorage
fileStorage = new FileStorage()
fileStorage
imagePath
// 用来控制 child 类型
viewController = new ViewController()
Expand All @@ -2147,12 +2148,12 @@ class Setting extends Controller {
constructor(args = {}) {
super()

this.fileStorage = args.fileStorage ?? this.fileStorage
// set 和 get 同时设置才会生效
if (typeof args.set === "function" && typeof args.get === "function") {
this.set = args.set
this.get = args.get
} else {
this.fileStorage = args.fileStorage ?? new FileStorage()
this.dataFile = args.dataFile ?? "setting.json"
}
if (args.structure) {
Expand Down
18 changes: 8 additions & 10 deletions scripts/ui/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ class HomeUI {
constructor(kernel) {
this.kernel = kernel
this.viewController = new ViewController()
// 检查是否携带widget参数,携带则打开设置页面
if (this.kernel.query["widget"]) {
setTimeout(() => {
const widget = this.kernel.widgetInstance(this.kernel.query["widget"])
// 检查是否携带 widget 参数,携带则打开设置页面
if ($context.query["widget"]) {
$delay(0.5, () => {
const widget = this.kernel.widgetInstance($context.query["widget"])
if (widget) {
widget.custom()
// 清空参数
this.kernel.query["widget"] = undefined
}
}, 500)
})
}
}

getWidgetListView() {
const data = this.kernel.getWidgetList()
const template = data => {
return {
icon: {// 如果不设置image属性,默认为小组件目录下的icon.png
icon: {// 如果不设置 image 属性,默认为小组件目录下的 icon.png
image: $image(data.icon[0], data.icon[1])
},
title: {
Expand Down Expand Up @@ -61,7 +59,7 @@ class HomeUI {
src: fromPath,
dst: newPath
})
// 更新设置文件中的NAME常量
// 更新设置文件中的 NAME 常量
let settingjs = $file.read(`${newPath}/setting.js`).string
const firstLine = `const NAME = "${from}"`
const newFirstLine = `const NAME = "${newName}"`
Expand All @@ -70,7 +68,7 @@ class HomeUI {
data: $data({ string: settingjs }),
path: `${newPath}/setting.js`
})
// 更新config.json
// 更新 config.json
const config = JSON.parse($file.read(`${newPath}/config.json`).string)
if (config.from === undefined) config.from = from
config.name = newName
Expand Down
8 changes: 6 additions & 2 deletions scripts/widget/Join/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ class JoinWidget extends Widget {
const height = $widget.displaySize.height
// 调节宽度并裁剪多余部分
if (!leftView.props.frame) leftView.props.frame = {}
leftView.props.frame["maxWidth"] = width
if (leftView.props.frame["maxWidth"] > width) {
leftView.props.frame["maxWidth"] = width
}
leftView.props["clipped"] = true
leftView.widgetURL = undefined
if (!rightView.props.frame) rightView.props.frame = {}
rightView.props.frame["maxWidth"] = width
if (rightView.props.frame["maxWidth"] > width) {
rightView.props.frame["maxWidth"] = width
}
rightView.props["clipped"] = true
rightView.widgetURL = undefined
return {
Expand Down
4 changes: 3 additions & 1 deletion scripts/widget/Join/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class JoinSetting extends BaseSetting {
const data = this.kernel.getWidgetList()
const result = []
data.forEach(item => {
if (item.name !== NAME)
if (item.name !== NAME && item.name !== "Calendar")
result.push(item.name)
})
// "Calendar" 作为默认值,永远排在最前面
result.unshift("Calendar")
return result
})()

Expand Down
12 changes: 8 additions & 4 deletions scripts/widget/TextClock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TextClockWidget extends Widget {
this.oneDayInMillis = 60 * 60 * 24 * 1000
}

view2x2(ctx) {
view2x2() {
return {
type: "text",
props: {
Expand All @@ -24,21 +24,25 @@ class TextClockWidget extends Widget {
monospaced: true
},
frame: {
maxWidth: ctx.displaySize.width - 30
maxWidth: $widget.displaySize.width - 30
},
lineLimit: 1,
minimumScaleFactor: 0.01
}
}
}

joinView() {
return this.view2x2()
}

render() {
$widget.setTimeline({
policy: {
afterDate: new Date(this.midnight.getTime() + this.oneDayInMillis)
},
render: ctx => {
const view = this.view2x2(ctx)
render: () => {
const view = this.view2x2()
this.printTimeConsuming()
return view
}
Expand Down

0 comments on commit 4c71e16

Please sign in to comment.