使用 JavaScript 开发 Windows 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3609924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:09:21  来源:igfitidea点击:

Developing Windows apps with JavaScript

javascriptwindows

提问by Luca Matteis

I'm currently in the need of developing a Windows application. I want to keep things simple (in the spirit of uTorrent) and I would like the result program to be a single .exe file containing all that it needs.

我目前需要开发 Windows 应用程序。我想让事情变得简单(本着 uTorrent 的精神)并且我希望结果程序是一个包含它需要的所有内容的单个 .exe 文件。

The program is simple. It just needs some UI. It needs to run for a long period of time (lay there as a tray icon). It needs to do some routine tasks like simple I/O. It also needs to access the internet, specifically some web server.

该程序很简单。它只需要一些用户界面。它需要运行很长时间(作为托盘图标放置在那里)。它需要执行一些常规任务,例如简单的 I/O。它还需要访问互联网,特别是一些网络服务器。

Apart from these small requirements I would like to write all of it in JavaScript, as I feel more comfortable with it than any other language.

除了这些小的要求,我想用 JavaScript 编写所有这些,因为我觉得它比任何其他语言都更舒服。

I know there's things like Windows Script Host that let you run JavaScript programs and interact with some Win32 API, but will I be able to do everything I need with Windows Script Host? Can I pack all of the Windows Script Host in a single .exe?

我知道 Windows Script Host 之类的东西可以让您运行 JavaScript 程序并与某些 Win32 API 交互,但是我是否能够使用 Windows Script Host 完成我需要的一切?我可以将所有 Windows 脚本宿主打包在一个 .exe 中吗?

If not, what alternatives do I have for JavaScript?

如果没有,我有哪些 JavaScript 替代方案?

采纳答案by Luca Matteis

I found that there's actually a JavaScript compiler that comes with the .NET framework called jsc.exe.

我发现实际上有一个 .NET 框架附带的 JavaScript 编译器,称为jsc.exe.

For more information:

想要查询更多的信息:

http://www.phpied.com/make-your-javascript-a-windows-exe/

http://www.phpied.com/make-your-javascript-a-windows-exe/

http://msdn.microsoft.com/en-us/library/7435xtz6(VS.80).aspx

http://msdn.microsoft.com/en-us/library/7435xtz6(VS.80).aspx

I guess it's not really JavaScript since it introduces extra things like importand even some classsyntax which is weird for me. But this works perfectly for me as I will just doing things as I am used to on the web.

我想它不是真正的 JavaScript,因为它引入了额外的东西import,甚至一些class对我来说很奇怪的语法。但这对我来说非常有效,因为我只会像在网络上那样做事。

回答by Jason Cramer

It seems that nobody mentioned JSDB.

似乎没有人提到JSDB

JSDB offers a command line environment which you can execute arbitrary javascript code. You can easily compile to a .exe file by using the command copy /b jsdb.exe+program.zip program.exe

JSDB 提供了一个命令行环境,您可以在其中执行任意 javascript 代码。您可以使用以下命令轻松编译为 .exe 文件copy /b jsdb.exe+program.zip program.exe

It's important to know that you've got to call your main js file main.js within a standard zip file. Not sure if the name program.zip is required.

重要的是要知道您必须在标准 zip 文件中调用您的主 js 文件 main.js。不确定是否需要名称 program.zip。

I haven't actually tried making GUI applications with this yet - although it seems to support various APIs like ActiveX.

我还没有真正尝试过用它制作 GUI 应用程序 - 尽管它似乎支持各种 API,如 ActiveX。

It's possible that by using the copy /b command mentioned above, you could compile a script from the wscript.exe file - but I tried and couldn't get it working. Let me know if anybody tries and has success somehow.

有可能通过使用上面提到的 copy /b 命令,您可以从 wscript.exe 文件编译脚本 - 但我尝试过但无法使其正常工作。如果有人尝试并以某种方式取得成功,请告诉我。

回答by Andy E

Aside from Windows Script Host, there are

除了 Windows Script Host,还有

Both are written with standard web technologies, HTML, JavaScript, Flash, etc. They can also be extended with COM objects/ActiveX controls such as FileSystemObject, WMI, WScript or even ones that you write yourself. Windows Desktop Gadgets have access to a separate API/namespace with various Win32-esque properties and methods.

两者都是用标准 Web 技术、HTML、JavaScript、Flash 等编写的。它们也可以使用 COM 对象/ActiveX 控件(如 FileSystemObject、WMI、WScript 甚至您自己编写的控件)进行扩展。Windows 桌面小工具可以访问具有各种 Win32 式属性和方法的单独 API/命名空间。

回答by Ryan Kinal

I think you're looking for Adobe AIR

我认为您正在寻找Adobe AIR

The Adobe? AIR? 2 runtime enables developers to use HTML, JavaScript, Adobe Flash? software, and ActionScript? to build web applications that run as standalone client applications without the constraints of a browser. ~ The AIR website

奥多比?空气?2 运行时使开发人员能够使用 HTML、JavaScript、Adobe Flash?软件和 ActionScript?构建作为独立客户端应用程序运行的 Web 应用程序,不受浏览器的限制。~ AIR 网站

回答by rochal

I believe the best way to go is V8 JavaScript Engineprovided by Google.

我相信最好的方法是谷歌提供的V8 JavaScript 引擎

"V8can run standalone, or can be embedded into any C++ application." - which I believe is perfect for your needs, because you can do most of the stuff in JavaScript and use provided interfaces to communicate with the system.

V8可以独立运行,也可以嵌入到任何 C++ 应用程序中。” - 我认为这非常适合您的需求,因为您可以在 JavaScript 中完成大部分工作,并使用提供的接口与系统进行通信。

回答by Pekka

Internet Explorer introduced the concept of Hypertext Applicationsin IE 5. It never made a big breakthrough, so resources and documentation are scarce.

Internet Explorer在 IE 5 中引入了超文本应用程序的概念。它从未有过大的突破,因此资源和文档都很稀缺。

Mozilla-backed competitor Prismseems to be alive and well, though, and is definitely worth a look.

不过,Mozilla 支持的竞争对手Prism似乎还活着,而且绝对值得一看。

Prism is an application that lets users split web applications out of their browser and run them directly on their desktop

Prism 是一个应用程序,它允许用户将 Web 应用程序从浏览器中分离出来,并直接在他们的桌面上运行

回答by Angelo R.

I'm not 100% but I believe WSH uses JScript or WScript, not JavaScript.

我不是 100% 但我相信 WSH 使用 JScript 或 WScript,而不是 JavaScript。

回答by Angelo R.

Color me crazy, but its only a short step form Javascript to Java or C#. I'd suggest C# as, on a windows machine, the libraries are already there. You can just copypaste your .exe and let 'er rip.

让我疯狂,但它只是从 Javascript 到 Java 或 C# 的一小步。我建议使用 C#,因为在 Windows 机器上,库已经存在。您只需复制粘贴您的 .exe 文件,然后就可以破解了。

回答by zumalifeguard

If you want a single .EXE, what runtimes are you okay if they are required pre-requisites?

如果你想要一个单一的 .EXE,如果它们是必需的先决条件,你可以使用什么运行时?

If you're okay with requiring .NET runtime to be preinstalled, then you do all your work in JScript.NET

如果您同意要求预装 .NET 运行时,那么您可以在 JScript.NET 中完成所有工作

回答by bygreencn

Chromium Embedded Framework (CEF) may give you some help. i have not clearly know how, but i realy found many Apps using this framework.

Chromium Embedded Framework (CEF) 可能会给你一些帮助。我还不清楚是怎么做的,但我确实找到了很多使用这个框架的应用程序。

http://code.google.com/p/chromiumembedded/

http://code.google.com/p/chromiumembedded/

Introduce for CEF are: The Chromium Embedded Framework (CEF) is an open source project founded by Marshall Greenblatt in 2008 to develop a Web browser control based on the Google Chromium project. CEF currently supports a range of programming languages and operating systems and can be easily integrated into both new and existing applications. It was designed from the ground up with both performance and ease of use in mind. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and WebKit implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser.

CEF 的介绍是: Chromium Embedded Framework (CEF) 是一个开源项目,由 Marshall Greenblatt 于 2008 年创立,旨在开发基于 Google Chromium 项目的 Web 浏览器控件。CEF 目前支持多种编程语言和操作系统,并且可以轻松集成到新的和现有的应用程序中。它的设计从头开始就兼顾了性能和易用性。基础框架包括通过本机库公开的 C 和 C++ 编程接口,这些库将主机应用程序与 Chromium 和 WebKit 实现细节隔离开来。它提供浏览器控件和主机应用程序之间的紧密集成,包括对自定义插件、协议、JavaScript 对象和 JavaScript 扩展的支持。宿主应用程序可以选择性地控制资源加载、导航、

Numerous individuals and organizations contribute time and resources to support CEF development, but more involvement from the community is always welcome. This includes support for both the core CEF project and external projects that integrate CEF with additional programming languages and frameworks (see the "External Projects" section below).

许多个人和组织贡献了时间和资源来支持 CEF 的发展,但社区的更多参与总是受欢迎的。这包括对核心 CEF 项目和将 CEF 与其他编程语言和框架集成的外部项目的支持(请参阅下面的“外部项目”部分)。