Skip to content

Commit

Permalink
Merge pull request #52 from ipuppet/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ipuppet authored Jun 15, 2022
2 parents 703555c + dc34e87 commit 3be315e
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 19 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": "1.5.13",
"version": "1.5.14",
"author": "ipuppet",
"module": false
},
Expand Down
13 changes: 12 additions & 1 deletion scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const Clipboard = require("./ui/clipboard")
const ActionManager = require("./ui/components/action-manager")
const Editor = require("./ui/components/editor")

const KeyboardScripts = require("./ui/components/keyboard-scripts")
const TodayActions = require("./ui/components/today-actions")

const fileStorage = new FileStorage()

class AppKernel extends Kernel {
Expand Down Expand Up @@ -307,7 +310,6 @@ class AppKernel extends Kernel {

this.setting.method.setKeyboardQuickStart = animate => {
animate.touchHighlight()
const KeyboardScripts = require("./ui/components/keyboard-scripts")
if (this.isUseJsboxNav) {
KeyboardScripts.push()
} else {
Expand All @@ -324,6 +326,15 @@ class AppKernel extends Kernel {
disappeared: () => animate.touchHighlightEnd()
})
}

this.setting.method.setTodayWidgetActions = animate => {
animate.touchHighlight()
if (this.isUseJsboxNav) {
TodayActions.push(this)
} else {
this.setting.viewController.push(TodayActions.getPageController(this))
}
}
}
}

Expand Down
69 changes: 69 additions & 0 deletions scripts/libs/easy-jsbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,73 @@ class Kernel {
}
}

class UILoading {
#labelId
text = ""
interval
fullScreen = false
#loop = () => { }

constructor() {
this.#labelId = uuid()
}

updateText(text) {
$(this.#labelId).text = text
}

setLoop(loop) {
if (typeof loop !== "function") {
throw "loop must be a function"
}
this.#loop = loop
}

done() {
clearInterval(this.interval)
}

load() {
$ui.render({
props: {
navBarHidden: this.fullScreen
},
views: [
{
type: "spinner",
props: {
loading: true
},
layout: (make, view) => {
make.centerY.equalTo(view.super).offset(-15)
make.width.equalTo(view.super)
}
},
{
type: "label",
props: {
id: this.#labelId,
align: $align.center,
text: ""
},
layout: (make, view) => {
make.top.equalTo(view.prev.bottom).offset(10)
make.left.right.equalTo(view.super)
}
}
],
layout: $layout.fill,
events: {
appeared: () => {
this.interval = setInterval(() => {
this.#loop()
}, 100)
}
}
})
}
}

class FileStorageParameterError extends Error {
constructor(parameter) {
super(`Parameter [${parameter}] is required.`)
Expand Down Expand Up @@ -3671,6 +3738,7 @@ module.exports = {
versionCompare,
compressImage,
// class
View,
UIKit,
ViewController,
Matrix,
Expand All @@ -3688,6 +3756,7 @@ module.exports = {
TabBarHeaderView,
TabBarController,
Kernel,
UILoading,
FileStorage,
Setting
}
10 changes: 5 additions & 5 deletions scripts/ui/components/action-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ class ActionManager {
return data
}

getMatrixView() {
const columns = 2
const spacing = 15
const itemHeight = 100

getMatrixView({
columns = 2,
spacing = 15,
itemHeight = 100
} = {}) {
this.matrix = Matrix.create({
type: "matrix",
props: {
Expand Down
8 changes: 7 additions & 1 deletion scripts/ui/components/keyboard-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {

class KeyboardScripts {
constructor() {
this.listId = "keyboard-clipboard-list"
this.listId = "keyboard-script-list"
}

static getAddins() {
Expand Down Expand Up @@ -83,6 +83,7 @@ class KeyboardScripts {
type: "list",
props: {
id: this.listId,
reorder: true,
data: KeyboardScripts.getAddins(),
actions: [
{
Expand All @@ -93,6 +94,11 @@ class KeyboardScripts {
}
]
},
events: {
reorderFinished: data => {
KeyboardScripts.setAddins(data)
}
},
layout: $layout.fill
}
}
Expand Down
202 changes: 202 additions & 0 deletions scripts/ui/components/today-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
const {
UIKit,
Sheet,
NavigationItem,
PageController
} = require("../../libs/easy-jsbox")

class TodayActions {
constructor(kernel) {
this.listId = "today-action-list"
this.kernel = kernel
}

getActions() {
const actions = $cache.get("today.actions")
if (actions === undefined) {
return []
}
return JSON.parse(actions)
}

setActions(list = []) {
list.map((item, i) => {
if (item === null) {
list.splice(i, 1)
}
})
$cache.set("today.actions", JSON.stringify(list))
}

getAllActions() {
let actions = []
this.kernel.actionManager.getActionTypes().forEach(type => {
actions = actions.concat(this.kernel.actionManager.getActions(type))
})
return actions
}

getUnsetActions() {
const actions = this.getActions().map(action => action.name)
const res = []
this.getAllActions().forEach(action => {
const name = action.name
if (actions.indexOf(name) === -1) {
res.push(action)
}
})
return res
}

getListData(actions) {
return actions.map(action => {
return {
action: {
text: action.name,
info: action
},
icon: action.icon.slice(0, 5) === "icon_"
? { icon: $icon(action.icon.slice(5, action.icon.indexOf(".")), $color("#ffffff")) }
: { image: $image(action.icon) },
color: { bgcolor: $color(action.color) }
}
})
}

getListTemplate() {
return {
views: [
{
type: "image",
props: {
id: "color",
cornerRadius: 8,
smoothCorners: true
},
layout: make => {
make.top.left.inset(10)
make.size.equalTo($size(30, 30))
}
},
{
type: "image",
props: {
id: "icon",
tintColor: $color("#ffffff"),
},
layout: make => {
make.top.left.inset(15)
make.size.equalTo($size(20, 20))
}
},
{
type: "label",
props: { id: "action" },
layout: (make, view) => {
make.bottom.top.inset(10)
make.left.equalTo(view.prev.prev.right).offset(10)
make.right.inset(10)
}
}
]
}
}

add() {
const view = {
type: "list",
props: {
data: this.getListData(this.getUnsetActions()),
template: this.getListTemplate(),
rowHeight: 50
},
events: {
didSelect: (sender, indexPath, data) => {
const action = data.action.info
const actions = this.getActions()
actions.unshift(action)
this.setActions(actions)
$(this.listId).insert({
indexPath: $indexPath(0, 0),
value: this.getListData([action])[0]
})
sender.delete(indexPath)
}
},
layout: $layout.fill
}
const sheet = new Sheet()
sheet
.setView(view)
.addNavBar({ title: $l10n("ADD") })
.init()
.present()
}

getNavButtons() {
return [
{
symbol: "plus",
tapped: () => this.add()
}
]
}

getListView() {
return {
type: "list",
props: {
id: this.listId,
data: this.getListData(this.getActions()),
template: this.getListTemplate(),
rowHeight: 50,
reorder: true,
actions: [
{
title: "delete",
handler: (sender, indexPath) => {
this.setActions(sender.data.map(data => data.action.info))
}
}
]
},
events: {
reorderFinished: data => {
const actions = []
data.forEach(data => {
actions.push(data.action.info)
})
this.setActions(actions)
}
},
layout: $layout.fill
}
}

static getPageController(kernel) {
const todayActions = new TodayActions(kernel)
const pageController = new PageController()
pageController
.setView(todayActions.getListView())
.navigationItem
.setTitle($l10n("ACTIONS"))
.setLargeTitleDisplayMode(NavigationItem.largeTitleDisplayModeNever)
.setRightButtons(todayActions.getNavButtons())
return pageController
}

static push(kernel) {
const todayActions = new TodayActions(kernel)
const navButtons = todayActions.getNavButtons().map(item => {
item.handler = item.tapped
delete item.tapped
return item
})
UIKit.push({
navButtons: navButtons,
views: [todayActions.getListView()]
})
}
}

module.exports = TodayActions
3 changes: 1 addition & 2 deletions scripts/ui/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ class Keyboard extends Clipboard {
getBottomBarView() {
const navigationBar = new NavigationBar()
const navigationItem = new NavigationItem()

navigationItem.setLeftButtons([
{
symbol: "paperplane",
menu: {
pullDown: true,
asPrimary: true,
items: KeyboardScripts.getAddins().map(addin => {
items: KeyboardScripts.getAddins().reverse().map(addin => {
return {
title: addin,
handler: this.keyboardTapped(() => $addin.run(addin))
Expand Down
Loading

0 comments on commit 3be315e

Please sign in to comment.