欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > Photino:通过.NET Core构建跨平台桌面应用程序,.net国产系统

Photino:通过.NET Core构建跨平台桌面应用程序,.net国产系统

2025/5/11 0:41:20 来源:https://blog.csdn.net/u010919083/article/details/143926868  浏览:    关键词:Photino:通过.NET Core构建跨平台桌面应用程序,.net国产系统

一、Photino.NET简介:

最近发现了一个不错的框架 Photino.Net 一份代码运行,三个平台 windows max linux ,其中windows10,windows11,ubuntu 18.04,ubuntu 20.04 已测试均可以。mac 因为没有相关电脑没有测试。

github:https://github.com/tryphotino/photino.NET

二、示例代码

首先创建一个控制台程序:

添加如下代码:

using Photino.NET;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;namespace PhotinoNetDemo
{internal class Program{private static PhotinoWindow? _window;private static Timer? _timer;[STAThread]static void Main(string[] args){Console.WriteLine("Hello, World!");// 隐藏控制台窗口HideConsoleWindow();_window =new PhotinoWindow().RegisterWebMessageReceivedHandler(WebMessageHandler).SetIconFile("wwwroot/app.ico").Load("wwwroot/index.html");//.Load("wwwroot/menu.html");_timer = new Timer(UpdateMessage);_window.WaitForClose();  }private static void UpdateMessage(object? state){try{SendWebMessage("updateTime",$"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");}catch (Exception e){Console.WriteLine(e);}}private static void WebMessageHandler(object? sender, string e){switch (e){case "start":_timer.Change(0, 1);break;default:break;}SendWebMessage("updateWebMessage",$"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}后台收到:{e}");}public static void SendWebMessage(string methodName, object message){// 创建 JsonSerializerOptions 实例var options = new JsonSerializerOptions{// 设置 Encoder 属性,允许所有Unicode范围,不进行转义Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)};string str = $"{methodName},{System.Text.Json.JsonSerializer.Serialize(message, options)}";_window!.SendWebMessage(str);}[MyCustomAttribute(methodName:"addMessage")]public static void AddMessage() { }// 导入Windows API函数[DllImport("kernel32.dll")]static extern IntPtr GetConsoleWindow();[DllImport("user32.dll")]static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);private const int SW_HIDE = 0;// 调用Windows API隐藏控制台窗口private static void HideConsoleWindow(){IntPtr consoleHandle = GetConsoleWindow();if (consoleHandle != IntPtr.Zero){ShowWindow(consoleHandle, SW_HIDE);}}}
}

添加文件wwwroot

创建index.html

<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head><meta charset="utf-8" /><title></title>
</head>
<body><h1>当前时间:<span style="color:red;" id="currentTime"></span></h1><button onclick="start()">开始时间</button><button onclick="fun1()">发送到后台</button><button onclick="fun2()">跳转</button><div id="div1"></div>
</body>
<script type="text/javascript">function start() {window.external.sendMessage("start");}function fun1() {window.external.sendMessage("111");}function fun2() {window.location = "menu.html";}window.external.receiveMessage(message => { console.log(message);let methodName = message.split(',')[0];let params = message.split(',')[1];switch (methodName) {case "updateTime":debugger;document.getElementById("currentTime").innerHTML = params; break;case "updateWebMessage":document.getElementById("div1").innerHTML += message + "</br>";break;default: break;}});
</script>
</html>

发布测试,全量包x64

 

 三、跨平台测试

 全量包才60m ,太牛了。关键还跨平台。

 四、信创支持 国产系统

国产系统目前测试了麒麟V10 ,安装过程虽然麻烦点,但已经成功运行,图片如下:

 五、展望

 不错的技术,持续关注中。本篇文章也会陆续补充测试过程,过程中遇到的问题!!!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词