Skip to content

Commit

Permalink
增加 Open in JSBox
Browse files Browse the repository at this point in the history
- 键盘小地球长按
- 通知中心小组件通过 Launcer 加载时会出现
  • Loading branch information
ipuppet committed Oct 4, 2022
1 parent 9424009 commit 731c501
Show file tree
Hide file tree
Showing 8 changed files with 62 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": "CAIO",
"version": "1.6.7",
"version": "1.6.8",
"author": "ipuppet",
"module": false
},
Expand Down
39 changes: 23 additions & 16 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class AppKernel extends Kernel {
settingMethods(this)
}

addOpenInJsboxButton() {
this.useJsboxNav()
this.setNavButtons([
{
image: $image("assets/icon.png"),
handler: () => this.openInJsbox()
}
])
}

initComponents() {
// Clipboard
this.clipboard = new Clipboard(this)
Expand Down Expand Up @@ -71,18 +81,9 @@ class AppUI {
static renderMainUI() {
const kernel = new AppKernel()
const buttons = {
clipboard: {
icon: "doc.on.clipboard",
title: $l10n("CLIPBOARD")
},
actions: {
icon: "command",
title: $l10n("ACTIONS")
},
setting: {
icon: "gear",
title: $l10n("SETTING")
}
clipboard: { icon: "doc.on.clipboard", title: $l10n("CLIPBOARD") },
actions: { icon: "command", title: $l10n("ACTIONS") },
setting: { icon: "gear", title: $l10n("SETTING") }
}
kernel.setting.setEvent("onSet", key => {
if (key === "mainUIDisplayMode") {
Expand Down Expand Up @@ -123,8 +124,8 @@ class AppUI {
kernel.tabBarController
.setPages({
clipboard: clipboardNavigationView.getPage(),
actions: kernel.actionManager.getPageView(),
setting: kernel.setting.getPageView()
actions: kernel.actionManager.getPage(),
setting: kernel.setting.getPage()
})
.setCells({
clipboard: buttons.clipboard,
Expand All @@ -138,16 +139,22 @@ class AppUI {

static renderKeyboardUI() {
const kernel = new AppKernel()
kernel.addOpenInJsboxButton()

const Keyboard = require("./ui/keyboard")
const keyboard = new Keyboard(kernel)
$ui.render({ views: [keyboard.getView()] })

kernel.UIRender(keyboard.getView())
}

static renderTodayUI() {
const kernel = new AppKernel()
kernel.addOpenInJsboxButton()

const Today = require("./ui/today")
const today = new Today(kernel)
$ui.render({ views: [today.getView()] })

kernel.UIRender(today.getView())
}

static renderUnsupported() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/libs/easy-jsbox.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/ui/components/action-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ class ActionManager {
return this.matrix.definition
}

getPageView() {
getPage() {
const navigationView = new NavigationView()
navigationView.navigationBarItems.setRightButtons(this.getNavButtons())
navigationView.setView(this.getMatrixView()).navigationBarTitle($l10n("ACTIONS"))
Expand Down
6 changes: 5 additions & 1 deletion scripts/ui/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ class Keyboard extends Clipboard {
pullDown: true,
items: [
{
title: "Next Keyboard",
title: $l10n("SWITCH_KEYBOARD"),
handler: this.keyboardTapped(() => $keyboard.next())
},
{
title: $l10n("OPEN_IN_JSBOX"),
handler: () => this.kernel.openInJsbox()
}
]
}
Expand Down
38 changes: 27 additions & 11 deletions scripts/ui/today.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { UIKit, BarButtonItem, NavigationBarItems, NavigationBar } = require("../libs/easy-jsbox")
const { View, UIKit, BarButtonItem, NavigationBarItems, NavigationBar } = require("../libs/easy-jsbox")
const Clipboard = require("./clipboard")
const TodayActions = require("./components/today-actions")

Expand Down Expand Up @@ -293,15 +293,17 @@ class Today extends Clipboard {
}
}

getMatrixView() {
getActionView() {
let data = this.todayActions.getActions()
if (data.length === 0) {
data = this.todayActions.getAllActions()
}
return {

const matrixView = {
type: "matrix",
props: {
id: this.matrixId,
bgcolor: $color("clear"),
columns: 2,
itemHeight: 50,
spacing: 8,
Expand Down Expand Up @@ -375,16 +377,14 @@ class Today extends Clipboard {
}
}
}
}

getActionView() {
return {
type: "view",
props: {
id: this.actionsId,
hidden: this.tabIndex !== 2
},
views: [this.getMatrixView()],
views: [matrixView],
layout: (make, view) => {
make.top.equalTo(this.navHeight)
make.bottom.left.right.equalTo(view.super.safeArea)
Expand All @@ -393,11 +393,27 @@ class Today extends Clipboard {
}

getView() {
return {
type: "view",
views: [this.getNavBarView(), this.getListView(), this.getActionView()],
layout: $layout.fill
}
// 直接放最外层 ready 事件不生效
return View.createFromViews([
{
type: "view",
views: [this.getNavBarView(), this.getListView(), this.getActionView()],
layout: $layout.fill,
events: {
ready: async () => {
if ($app.env !== $env.today) return

await $thread.main(0.5)
$ui.animate({
duration: 0.2,
animation: () => {
$ui.vc.runtimeValue().$view().$setBackgroundColor($color("clear"))
}
})
}
}
}
])
}
}

Expand Down
2 changes: 2 additions & 0 deletions strings/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"JSBOX_TOOLBAR" = "JSBox Toolbar";
"QUICK_START_SCRIPTS" = "Quick Start Scripts";
"SEND" = "Send";
"OPEN_IN_JSBOX" = "Open in JSBox";
"SWITCH_KEYBOARD" = "Switch Keyboard";

"CHECK_UPDATE" = "Check Update";
"UPDATE" = "Update";
Expand Down
2 changes: 2 additions & 0 deletions strings/zh-Hans.strings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"JSBOX_TOOLBAR" = "JSBox 工具栏";
"QUICK_START_SCRIPTS" = "快速启动脚本";
"SEND" = "发送";
"OPEN_IN_JSBOX" = "在 JSBox 中打开";
"SWITCH_KEYBOARD" = "切换键盘";

"CHECK_UPDATE" = "检查更新";
"UPDATE" = "更新";
Expand Down

0 comments on commit 731c501

Please sign in to comment.