uniapp h5 生成 ubuntu桌面程序 并运行方法

news2024/10/1 23:40:09

uniapp h5 生成 ubuntu桌面程序 并运行方法,在window环境下开发,发布到ubuntu桌面,并运行

1、安装Nodejs

安装包官方下载地址:https://www.nodejs.com.cn/

安装完后cmd,如图,即安装成功

2、通过Nodejs安装 electron

window的cmd命令下执行

官方推荐的如下命令

npm install --save-dev electron

报错

网络问题,国外的东西

改用以下方法

npm install -g cnpm --registry=https://registry.npm.taobao.org

使用 cnpm 进行安装

cnpm i electron --save-d
cnpm install electron-packager -g

这样就成功了

二、uniapp发布

1、修改项目运行路径./

2、发布程序

3、发布后的目录

F:\vue\HBuilderProjects\IotTouchScreen_PM1001\unpackage\dist\build\h5

在下面新建两个文件,main.js和package.json

package.json 写入内容

{  "name"    : "exam",  "version" : "0.1.0",  "main"    : "main.js"}

main.js写入内容

const {
app,
BrowserWindow,
ipcMain
} = require('electron')
const fs = require('fs')
const electron = require('electron')
const path = require('path')
const url = require('url')
 
// ipcMain.on('asynchronous-message', function(event, arg) {
//    // arg是从渲染进程返回来的数据
//   console.log(arg,1);
 
//   // 这里是传给渲染进程的数据C:/Users/Administrator/Desktop/test.txt
//   fs.readFile(path.join(__dirname,"./test.txt"),"utf8",(err,data)=>{
//    if(err){
// event.sender.send('asynchronous-reply', "读取失败");
// }else{
// event.sender.send('asynchronous-reply', data);
// }
 
//   })
// });
 
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
const Menu = electron.Menu
 
function createWindow() {
// Create the browser window.
// Menu.setApplicationMenu(null)
 
//解决点击窗口最大化样式整体过大问题
const WIDTH = 1860
const HEIGHT = 900
const aspectRatio = WIDTH / HEIGHT // 窗口宽高比
 
 
win = new BrowserWindow({
fullscreen: true,//(设置默认打开满屏)
// width: 800,
// height: 600,
// width: WIDTH,
// height: HEIGHT,
frame: false, // 无边框窗口
webPreferences: {
nodeIntegration: true, // 使渲染进程拥有node环境
 
},
icon: path.join(__dirname, 'icon.ico') // 设置ico
 
})
 
 
win.once('ready-to-show', () => {
// 限制窗口最小尺寸(int整形), 无边框模式下,不考虑标题栏高度
win.setMinimumSize(WIDTH / 2, HEIGHT / 2)
win.show()
})
 
// 控制等比缩放
win.on('will-resize', resizeWindow)
 
function resizeWindow(event, newBounds) {
const wins = event.sender
event.preventDefault() // 拦截,使窗口先不变
const currentSize = wins.getSize()
const widthChanged = currentSize[0] !== newBounds.width // 判断是宽变了还是高变了,两者都变优先按宽适配
// ! 虽然搞不懂为何有1px偏差,但是可以解决问题(Windows 10)
if (widthChanged) {
wins.setContentSize(newBounds.width - 1, parseInt(newBounds.width / aspectRatio + 0.5) - 1)
} else {
wins.setContentSize(parseInt(aspectRatio * newBounds.height + 0.5) - 1, newBounds.height - 1)
}
}
 
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
//cpu
 
 
// Open the DevTools.
// win.webContents.openDevTools()
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
 
// ipcMain.on('asynchronous-message', function(event, arg) {
//    // arg是从渲染进程返回来的数据
//   console.log(arg,2);
 
//   // 这里是传给渲染进程的数据C:/Users/Administrator/Desktop/test.txt
//   fs.readFile(path.join(__dirname,"./test.txt"),"utf8",(err,data)=>{
//    if(err){
// event.sender.send('asynchronous-reply', "读取失败");
// }else{
// event.sender.send('asynchronous-reply', data);
// }
 
//   })
// });
}
 
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
 
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
 
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
 
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
 
 
 

4、打包到目录运行平台win x64(玩熟了修改目标平台即可发到ubuntu),用window的cmd命令下执行指令

1.electron-packager . 可执行文件的文件名 --win --out 打包成的文件夹名 --arch=x64位还是32位 --electron-version版本号(不是你的h5版本号,是electron版本号,上面第一步安装的electron的版本号) --overwrite --ignore=node_modules
例如:

electron-packager . myAPP --win --out appDist --arch=x64 --electron-version 28.1.4 --overwrite --ignore=node_modules

也是网络问题,timeout问题

解决方法

发布到win x64

electron-packager . appName --platform=win32 --electron-version=28.1.4  --arch=x64 --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/ --asar --app-version=0.0.0 --build-version=0.0.0 --out=outName --overwrite --no-package-manager --ignore="(.git)" --icon=logo.ico
 

发布到ubuntu arm64

electron-packager . appName --platform=linux --electron-version=28.1.4  --arch=arm64 --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/ --asar --app-version=0.0.0 --build-version=0.0.0 --out=outName --overwrite --no-package-manager --ignore="(.git)" --icon=logo.ico

会在当前目录下生成一个 outName 文件夹,下面就是发布后的程序

三、ubuntu arm64环境上运 行

把程序通过ssh复制到ubuntu上面  如: /usr/app/

通过桌面运行指令

cd /usr/app/

权限

chmod 777 appName

运行

./appName

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1402468.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于大整形的运算收录

目录 目录 目录 前言 为什么要大整数 大整形的加/减法 大整形的乘法 大整形除法 大整形开方 代码实现 前言 好久没有更新博客了,hhh。时隔三个月,我又回来了。先来点简单的大整形,虽说简单,但是在编写的时候还是debug了…

redis优化系列(六)

本期分享redis内存过期策略:过期key的处理 Redis之所以性能强,最主要的原因就是基于内存存储。然而单节点的Redis其内存大小不宜过大,会影响持久化或主从同步性能。 可以通过修改配置文件来设置Redis的最大内存: maxmemory 1gb …

远程登录Linux服务器:命令+工具版

通常在工作过程中,公司中使用的真实服务器或者是云服务器,都不允许除运维人员之外的员工直接接触,因此就需要通过远程登录的方式来操作。 所以,远程登录工具就是必不可缺的,目前,比较主流的有 Xshell,SSHS…

京东云开发者DDD妙文欣赏(2)报菜名和化繁为简的创新

DDD领域驱动设计批评文集 做强化自测题获得“软件方法建模师”称号 《软件方法》各章合集 京东云开发者原文链接:DDD落地实践-架构师眼中的餐厅>>,以下简称《餐厅》。 我截图时,阅读量有6044,在同类文章中已经算是热文了…

C++ | 头文件

头文件(.h): 写类的声明(包括类里面的成员和方法的声明)、函数原型、#define常数等,但一般来说不写出具体的实现。 注: 1)头文件中只能写声明,不能写定义;2&#xff09…

【论文解读】PV-RCNN: Point-Voxel Feature Set Abstraction for 3D Object Detection

PV-RCNN 摘要引言方法3D Voxel CNN for Efficient Feature Encoding and Proposal GenerationVoxel-to-keypoint Scene Encoding via Voxel Set AbstractionKeypoint-to-grid RoI Feature Abstraction for Proposal Refinement 实验结论 摘要 我们提出了一种新的高性能3D对象检…

Kotlin协程的JVM实现源码分析(下)

协程 根据 是否保存切换 调用栈 ,分为: 有栈协程(stackful coroutine)无栈协程(stackless coroutine) 在代码上的区别是:是否可在普通函数里调用,并暂停其执行。 Kotlin协程&…

Apifox适用于API测试、管理的工具

一、产品介绍 Apifox是一款强大的API管理工具,它可以帮助开发人员和团队高效地设计、开发、测试、部署和管理API。Apifox提供了丰富的功能,如API文档生成、版本控制、团队协作、性能监控等,让API开发和管理变得更加简单和高效。 二、应用场…

2023 年值得一读的技术文章 | NebulaGraph 技术社区

在之前的产品篇,我们了解到了 NebulaGraph 内核及周边工具在 2023 年经历了什么样的变化。伴随着这些特性的变更和上线,在【文章】博客分类中,一篇篇的博文记录下了这些功能背后的设计思考和研发实践。当中,既有对内存管理 Memory…

【LeetCode】每日一题 2024_1_21 分割数组的最大值(二分)

文章目录 LeetCode?启动!!!题目:分割数组的最大值题目描述代码与解题思路 LeetCode?启动!!! 今天是 hard,难受,还好有题解大哥的清晰讲解 题目&a…

十一、K8S-ingress

目录 一、什么是Ingress 1、为什么要用ingress: 2、ingress概念: 1、pod漂移问题 ​编辑 2、端口管理的问题: 3、域名分配及动态更新问题 3、Ingress-nginx 工作原理 4、ingress-controller工作原理 5、ingress部署原理 1、Deploy…

【UEFI基础】EDK网络框架(TCP4)

TCP4 TCP4协议说明 相比UDP4,TCP4是一种面向连接的通信协议,因此有更好的可靠性。 TCP4的首部格式如下: 各个参数说明如下: 字段长度(bit)含义Source Port16源端口,标识哪个应用程序发送。D…

爬虫案例—爬取ChinaUnix.net论坛板块标题

爬虫案例—爬取ChinaUnix.net论坛板块标题 ChinaUnix.net论坛网址:http://bbs.chinaunix.net 目标:抓取各个板块的标题和内容的标题 网站截图: 利用requests和xpath实现目标。源码如下: import requests from lxml import etr…

Vue——计算属性

文章目录 计算属性computed 计算属性 vs methods 方法计算属性完整写法 综合案例:成绩案例 计算属性 概念:基于现有的数据,计算出来的新属性。依赖的数据变化,自动重新计算 语法: ①声明computed配置项中,一个计算属性…

vue3-模版引用ref

1. 介绍 概念&#xff1a;通过 ref标识 获取真实的 dom对象或者组件实例对象 2. 基本使用 实现步骤&#xff1a; 调用ref函数生成一个ref对象 通过ref标识绑定ref对象到标签 代码如下&#xff1a; 父组件&#xff1a; <script setup> import { onMounted, ref } …

必看——SSL安全证书

SSL&#xff08;Secure Socket Layer&#xff09;安全证书是一种用于确保在网络上数据传输过程中的安全性和加密性的数字证书。SSL证书通过对数据进行加密&#xff0c;确保敏感信息在用户和服务器之间的传输过程中不被窃取或篡改。下面是获取和配置SSL安全证书的基本步骤&#…

【大数据】YARN常用命令及Rest API

YARN 1.YARN常用命令 1.1 作业 命令说明yarn application -list列出所有的applicationyarn application -list -appStates [ALL、NEW、NEW_SAVING、SUBMITTED、ACCEPTED、RUNNING、FINISHED、FAILED、KILLED]根据application状态过滤yarn application -kill [applicationId]…

【GitHub项目推荐--不错的 C 开源项目】【转载】

大学时接触的第一门语言就是 C语言&#xff0c;虽然距 C语言创立已过了40多年&#xff0c;但其经典性和可移植性任然是当今众多高级语言中不可忽视的&#xff0c;想要学好其他的高级语言&#xff0c;最好是先从掌握 C语言入手。 今天老逛盘点 GitHub 上不错的 C语言 开源项目&…

commit 历史版本记录修正

commit 历史版本记录修正 当 Bug 发生的时候&#xff0c;我们会需要去追踪特定 bug 的历史记录&#xff0c;以查出该 bug 真正发生的原因&#xff0c;这个时候就是版本控制带来最大价值的时候。 因此&#xff0c;要怎样维持一个好的版本记录是非常重要的&#xff0c;下面是一…

第91讲:MySQL主从复制集群主库与从库状态信息的含义

文章目录 1.主从复制集群正常状态信息2.从库状态信息中重要参数的含义 1.主从复制集群正常状态信息 通过以下命令查看主库的状态信息。 mysql> show processlist;在主库中查询当前数据库中的进程&#xff0c;看到Master has sent all binlog to slave; waiting for more u…