### Application Start Script Example
Source: https://developer.fnnas.com/docs/core-concepts/environment-variables
This script demonstrates how to use various environment variables to manage application startup, configuration, and status checks. It handles start, status, and stop commands.
```bash
#!/bin/bash
case $1 in
start)
echo "启动应用: $TRIM_APPNAME 版本: $TRIM_APPVER"
echo "应用目录: $TRIM_APPDEST"
echo "配置文件目录: $TRIM_PKGETC"
echo "数据目录: $TRIM_PKGVAR"
echo "服务端口: $TRIM_SERVICE_PORT"
# 检查配置文件是否存在
if [ ! -f "$TRIM_PKGETC/config.conf" ]; then
echo "配置文件不存在,创建默认配置..."
cp "$TRIM_APPDEST/config.conf.example" "$TRIM_PKGETC/config.conf"
fi
# 启动应用
cd "$TRIM_APPDEST"
./myapp --config "$TRIM_PKGETC/config.conf" \
--data "$TRIM_PKGVAR" \
--port "$TRIM_SERVICE_PORT" \
--user "$TRIM_USERNAME" \
--log "$TRIM_TEMP_LOGFILE" &
echo "应用启动完成"
exit 0
;;
status)
# 检查应用是否在运行
if pgrep -f "myapp.*$TRIM_SERVICE_PORT" > /dev/null; then
echo "应用正在运行"
exit 0
else
echo "应用未运行"
exit 3
fi
;;
stop)
echo "停止应用..."
pkill -f "myapp.*$TRIM_SERVICE_PORT"
exit 0
;;
*)
echo "未知命令: $1"
exit 1
;;
esac
```
--------------------------------
### Simulate Custom Exception in Start Script
Source: https://developer.fnnas.com/docs/core-concepts/framework
This example shows how to handle a missing configuration file during application startup. It writes an error to TRIM_TEMP_LOGFILE and exits with code 1.
```bash
#!/bin/bash
case $1 in
start)
# 检查配置文件是否存在
if [ ! -f "$TRIM_PKGETC/config.conf" ]; then
echo "配置文件不存在, 应用启动失败!" > "${TRIM_TEMP_LOGFILE}"
exit 1
fi
# 启动应用
cd "$TRIM_APPDEST"
./myapp --config "$TRIM_PKGETC/config.conf" \
--data "$TRIM_PKGVAR" \
--port "$TRIM_SERVICE_PORT" \
--user "$TRIM_USERNAME" \
--log "$TRIM_TEMP_LOGFILE" &
echo "应用启动完成"
exit 0
;;
stop)
echo "停止应用..."
pkill -f "myapp.*$TRIM_SERVICE_PORT"
exit 0
;;
status)
# 检查应用是否在运行
if pgrep -f "myapp.*$TRIM_SERVICE_PORT" > /dev/null; then
echo "应用正在运行"
exit 0
else
echo "应用未运行"
exit 3
fi
;;
*)
exit 1
;;
esac
```
--------------------------------
### Installation Wizard Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Defines the steps and fields for an installation wizard, including welcome messages, terms agreement, admin account creation, and application configuration like database type and port.
```json
[
{
"stepTitle": "欢迎安装",
"items": [
{
"type": "tips",
"helpText": "欢迎使用我们的应用!在开始使用前,请阅读并同意我们的服务条款。"
},
{
"type": "tips",
"helpText": "请阅读 隐私政策 和 服务条款。"
},
{
"type": "switch",
"field": "wizard_agree_terms",
"label": "我已阅读并同意服务条款",
"rules": [
{
"required": true,
"message": "请同意服务条款"
}
]
}
]
},
{
"stepTitle": "创建管理员账号",
"items": [
{
"type": "text",
"field": "wizard_admin_username",
"label": "管理员用户名",
"initValue": "admin",
"rules": [
{
"required": true,
"message": "请输入管理员用户名"
},
{
"pattern": "^[a-zA-Z0-9_]+$",
"message": "用户名只能包含字母、数字和下划线"
}
]
},
{
"type": "password",
"field": "wizard_admin_password",
"label": "管理员密码",
"rules": [
{
"required": true,
"message": "请输入管理员密码"
},
{
"min": 8,
"message": "密码长度不能少于8位"
}
]
},
{
"type": "password",
"field": "wizard_admin_password_confirm",
"label": "确认密码",
"rules": [
{
"required": true,
"message": "请确认密码"
}
]
}
]
},
{
"stepTitle": "应用配置",
"items": [
{
"type": "select",
"field": "wizard_database_type",
"label": "数据库类型",
"initValue": "sqlite",
"options": [
{
"label": "SQLite (推荐,无需额外配置)",
"value": "sqlite"
},
{
"label": "MySQL",
"value": "mysql"
}
]
},
{
"type": "text",
"field": "wizard_app_port",
"label": "应用端口",
"initValue": "8080",
"rules": [
{
"required": true,
"message": "请输入端口号"
},
{
"pattern": "^[0-9]+$",
"message": "端口号必须是数字"
}
]
}
]
}
]
```
--------------------------------
### Example Manifest File
Source: https://developer.fnnas.com/docs/core-concepts/manifest
This example demonstrates a typical manifest file structure, including essential fields for application identification, system requirements, developer information, UI configuration, port settings, and dependency management.
```properties
appname=myapp
version=1.0.0
display_name=我的应用
desc=这是一个示例应用,展示了 manifest 文件的基本用法
arch=x86_64
source=thirdparty
maintainer=张三
maintainer_url=https://example.com
distributor=示例公司
distributor_url=https://company.com
os_min_version=0.9.0
desktop_uidir=ui
desktop_applaunchname=myapp.APPLICATION
service_port=8080
checkport=true
install_dep_apps=mariaDB:redis
```
--------------------------------
### Docker Compose File Example
Source: https://developer.fnnas.com/docs/core-concepts/resource
An example Docker Compose file defining services, ports, volumes, environment variables, and dependencies for a multi-container application.
```yaml
version: '3.8'
services:
web:
build: .
ports:
- "8080:80"
volumes:
- ./data:/app/data
environment:
- DB_HOST=db
- DB_PORT=3306
depends_on:
- db
db:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=myapp
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
```
--------------------------------
### Python MinIO Client Initialization and Bucket Creation
Source: https://developer.fnnas.com/docs/core-concepts/middleware
Initialize the MinIO client with your endpoint, access key, and secret key. This example demonstrates how to check for and create a bucket if it doesn't exist.
```python
import minio
from minio import Minio
from minio.error import S3Error
# 1. 初始化客户端
# 默认配置下的 MinIO 可通过 host 127.0.0.1 和 port 9000 连接
client = Minio(
endpoint="127.0.0.1:9000",
access_key="your_access_key", # 替换为你的 MinIO 管理员用户名 或 Access Key
secret_key="your_secret_key", # 替换为你的 MinIO 管理员密码 或 Secret Key
secure=False # 本地测试通常为 False
)
# 2. 定义桶名
bucket_name = "my-bucket"
# 创建 Bucket 示例
def main():
try:
# 检查桶是否存在,如果不存在则创建它
if not client.bucket_exists(bucket_name):
client.make_bucket(bucket_name)
print(f"Bucket '{bucket_name}' 已创建.")
else:
print(f"Bucket '{bucket_name}' 已存在.")
except S3Error as err:
print("创建 Bucket 时发生错误:", err)
if __name__ == "__main__":
main()
```
--------------------------------
### Correct Dependency Order for Installation
Source: https://developer.fnnas.com/docs/core-concepts/dependency
When declaring multiple dependencies, the order in `install_dep_apps` specifies the installation sequence. The system installs dependencies from right to left, ensuring that prerequisites are met before dependent applications are installed.
```properties
# 正确的依赖顺序,安装时将先安装dep1,后安装dep2
install_dep_apps=dep2:dep1
```
--------------------------------
### Incorrect Dependency Order Example
Source: https://developer.fnnas.com/docs/core-concepts/dependency
An incorrect dependency order in `install_dep_apps` can lead to installation failures or runtime issues if a dependent application is installed before its prerequisites. Always ensure the order reflects the actual dependency graph.
```properties
# 错误的依赖顺序,如果dep2依赖于dep1,可能导致问题
install_dep_apps=dep1:dep2
```
--------------------------------
### Application Directory Structure
Source: https://developer.fnnas.com/docs/core-concepts/framework
This outlines the standard directory structure for applications installed on the飞牛 fnOS system. It details system-created directories and developer-defined directories.
```bash
```
/var/apps/[appname]
├── cmd
│ ├── install_callback
│ ├── install_init
│ ├── main
│ ├── uninstall_callback
│ ├── uninstall_init
│ ├── upgrade_init
│ ├── upgrade_callback
│ ├── config_init
│ └── config_callback
├── config
│ ├──privilege
│ └──resource
├── ICON_256.PNG
├── ICON.PNG
├── LICENSE
├── manifest
├── etc->/vol[volume_number]/@appconf/[appname]
├── home->/vol[volume_number]/@apphome/[appname]
├── target->/vol[volume_number]/@appcenter/[appname]
├── tmp->/vol[volume_number]/@apptemp/[appname]
├── var->/vol[volume_number]/@appdata/[appname]
├── shares
│ ├──datashare1->/vol[volume_number]/@appshare/datashare1
│ └──datashare2->/vol[volume_number]/@appshare/datashare2
└── wizard
├── install
├── uninstall
├── upgrade
└── config
```
```
--------------------------------
### Configure Python Environment and Virtual Environment
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Configure the PATH to include the Python 3.12 bin directory. Then, create and activate a virtual environment for project dependencies using venv and install requirements.
```bash
# Optional versions: python312, python311, python310, python39, python38
export PATH=/var/apps/python312/target/bin:$PATH
# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Install python related dependencies to .venv
pip install -r requirements.txt
```
--------------------------------
### Declare MinIO Dependency in Manifest
Source: https://developer.fnnas.com/docs/core-concepts/middleware
Add 'minio' to `install_dep_apps` in your manifest to ensure MinIO is running when your application starts.
```yaml
install_dep_apps=minio
```
--------------------------------
### Application Lifecycle Management Script
Source: https://developer.fnnas.com/docs/core-concepts/framework
A basic structure for the main script that manages application start, stop, and status checks. It uses a case statement to handle different commands.
```bash
#!/bin/bash
case $1 in
start)
# 启动应用的命令,成功返回 0,失败返回 1
exit 0
;;
stop)
# 停止应用的命令,成功返回 0,失败返回 1
exit 0
;;
status)
# 检查应用运行状态,运行中返回 0,未运行返回 3
exit 0
;;
*)
exit 1
;;
esac
```
--------------------------------
### Radio Button Group Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Set up radio buttons for single selection from a list of options, such as installation types. Requires a selection to be made.
```json
{
"type": "radio",
"field": "wizard_install_type",
"label": "安装类型",
"initValue": "standard",
"options": [
{
"label": "标准安装",
"value": "standard"
},
{
"label": "自定义安装",
"value": "custom"
}
],
"rules": [
{
"required": true,
"message": "请选择安装类型"
}
]
}
```
--------------------------------
### Declare Redis Dependency in Manifest
Source: https://developer.fnnas.com/docs/core-concepts/middleware
Add 'redis' to `install_dep_apps` in your manifest to ensure Redis is running when your application starts.
```yaml
install_dep_apps=redis
```
--------------------------------
### Declare App Dependencies in Manifest
Source: https://developer.fnnas.com/docs/core-concepts/dependency
Use the `install_dep_apps` field in the `manifest` file to declare applications that must be installed and running for your application to function correctly. Dependencies are listed in order of execution, from last to first.
```properties
version=1.0.0
install_dep_apps=dep2:dep1
```
--------------------------------
### Declare Node.js v22 Dependency
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Declare a dependency on Node.js v22 in the manifest file. The application center ensures this version is installed and available.
```yaml
install_dep_apps=nodejs_v22
```
--------------------------------
### Python Redis Connection and Usage Example
Source: https://developer.fnnas.com/docs/core-concepts/middleware
Connect to Redis using a connection pool, specifying the database and other parameters. The connection pool manages connections, so explicit closing is not required.
```python
import redis
def main():
# 创建连接池,指定逻辑数据库(如 db=1),防止冲突
# 默认配置下的 redis 可通过 host 127.0.0.1 和 port 6739 连接
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=1, decode_responses=True, max_connections=10)
# 从连接池获取连接
client = redis.Redis(connection_pool=pool)
# 使用连接
client.lpush('my_list', 'item1', 'item2')
items = client.lrange('my_list', 0, -1)
print(items) # 输出: ['item2', 'item1']
# 不需要手动关闭连接,连接池会管理
# 但在程序退出前,可以关闭连接池
# pool.disconnect()
# 如需切换数据库,可重新创建连接池并指定不同的 db 参数
if __name__ == "__main__":
main()
```
--------------------------------
### Declare Python 3.12 Dependency
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Declare a dependency on Python 3.12 in the manifest file. The application center ensures this version is installed and available.
```yaml
install_dep_apps=python312
```
--------------------------------
### Checkbox Group Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Define a checkbox group for multiple selections, like choosing installation modules. Users must select at least one option.
```json
{
"type": "checkbox",
"field": "wizard_modules",
"label": "安装模块",
"initValue": ["web", "api"],
"options": [
{
"label": "Web界面",
"value": "web"
},
{
"label": "API接口",
"value": "api"
},
{
"label": "数据库",
"value": "database"
}
],
"rules": [
{
"required": true,
"message": "请至少选择一个模块"
}
]
}
```
--------------------------------
### Declare Java 21 OpenJDK Dependency
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Declare a dependency on Java 21 OpenJDK in the manifest file. The application center ensures this version is installed and available.
```yaml
install_dep_apps=java-21-openjdk
```
--------------------------------
### 打包应用
Source: https://developer.fnnas.com/docs/core-concepts/docker
在项目根目录执行 `fnpack build` 命令来打包应用,生成 `.fpk` 文件。
```bash
fnpack build
```
--------------------------------
### 创建 Docker 应用目录
Source: https://developer.fnnas.com/docs/core-concepts/docker
使用 `fnpack create` 命令创建应用目录,并指定 `docker` 模板。生成的目录结构包含应用代码、Docker 资源、配置文件和生命周期管理脚本。
```bash
fnpack create my-app -t docker
```
--------------------------------
### HTML Structure for App Center Demo
Source: https://developer.fnnas.com/docs/quick-started/create-application
Sets up the basic HTML for the App Center tutorial, including meta tags, title, CSS, and JavaScript imports.
```html
应用中心教学演示
Welcome to the fnOS AppCenter
点击上方文字体验JS交互
```
--------------------------------
### Configure System Integration Resources
Source: https://developer.fnnas.com/docs/core-concepts/resource
Specify files to be symlinked into system directories (`/usr/local/bin`, `/usr/local/lib`, `/usr/local/etc`) upon application startup and removed upon shutdown.
```json
{
"usr-local-linker": {
"bin": [
"bin/myapp-cli",
"bin/myapp-server"
],
"lib": [
"lib/mylib.so",
"lib/mylib.a"
],
"etc": [
"etc/myapp.conf",
"etc/myapp.d/default.conf"
]
}
}
```
--------------------------------
### 检查 Docker 应用启停状态脚本
Source: https://developer.fnnas.com/docs/core-concepts/docker
此脚本用于检查 Docker 应用的运行状态。它会读取 `docker-compose.yaml` 文件以获取容器名称,并使用 `docker inspect` 命令判断容器是否正在运行。默认情况下,Docker 应用的启停由应用中心管理。
```bash
#!/bin/bash
FILE_PATH="${TRIM_APPDEST}/docker/docker-compose.yaml"
is_docker_running () {
DOCKER_NAME=""
if [ -f "$FILE_PATH" ]; then
DOCKER_NAME=$(cat $FILE_PATH | grep "container_name" | awk -F ':' '{print $2}' | xargs)
echo "DOCKER_NAME is set to: $DOCKER_NAME"
fi
if [ -n "$DOCKER_NAME" ]; then
docker inspect $DOCKER_NAME | grep -q "\"Status\": \"running\"," || exit 1
return
fi
}
case $1 in
start)
# run start command. exit 0 if success, exit 1 if failed
# do nothing, docker application will be started by appcenter
exit 0
;;
stop)
# run stop command. exit 0 if success, exit 1 if failed
# do nothing, docker application will be stopped by appcenter
exit 0
;;
status)
# check application status command. exit 0 if running, exit 3 if not running
# check first container by default, you cound modify it by yourself
if is_docker_running; then
exit 0
else
exit 3
fi
;;
*)
exit 1
;;
esac%
```
--------------------------------
### 编辑应用启停脚本 (main)
Source: https://developer.fnnas.com/docs/core-concepts/native
定义应用启动和停止时的执行逻辑,包括日志文件、PID 文件路径和环境变量设置。
```bash
#!/bin/bash
LOG_FILE="${TRIM_PKGVAR}/info.log"
PID_FILE="${TRIM_PKGVAR}/app.pid"
export PATH=/var/apps/nodejs_v22/target/bin:$PATH
# data directory to write note.txt
DATA_DIR="${TRIM_DATA_SHARE_PATHS%%:*}"
```
--------------------------------
### 配置 Root 权限模式
Source: https://developer.fnnas.com/docs/core-concepts/privilege
通过将 `run-as` 设置为 `root` 来启用 Root 权限模式,允许应用执行特权操作。此模式仅适用于官方合作企业开发者。
```json
{
"defaults": {
"run-as": "root"
},
"username": "myapp_user",
"groupname": "myapp_group"
}
```
--------------------------------
### 创建飞牛 fnOS 应用打包目录
Source: https://developer.fnnas.com/docs/core-concepts/native
使用 fnpack 命令创建飞牛 fnOS 应用的打包目录结构。
```bash
fnpack create fnnas.notepad
```
--------------------------------
### Collect and Use Wizard Selections
Source: https://developer.fnnas.com/docs/core-concepts/wizard
This script demonstrates how to capture user selections from a wizard, including administrator username, password, database type, and application port. It then prints these values and conditionally configures the database based on the selected type.
```bash
ADMIN_USERNAME="$wizard_admin_username"
ADMIN_PASSWORD="$wizard_admin_password"
DATABASE_TYPE="$wizard_database_type"
APP_PORT="$wizard_app_port"
echo "管理员用户名: $ADMIN_USERNAME"
echo "数据库类型: $DATABASE_TYPE"
echo "应用端口: $APP_PORT"
if [ "$DATABASE_TYPE" = "mysql" ]; then
echo "配置MySQL数据库..."
else
echo "使用SQLite数据库..."
fi
```
--------------------------------
### 配置默认应用用户权限
Source: https://developer.fnnas.com/docs/core-concepts/privilege
使用 `config/privilege` 文件定义应用的默认运行身份为应用用户。如果未指定 `username` 和 `groupname`,系统将自动使用 `appname`。
```json
{
"defaults": {
"run-as": "package"
},
"username": "myapp_user",
"groupname": "myapp_group"
}
```
--------------------------------
### Configure Java Environment
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Configure the PATH to include the Java 21 OpenJDK bin directory. This ensures the correct java command is available in the current session.
```bash
# Optional versions: java-21-openjdk, java-17-openjdk, java-11-openjdk
export PATH=/var/apps/java-21-openjdk/target/bin:$PATH
# Confirm java version
java --version
```
--------------------------------
### 检查当前运行用户身份
Source: https://developer.fnnas.com/docs/core-concepts/privilege
在应用脚本中,使用环境变量 `TRIM_RUN_USERNAME` 和 `TRIM_USERNAME` 来检查当前运行的用户身份,并根据需要执行不同的逻辑。
```bash
#!/bin/bash
echo "当前运行用户: $TRIM_RUN_USERNAME"
echo "应用专用用户: $TRIM_USERNAME"
if [ "$TRIM_RUN_USERNAME" = "root" ]; then
echo "应用以 root 权限运行"
else
echo "应用以应用用户权限运行"
fi
```
--------------------------------
### Uninstallation Wizard Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Defines the steps for an uninstallation wizard, focusing on user confirmation for data handling, such as keeping or deleting application data.
```json
[
{
"stepTitle": "确认卸载",
"items": [
{
"type": "tips",
"helpText": "您即将卸载此应用。请选择如何处理应用数据:"
},
{
"type": "radio",
"field": "wizard_data_action",
"label": "数据保留选项",
"initValue": "keep",
"options": [
{
"label": "保留数据(推荐)- 将来重新安装时可恢复",
"value": "keep"
},
{
"label": "删除所有数据 - 此操作不可恢复!",
"value": "delete"
}
],
"rules": [
{
"required": true,
"message": "请选择数据保留选项"
}
]
},
{
"type": "tips",
"helpText": "警告: 选择删除数据后,所有应用数据将永久丢失,无法恢复。"
}
]
}
]
```
--------------------------------
### 复制编译产物到应用目录
Source: https://developer.fnnas.com/docs/core-concepts/native
将构建好的前端和后端代码复制到飞牛 fnOS 应用的指定目录中。
```bash
mkdir notepad/fnnas.notepad/app/server
cp -r notepad/dist/* notepad/fnnas.notepad/app/server/
```
--------------------------------
### Switch Toggle Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Implement a simple on/off switch for boolean settings, like enabling automatic backups. It has an initial value of 'true'.
```json
{
"type": "switch",
"field": "wizard_enable_backup",
"label": "启用自动备份",
"initValue": "true"
}
```
--------------------------------
### Configure Node.js Environment
Source: https://developer.fnnas.com/docs/core-concepts/runtime
Configure the PATH to include the Node.js v22 bin directory. This ensures the correct node and npm commands are available in the current session.
```bash
# Optional versions: nodejs_v22, nodejs_v20, nodejs_v18, nodejs_v16, nodejs_v14
export PATH=/var/apps/nodejs_v22/target/bin:$PATH
# Confirm node version
node -v
# Confirm npm version
npm -v
```
--------------------------------
### App Directory Structure
Source: https://developer.fnnas.com/docs/quick-started/create-application
Defines the expected file and folder organization for the HelloFnosAppCenter application.
```plaintext
HelloFnosAppCenter
├── css
│ └── style.css
├── images
│ └── logo.png
├── index.html
└── js
└── main.js
```
--------------------------------
### Configure Data Sharing Resources
Source: https://developer.fnnas.com/docs/core-concepts/resource
Define directories to share with users and their access permissions (read-only or read-write). Shares are visible in the system's file manager under 'Application Files'.
```json
{
"data-share": {
"shares": [
{
"name": "documents",
"permission": {
"rw": ["myapp_user"]
}
},
{
"name": "documents/backups",
"permission": {
"ro": ["myapp_user"]
}
}
]
}
}
```
--------------------------------
### 构建前端和后端
Source: https://developer.fnnas.com/docs/core-concepts/native
执行构建命令以生成可执行文件,为部署到飞牛 fnOS 做准备。
```bash
npm run build
```
--------------------------------
### Configure Docker Project Resources
Source: https://developer.fnnas.com/docs/core-concepts/resource
Define Docker Compose projects, specifying their name and the relative path to the directory containing the `docker-compose.yaml` file.
```json
{
"docker-project": {
"projects": [
{
"name": "myapp-stack",
"path": "docker"
}
]
}
}
```
--------------------------------
### Select Dropdown Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Configure a dropdown select box for choosing one option from a list, such as database types. A selection is mandatory.
```json
{
"type": "select",
"field": "wizard_database_type",
"label": "数据库类型",
"initValue": "sqlite",
"options": [
{
"label": "SQLite (推荐)",
"value": "sqlite"
},
{
"label": "MySQL",
"value": "mysql"
},
{
"label": "PostgreSQL",
"value": "postgresql"
}
],
"rules": [
{
"required": true,
"message": "请选择数据库类型"
}
]
}
```
--------------------------------
### 编辑应用配置 (resource)
Source: https://developer.fnnas.com/docs/core-concepts/native
配置应用的数据共享和读写权限,允许应用访问和修改共享数据。
```json
{
"data-share": {
"shares": [
{
"name": "fnnas.notepad",
"permission": {
"rw": [
"fnnas.notepad"
]
}
}
]
}
}
```
--------------------------------
### CSS Styling for App Center Demo
Source: https://developer.fnnas.com/docs/quick-started/create-application
Provides CSS for styling the App Center demo page, including global resets, body background, logo, and text elements with hover effects.
```css
/* 全局样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 页面整体样式 */
body {
font-family: "Microsoft YaHei", sans-serif; /* 字体设置 */
background: linear-gradient(120deg, #5f85ff, #48e08f); ; /* 页面蓝绿渐变背景*/
min-height: 100vh; /* 页面高度占满视口 */
display: flex; /* Flex布局:让内容垂直+水平居中 */
flex-direction: column;
align-items: center;
justify-content: center;
gap: 30px; /* 元素之间的间距 */
/* 渐变背景防重复 */
background-repeat: no-repeat;
}
/* Logo容器样式 */
.logo-container {
width: 120px; /* 容器宽度 */
height: 120px; /* 容器高度 */
border-radius: 50%; /* 圆形容器 */
overflow: hidden; /* 裁剪超出容器的图片 */
border: 3px solid #2563eb; /* 边框样式 */
box-shadow: 0 0 15px rgba(37, 99, 235, 0.4); /* 阴影效果 */
}
/* Logo图片样式 */
.logo {
width: 100%; /* 图片宽度占满容器 */
height: 100%; /* 图片高度占满容器 */
object-fit: cover; /* 图片等比缩放,填充容器 */
cursor: pointer; /* 鼠标悬浮显示手型 */
transition: transform 0.3s ease; /* 过渡动画(教学点:CSS动画) */
}
/* Logo悬浮效果 */
.logo:hover {
transform: scale(1.2); /* 鼠标悬浮放大1.2倍 */
}
.hello-container {
text-align: center; /* 文本居中 */
}
#helloText {
font-size: 48px; /* 字体大小 */
color: #303133; /* 字体颜色 */
transition: all 0.3s ease; /* 过渡动画 */
cursor: pointer;
}
/* 标题悬浮效果 */
#helloText:hover {
color: #2563eb; /* 悬浮变色 */
transform: translateY(-5px); /* 悬浮上移 5px */
/* 新增文字阴影,增强视觉层次 */
text-shadow: 0 2px 8px rgba(37, 99, 235, 0.3)
}
/* 提示文本样式 */
.tips {
margin-top: 15px;
font-size: 16px;
color: #64748b;
}
```
--------------------------------
### 安装和启动本地应用
Source: https://developer.fnnas.com/docs/core-concepts/native
在本地开发环境中安装项目依赖并启动应用,用于开发和测试。
```bash
npm install --workspaces
npm run start
```
--------------------------------
### Tips Text Display
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Use this to display informational text, links, or warnings to the user. It does not collect input.
```json
{
"type": "tips",
"helpText": "请阅读 隐私政策 了解我们如何处理您的数据。"
}
```
--------------------------------
### 编辑应用权限 (privilege)
Source: https://developer.fnnas.com/docs/core-concepts/native
定义应用运行的用户和组,确保应用以指定的权限运行。
```json
{
"defaults": {
"run-as": "package"
},
"username": "fnnas.notepad",
"groupname": "fnnas.notepad"
}
```
--------------------------------
### 编辑应用基本信息 (manifest)
Source: https://developer.fnnas.com/docs/core-concepts/native
配置飞牛 fnOS 应用的元数据,包括名称、版本、描述、架构等。
```properties
appname=fnnas.notepad
version=0.0.1
desc=A simple notepad
arch=x86_64
display_name=Notepad
maintainer=someone
distributor=someone
desktop_uidir=ui
desktop_applaunchname=fnnas.notepad.Application
source=thirdparty
```
--------------------------------
### Wizard File Structure
Source: https://developer.fnnas.com/docs/core-concepts/wizard
A wizard is defined as a JSON array, where each object represents a step with a title and a list of form items.
```json
[
{
"stepTitle": "第一步标题",
"items": [
// 表单项列表
]
},
{
"stepTitle": "第二步标题",
"items": [
// 表单项列表
]
}
]
```
--------------------------------
### Accessing Wizard Input via Environment Variables
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Explains that user selections from the wizard are converted into environment variables, using the field name directly as the variable name.
```bash
#!/bin/bash
```
--------------------------------
### Define Nested Dependencies (Flattened)
Source: https://developer.fnnas.com/docs/core-concepts/dependency
The application center only checks one level of dependency. For nested dependencies (e.g., App A depends on App B, and App B depends on App C), you must explicitly declare all dependencies in the `manifest` file by listing them all in `install_dep_apps`.
```properties
# 嵌套依赖的平铺定义
install_dep_apps=depB:depC
```
--------------------------------
### JavaScript for App Center Interaction
Source: https://developer.fnnas.com/docs/quick-started/create-application
Adds interactivity to the App Center demo page by handling click events on the heading to change text and display an alert.
```javascript
// 教学点1:DOM 获取元素
const helloText = document.getElementById('helloText');
// 教学点2:绑定点击事件(交互核心)
helloText.addEventListener('click', function() {
// 教学点3:修改 DOM 内容(动态改变文本)
const originalText = 'Hello fnOS AppCenter !';
const newText = '👋 你好,飞牛应用中心先锋开发者!';
if (helloText.innerText === originalText) {
helloText.innerText = newText;
// 教学点4:弹出提示框(基础交互)
alert('🎉 JS交互生效啦!文本已修改~');
} else {
helloText.innerText = originalText; // 还原文本
}
});
// 教学点5:控制台输出(调试常用)
console.log('✅ 外部JS文件加载成功!');
console.log('🔍 当前点击的元素:', helloText);
```
--------------------------------
### Password Input Field Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Configure a password input field for sensitive information. Input is masked with asterisks and can have minimum length requirements.
```json
{
"type": "password",
"field": "wizard_password",
"label": "管理员密码",
"rules": [
{
"required": true,
"message": "请输入密码"
},
{
"min": 6,
"message": "密码长度不能少于6位"
}
]
}
```
--------------------------------
### Write Error to Log and Exit
Source: https://developer.fnnas.com/docs/core-concepts/framework
This snippet demonstrates how to write an error message to the TRIM_TEMP_LOGFILE environment variable and exit with an error code of 1. This is used for custom error reporting in scripts.
```bash
echo "Error: Something went wrong" > $TRIM_TEMP_LOGFILE
exit 1
```
--------------------------------
### Text Input Field Configuration
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Use this for collecting user text input like usernames or emails. It supports required and length validation rules.
```json
{
"type": "text",
"field": "wizard_username",
"label": "用户名",
"initValue": "admin",
"rules": [
{
"required": true,
"message": "请输入用户名"
},
{
"min": 3,
"max": 20,
"message": "用户名长度应在3-20个字符之间"
}
]
}
```
--------------------------------
### Exact Length Validation Rule
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Use this rule to ensure the input has a specific, exact length, such as for verification codes.
```json
{
"len": 6,
"message": "请输入6位验证码"
}
```
--------------------------------
### Regular Expression Validation Rule
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Configure validation using a regular expression pattern to match specific character sets or formats.
```json
{
"pattern": "^[a-zA-Z0-9_]+$",
"message": "只能包含字母、数字和下划线"
}
```
--------------------------------
### Length Restriction Validation Rule
Source: https://developer.fnnas.com/docs/core-concepts/wizard
Apply this rule to limit the input length to a minimum and maximum character count.
```json
{
"min": 3,
"max": 50,
"message": "长度应在3-50个字符之间"
}
```
--------------------------------
### Required Field Validation Rule
Source: https://developer.fnnas.com/docs/core-concepts/wizard
This rule enforces that a field must not be empty.
```json
{
"required": true,
"message": "此字段不能为空"
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.