Skip to content

Commit

Permalink
Merge pull request #175 from ipuppet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ipuppet authored Jul 2, 2024
2 parents 6722078 + b283dfa commit 4336d7c
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 51 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": "CAIO",
"version": "2.2.13",
"version": "2.2.14",
"author": "ipuppet",
"module": false
},
Expand Down
2 changes: 1 addition & 1 deletion dist/CAIO.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ switch ($app.env) {
break
}

// AppInstance = require("./scripts/widget")
//AppInstance = require("./scripts/widget")
if (AppInstance) {
AppInstance.run()
}
2 changes: 1 addition & 1 deletion scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppKernelBase extends Kernel {

constructor() {
super()
$file.list($file.rootPath)
// $file.list($file.rootPath)
$app.listen({ exit: () => $objc_clean() })
// FileStorage
this.fileStorage = AppKernelBase.fileStorage
Expand Down
4 changes: 2 additions & 2 deletions scripts/setting/setting-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ function settingMethods(appKernel) {
animate.done()
}

kernel.setting.method.previewWidget = animate => {
const { Widget } = require("../widget")
kernel.setting.method.previewWidget = () => {
const widgets = {}
try {
JSON.parse($file.read("widget-options.json").string).forEach(item => {
Expand All @@ -456,6 +455,7 @@ function settingMethods(appKernel) {
$ui.menu({
items: Object.keys(widgets),
handler: name => {
const { Widget } = require("../widget")
Widget.render(widgets[name])
}
})
Expand Down
56 changes: 31 additions & 25 deletions scripts/ui/clips/clips.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Clips extends ClipsData {
if (UIKit.isTaio) return
$app.listen({
resume: () => {
// 重载小组件
$widget.reloadTimeline()
// 在应用恢复响应后调用
if (!this.needReload && $(this.views.listId).ocValue().$isEditing()) {
return
Expand Down Expand Up @@ -79,6 +81,34 @@ class Clips extends ClipsData {
this.delegates.setDelegate()
}

async checkUrlScheme() {
// actions widget
if ($context.query["runAction"]) {
const data = JSON.parse($text.base64Decode($context.query["runAction"]))
const action = this.kernel.actions.getAction(
data.category,
data.dir,
new ActionData({ env: ActionEnv.widget })
)
action.do()
return
}
// clips widget
if ($context.query["copy"]) {
const uuid = $context.query["copy"]
this.setCopied(uuid)
$ui.success($l10n("COPIED"))
} else if ($context.query["add"]) {
this.getAddTextView()
} else if ($context.query["actions"]) {
if (this.kernel.isUseJsboxNav) {
this.kernel.actions.present()
} else {
this.kernel.tabBarController.switchPageTo("actions")
}
}
}

/**
* list view ready event
*/
Expand All @@ -95,31 +125,7 @@ class Clips extends ClipsData {
if (UIKit.isTaio) return

// check url scheme
$delay(0.5, () => {
if ($context.query["copy"]) {
const uuid = $context.query["copy"]
this.setCopied(uuid)
$ui.success($l10n("COPIED"))
} else if ($context.query["add"]) {
this.getAddTextView()
} else if ($context.query["actions"]) {
if (this.kernel.isUseJsboxNav) {
this.kernel.actions.present()
} else {
this.kernel.tabBarController.switchPageTo("actions")
}
} else if ($context.query["runAction"]) {
$delay(0, () => {
const data = JSON.parse($text.base64Decode($context.query["runAction"]))
const action = this.kernel.actions.getAction(
data.category,
data.dir,
new ActionData({ env: ActionEnv.widget })
)
action.do()
})
}
})
$delay(0, () => this.checkUrlScheme())

this.appListen()
}
Expand Down
6 changes: 2 additions & 4 deletions scripts/widget.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
const { Logger } = require("./libs/easy-jsbox")
const { AppKernelBase } = require("./app")

/**
* @typedef {AppKernel} AppKernel
*/
class AppKernel extends AppKernelBase {
logFile = "widget.log"

constructor() {
super()

this.logger = new Logger()
this.logger.printToFile(this.fileStorage, "logs/widget.log")

this.setting.setReadonly()
}

Expand Down
58 changes: 42 additions & 16 deletions scripts/widget/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ class ActionsWidget {
return {
type: "vstack",
props: {
background: $color("primarySurface"),
alignment: $widget.horizontalAlignment.leading,
spacing: 0,
padding: 10,
padding: 20,
widgetURL: this.getUrlScheme(action)
},
views: [
Expand All @@ -100,7 +101,10 @@ class ActionsWidget {
}
},
{
cornerRadius: 10
cornerRadius: {
value: 15,
style: 1
}
}
],
views: [
Expand Down Expand Up @@ -152,9 +156,12 @@ class ActionsWidget {

const height = this.ctx.displaySize.height
const width = this.ctx.displaySize.width
const padding = 28
const itemHeight = (height - padding * (this.maxLength / 2 + 1)) / (this.maxLength / 2)
const itemWidth = (width - padding * 3) / 2
const padding = 25
const innerPadding = 5
const itemHeight = (height - padding * (this.maxLength / 2 + 1)) / (this.maxLength / 2) - innerPadding * 2
const itemWidth = (width - padding * 3) / 2 - innerPadding * 2
const r_outer = 15
const r_inner = r_outer * ((itemHeight - 2 * innerPadding) / itemHeight)
for (let i = 0; i < length; i += 2) {
const row = []
for (let j = 0; j < 2; j++) {
Expand All @@ -163,30 +170,48 @@ class ActionsWidget {
type: "hstack",
props: {
spacing: 0,
padding: 0,
link: this.getUrlScheme(action),
frame: {
maxWidth: itemWidth,
maxHeight: itemHeight,
alignment: $widget.alignment.leading
}
link: this.getUrlScheme(action)
},
modifiers: [
{
background: $color({
light: $rgb(245, 245, 245),
dark: $rgba(80, 80, 80, 0.3),
black: $rgba(70, 70, 70, 0.3)
}),
padding: innerPadding,
frame: {
maxWidth: itemWidth,
maxHeight: itemHeight,
alignment: $widget.alignment.leading
}
},
{
cornerRadius: {
value: r_outer,
style: 1
}
}
],
views: [
{
type: "hstack",
modifiers: [
{
background: $color(action.color),
frame: {
width: itemHeight - 5,
height: itemHeight - 5
width: itemHeight,
height: itemHeight
}
},
{
cornerRadius: 10
cornerRadius: {
value: r_inner,
style: 1
}
}
],
views: [this.getIcon(action, (itemHeight - 5) * 0.6)]
views: [this.getIcon(action, itemHeight * 0.6)]
},
{
type: "spacer",
Expand Down Expand Up @@ -216,6 +241,7 @@ class ActionsWidget {
return {
type: "vstack",
props: {
background: $color("primarySurface"),
spacing: padding,
padding: padding
},
Expand Down
2 changes: 2 additions & 0 deletions scripts/widget/list-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ListWidget {
return {
type: "vstack",
props: {
background: $color("primarySurface"),
alignment: $widget.horizontalAlignment.leading,
spacing: 0,
padding: this.padding,
Expand Down Expand Up @@ -141,6 +142,7 @@ class ListWidget {
return {
type: "hstack",
props: {
background: $color("primarySurface"),
spacing: 0,
padding: this.padding,
widgetURL: this.urlScheme.clips
Expand Down

0 comments on commit 4336d7c

Please sign in to comment.