开机启动雷电模拟器 全屏 启动指定app

因为项目需要在一台触摸一体机上浏览VR网页,但是window对VR网页的触摸控制基本无效,所以考虑将一体机刷成android_x86.但是android_x86的网站一直打不开,没办法,只能用模拟器试试,于是有了下面这番折腾,记录一下,免得下次还要重新想

一.将vr网页打包成安卓app.

1.创建vr场景网页项目

新建一个react项目,将所有的vr场景网页放入public目录.将所有的vr场景连接放入组件,点击后使用iframe展示

import React, { useState } from "react";
import "./thumbnail.css";

const roomList = [
  "报告厅",
  "大厅",
  "公共安全",
  "火灾逃生通道",
  "家庭安全",
  "交通安全",
  "入口",
  "消防安全",
  "校园安全",
  "心理健康咨询",
  "应急救护",
];

const Thumbnail = () => {
  const [selectedRoom, setSelectedRoom] = useState("");

  const handleClick = (room: string) => {
    setSelectedRoom(room);
  };

  const handleBackClick = () => {
    setSelectedRoom("");
  };

  const findIndex = (room: string) => {
    const res = roomList.findIndex((item) => item === room) + 1;
    console.log(res);
    return res + "";
  };

  return (
    <div className="thumbnail">
      {selectedRoom ? (
        <iframe
          src={`./assets/vr/${findIndex(selectedRoom)}/pano/index.html`}
          style={{ width: "100%", height: "100%" }}
          title={selectedRoom}
        />
      ) : (
        <>
          <img src="./assets/map.png" alt="地图" className="thumbnail-bg" />
          {roomList.map((room, index) => {
            return (
              <img
                src="./assets/camera.png"
                alt="房间"
                className={`camera ${room}`}
                onClick={() => handleClick(room)}
              />
            );
          })}
        </>
      )}
      {selectedRoom && (
        <img
          src="./assets/return.png"
          alt="返回"
          className="back-button"
          onClick={handleBackClick}
        />
      )}
    </div>
  );
};

export default Thumbnail;

重点在package.json增加  "homepage": "./",否则打包出来的app是空白的

  "homepage": "./",

运行项目,查看是否成功

yarn start

如果运行正确,则build项目

yarn build

2.打包app

注册账号,并下载HBuilder X,创建空的5+app项目

将上面build出来的react项目build目录中,除了manifest.json(重点),复制进新建的5+app目录

删除无用的空目录 .

在HBuilder X中双击manifest.json,进行app配置

 生成图标

由于此app只是浏览vr网页,无需任何权限,所以在模块配置中,去掉所有模块

在app常用其他设置中选择支持的cpu类型

打包,发行->云打包

 等待打包成功,后在目录中找到app

二.使用golang编写启动模拟器和app的程序

 1.编写yaml配置文件config.yaml

file_location: "D:\\leidian\\LDPlayer9\\dnplayer.exe"
wait_time: 10
send_key: "f11"
execute_command:
  command: "D:\\leidian\\LDPlayer9\\dnconsole.exe"
  parameters:
    - "runapp"
    - "--index"
    - "0"
    - "--packagename"
    - "com.xx.kkllhh"

 file_location为模拟器的地址

wait_time为等待模拟器启动的时间,单位是秒

send_key为设置模拟器全屏的快捷键,f大写无效

execute_command为运行指定app的命令,需按实际修改最后一行的"com.xx.kkllhh"包名.包名可以在云打包的界面中查看

2.golang程序

package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"time"

	"github.com/go-vgo/robotgo"
	"gopkg.in/yaml.v2"
)

type Config struct {
	FileLocation   string `yaml:"file_location"`
	WaitTime       int    `yaml:"wait_time"`
	SendKey        string `yaml:"send_key"`
	ExecuteCommand struct {
		Command    string   `yaml:"command"`
		Parameters []string `yaml:"parameters"`
	} `yaml:"execute_command"`
}

func main() {
	config := readConfig("config.yaml")

	// Open the exe program
	fmt.Println("Opening the exe program...")
	cmd := exec.Command(config.FileLocation)
	err := cmd.Start()
	if err != nil {
		fmt.Printf("Error starting the program: %v\n", err)
		return
	}

	// Wait for the specified duration
	waitWithCountdown(config.WaitTime)

	// Activate the window
	fmt.Println("Activating the window...")
	pid := int32(cmd.Process.Pid)
	robotgo.ActivePID(pid)

	// Move the mouse
	fmt.Println("Moving the mouse...")
	moveMouse()
	//等待1秒
	time.Sleep(1 * time.Second)
	// Send the specified key
	fmt.Printf("Sending key: %s\n", config.SendKey)
	robotgo.KeyTap(config.SendKey)

	//等待1秒
	time.Sleep(1 * time.Second)
	// Execute the command
	fmt.Println("Executing the command...")
	command := exec.Command(config.ExecuteCommand.Command, config.ExecuteCommand.Parameters...)
	commandOutput, err := command.CombinedOutput()
	if err != nil {
		fmt.Printf("Error executing command: %v\n", err)
		return
	}
	fmt.Printf("Command output: %s\n", string(commandOutput))
}

func readConfig(configFile string) Config {
	data, err := ioutil.ReadFile(configFile)
	if err != nil {
		fmt.Printf("Error reading config file: %v\n", err)
		os.Exit(1)
	}

	var config Config
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		fmt.Printf("Error unmarshalling config file: %v\n", err)
		os.Exit(1)
	}

	return config
}

func waitWithCountdown(seconds int) {
	for i := seconds; i > 0; i-- {
		fmt.Printf("Waiting... %d seconds remaining\n", i)
		time.Sleep(1 * time.Second)
	}
}

func moveMouse() {
	// 首先直接鼠标位置设置为 (800, 800)
	robotgo.Move(800, 800)

	// 然后,完成一次点击,(按下弹起)
	robotgo.Click("left")

	// 注意鼠标两次点击之间应当有一个时间间隔,否则可能不会触发双击的
	time.Sleep(100 * time.Millisecond)

	// 再来一次点击
	robotgo.Click("left")

	// 等待 2 秒钟(2000 毫秒)
	time.Sleep(2 * time.Second)

	// 将鼠标光标移动到另一个位置(2000, 2000)
	robotgo.Move(2000, 2000)
}

go程序的作用是打开模拟器->等待配置文件中设置的等待时间->移动鼠标点击模拟器->发送全屏快捷键->执行打开指定app的命令

三.在pc中的设置

1.将golang编译出来的程序和配置文件拷入D盘

  2.在windows的启动目录中放入start.exe的快捷方式,并将start.exe修改为管理员权限

 重启PC,自动启动模拟器,然后启动指定app

已经编译好的go程序和配置文件

自动启动雷电模拟器,然后启动指定app-其他文档类资源-CSDN文库

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值