鸿蒙沙箱浏览器 - SandboxFinder

欢迎 🌟star : github.com/iHongRen/Sa...

一个专为 HarmonyOS 应用开发者设计的沙箱文件浏览器,通过内置 HTTP 服务器提供 Web 界面访问应用沙箱目录。

核心特性

🗂️ 沙箱文件系统

  • 内置 HTTP 服务器 - 基于 TCP Socket 实现的轻量级 HTTP 服务器
  • 多设备 - 支持模拟器和真机
  • 文件类型识别 - 智能识别文本、图片、视频、音频、SQLite 数据库等文件类型
  • 自定义端口 - 默认端口7777

🌐 Web 界面访问

  • 响应式 Web UI - 使用 Vue 3 + Tailwind CSS 构建的现代化界面
  • 快速访问 - 提供便捷的沙箱目录访问(filesDircacheDirtempDirdatabaseDir 等)
  • 预览 - 支持文本、图片、视频、音频、SQLite 数据库预览
  • 排序 - 支持按名称、大小、时间排序
  • 搜索 - 实时关键字搜索

📁 文件操作功能

  • 基础文件操作 - 创建、删除、重命名

  • 文件上传 - 支持大文件分块、批量、拖放上传

  • 下载 - 直链下载

快速开始

集成到项目
  1. 安装
sh 复制代码
ohpm install @cxy/sandboxfinder

添加依赖,然后同步

json5 复制代码
// oh-package.json5
{
  "dependencies": {
    "@cxy/sandboxfinder": "^1.0.0"
  }
}
  1. 导入并启动
typescript 复制代码
// EntryAbility.ets

// 导入BuildProfile,编译工程自动生成
import BuildProfile from 'BuildProfile'; 

onWindowStageCreate(windowStage: window.WindowStage): void {
  windowStage.loadContent('pages/Index', (err) => {
    if (err.code) {
      return;
    }

    // 推荐在 DEBUG 模式下使用 - 动态加载
    if (BuildProfile.DEBUG) {
      import('@cxy/sandboxfinder').then(async (ns: ESObject) => {
        // 默认绑定到端口 7777
        ns.SandboxFinder.run()
      });

      // 避免服务挂起,设置不息屏
      windowStage.getMainWindowSync().setWindowKeepScreenOn(true)
    }
  });
}
  1. 确保鸿蒙设备和电脑在同一网络, 获取访问地址: 查看打印log -> 搜索 '--'。

    或者直接查看设备IP:设置 -> WLAN -> 已连接的WIFI详情 -> IP地址。

sh 复制代码
 ----------------------------------------------------------
 
 沙箱浏览器启动成功
 请浏览器访问: http://192.168.2.38:7777
 
 ----------------------------------------------------------
  1. 浏览器直接访问: http://192.168.2.38:7777 (换成你的IP)

模拟器使用

沙箱浏览器开启后,模拟器需转发端口,才能访问。

sh 复制代码
# 查看模拟器设备
> hdc list targets   # 输出: 127.0.0.1:5555

# 转发端口 fport tcp:<localPort> tcp:<serverPort>
hdc -t 127.0.0.1:5555 fport tcp:7777 tcp:7777   

# 输出: Forwardport result:OK 表示成功

转发成功后,访问: http://127.0.0.1:7777 , 如果无法访问,关闭网络代理工具试试看。

SandboxFinder 类说明

1、SandboxFinder 提供了两个对外静态方法:

ts 复制代码
/**
 * 运行服务
 * @param port  端口号,默认7777
 * @param context UIAbilityContext, 默认 getContext()
 * @returns ServerInfo =》 { address: string , port: number }
 */
static async run(port: number = 7777,
  context: common.UIAbilityContext = getContext() as common.UIAbilityContext): Promise<ServerInfo>;
    
    
 /**
 * 停止服务
 */
static async stop();

2、查看 ServerInfo

ts 复制代码
// EntryAbility.ets  - onWindowStageCreate()
import('@cxy/sandboxfinder').then(async (ns: ESObject) => {
  // 绑定到端口 6666
  ns.SandboxFinder.run(6666, this.context).then((serverInfo: ESObject) => {
    console.log(JSON.stringify(serverInfo))
  })
});

作者

@仙银 其他鸿蒙相关开源作品,欢迎使用和 🌟star :

1、hpack - 鸿蒙内部测试分发,一键脚本打包工具

2、Open-in-DevEco-Studio - macOS 直接在 Finder 工具栏上,使用 DevEco-Studio 打开鸿蒙工程。

3、cxy-theme - DevEco-Studio 绿色背景主题

相关推荐
Georgewu10 小时前
【HarmonyOS 6】 The target can not be empty. check the build.profile,json5 file of
harmonyos
Georgewu10 小时前
【HarmonyOS 6】Install Failed: error: failed to install bundle.code:9568322
harmonyos
爱笑的眼睛1112 小时前
HarmonyOS 应用开发新范式:深入剖析 Stage 模型与 ArkTS 状态管理
华为·harmonyos
爱笑的眼睛1113 小时前
深入浅出 HarmonyOS ArkUI 3.0:基于声明式开发范式与高级状态管理构建高性能应用
华为·harmonyos
程序员潘Sir16 小时前
鸿蒙应用开发从入门到实战(一):鸿蒙应用开发概述
harmonyos
参宿四南河三19 小时前
Kotlin的Flow用法(实例加长加倍版)
app·响应式编程
敲代码的鱼哇19 小时前
跳转原生系统设置插件 支持安卓/iOS/鸿蒙UTS组件
android·ios·harmonyos
在下历飞雨20 小时前
Kuikly基础之状态管理与数据绑定:让“孤寡”计数器动起来
ios·harmonyos
在下历飞雨20 小时前
Kuikly基础之Kuikly DSL基础组件实战:构建青蛙主界面
ios·harmonyos
HarmonyOS小助手21 小时前
HEIF:更高质量、更小体积,开启 HarmonyOS 图像新体验
harmonyos·鸿蒙·鸿蒙生态