-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
317 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
// run app | ||
const app = require("./scripts/app") | ||
app.run() | ||
let AppInstance | ||
|
||
switch ($app.env) { | ||
case $env.app: | ||
case $env.action: | ||
AppInstance = require("./scripts/app") | ||
break | ||
case $env.today: | ||
case $env.keyboard: | ||
AppInstance = require("./scripts/app-lite") | ||
break | ||
case $env.widget: | ||
AppInstance = require("./scripts/widget") | ||
break | ||
|
||
default: | ||
$intents.finish("不支持在此环境中运行") | ||
$ui.render({ | ||
views: [ | ||
{ | ||
type: "label", | ||
props: { | ||
text: "不支持在此环境中运行", | ||
align: $align.center | ||
}, | ||
layout: $layout.fill | ||
} | ||
] | ||
}) | ||
break | ||
} | ||
|
||
if (AppInstance) { | ||
AppInstance.run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "node build.js" | ||
} | ||
{ | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "node build.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const { Kernel, Logger, FileStorage, Setting, FileManager } = require("./libs/easy-jsbox") | ||
const SettingStructure = require("./setting/setting") | ||
const { Storage } = require("./dao/storage") | ||
const Clips = require("./ui/clips") | ||
const ActionManager = require("./ui/components/action-manager") | ||
|
||
/** | ||
* @typedef {AppKernelBase} AppKernelBase | ||
*/ | ||
class AppKernelBase extends Kernel { | ||
static fileStorage = new FileStorage() | ||
|
||
logPath = "logs" | ||
logFile = "caio.log" | ||
logFilePath = FileStorage.join(this.logPath, this.logFile) | ||
|
||
#storage | ||
|
||
constructor() { | ||
super() | ||
// FileStorage | ||
this.fileStorage = AppKernelBase.fileStorage | ||
// Logger | ||
this.logger = new Logger() | ||
this.logger.printToFile(this.fileStorage, this.logFilePath) | ||
// Setting | ||
this.setting = new Setting({ | ||
fileStorage: this.fileStorage, | ||
structure: SettingStructure | ||
}) | ||
this.setting.setReadonly() | ||
this.initComponents() | ||
} | ||
|
||
get storage() { | ||
if (!this.#storage) { | ||
this.print("init storage") | ||
this.#storage = new Storage(this) | ||
} | ||
return this.#storage | ||
} | ||
|
||
error(message) { | ||
if (this.fileStorage.exists(this.logFilePath)) { | ||
const logFileSize = this.fileStorage.readSync(this.logFilePath)?.info?.size ?? 0 | ||
if (logFileSize > 1024 * 10) { | ||
const dist = FileStorage.join(this.logPath, `caio.${Date.now()}.log`) | ||
this.fileStorage.move(this.logFilePath, dist) | ||
} | ||
} | ||
|
||
if (message instanceof Error) { | ||
message = `${message}\n${message.stack}` | ||
} | ||
super.error(message) | ||
this.logger.error(message) | ||
} | ||
|
||
initComponents() { | ||
// Clips | ||
this.clips = new Clips(this) | ||
// ActionManager | ||
this.actionManager = new ActionManager(this) | ||
// FileManager | ||
this.fileManager = new FileManager() | ||
} | ||
} | ||
|
||
module.exports = { | ||
AppKernelBase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { AppKernelBase } = require("./app-base") | ||
|
||
/** | ||
* @typedef {AppKernel} AppKernel | ||
*/ | ||
class AppKernel extends AppKernelBase { | ||
constructor() { | ||
super() | ||
|
||
this.setting.setReadonly() | ||
} | ||
|
||
addOpenInJsboxButton() { | ||
this.useJsboxNav() | ||
this.setNavButtons([ | ||
{ | ||
image: $image("assets/icon.png"), | ||
handler: () => this.openInJsbox() | ||
} | ||
]) | ||
} | ||
} | ||
|
||
class AppUI { | ||
// 小组件模式下不初始化 AppKernel | ||
static kernel = $app.env !== $env.widget ? new AppKernel() : undefined | ||
|
||
static renderKeyboardUI() { | ||
this.kernel.addOpenInJsboxButton() | ||
|
||
const Keyboard = require("./ui/keyboard") | ||
const keyboard = new Keyboard(this.kernel) | ||
|
||
this.kernel.KeyboardRender(keyboard.getView()) | ||
} | ||
|
||
static renderTodayUI() { | ||
this.kernel.addOpenInJsboxButton() | ||
|
||
const Today = require("./ui/today") | ||
const today = new Today(this.kernel) | ||
|
||
this.kernel.UIRender(today.getView()) | ||
} | ||
} | ||
|
||
module.exports = { | ||
run: () => { | ||
//AppUI.renderKeyboardUI();return | ||
//AppUI.renderTodayUI();return | ||
|
||
if ($app.env === $env.today) { | ||
AppUI.renderTodayUI() | ||
} else if ($app.env === $env.keyboard) { | ||
AppUI.renderKeyboardUI() | ||
} | ||
} | ||
} |
Oops, something went wrong.