gpt4 book ai didi

java - 启动 webstart 而不下载...?

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:26 24 4
gpt4 key购买 nike

我制作了一个 Java webstart 应用程序,并创建了一个带有启动链接的 HTML 页面。问题是,在谷歌浏览器中,没有选项可以只“打开”一个文件而不保存它。我想制作一个可以自动启动 JNLP 文件而无需保存的 HTML 页面。或者更确切地说,用户无需打开文件资源管理器即可启动它)这可能吗?

最佳答案

在受够了这个问题之后,我围绕扩展编写了自己的工作。

它是在 ubuntu 下编写的,但应该是可移植的(甚至可以通过一些工作/阅读到 win32)。

单击即可启动 jnlp 文件,无需提示或下载。它只是将 jnlp 文件的 url 直接传递给 javaws。没有困惑的下载文件夹,没有额外的点击。

它简单、粗暴且有效。我过滤了 URL,因此它只适用于我自己的内部服务器,这样我就不会不小心启动一些随机的 jnlp 文件。我敢肯定,可以做更多的工作来改进它。按原样使用,无保修等。

文件:

/usr/local/bin/jnlp-launcher

#!/usr/bin/env python

import struct
import sys
import threading
import Queue
import json
import os


# On Windows, the default I/O mode is O_TEXT. Set this to O_BINARY
# to avoid unwanted modifications of the input/output streams.
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

# Helper function that sends a message to the webapp.
def send_message(message):
# Write message size.
sys.stdout.write(struct.pack('I', len(message)))
# Write the message itself.
sys.stdout.write(message)
sys.stdout.flush()

# Thread that reads messages from the webapp.
def read_thread_func(queue):
message_number = 0
while 1:
# Read the message length (first 4 bytes).
text_length_bytes = sys.stdin.read(4)

if len(text_length_bytes) == 0:
if queue:
queue.put(None)
sys.exit(0)

# Unpack message length as 4 byte integer.
text_length = struct.unpack('i', text_length_bytes)[0]

# Read the text (JSON object) of the message.
text = sys.stdin.read(text_length).decode('utf-8')

decoded = json.loads(text);
os.system("javaws " + decoded['url']);


def Main():
read_thread_func(None)
send_message('"complete"')
sys.exit(0)

if __name__ == '__main__':
Main()

chrome 扩展是放置在本地目录中的 2 个文件:

list .json

{
"manifest_version": 2,

"background": {
"persistent": false,
"scripts": [ "bg.js" ]
},

"name": "JNLP Fixer",
"description": "Handle JNLPs",
"version": "1.0",

"permissions": [
"downloads", "nativeMessaging"
]
}

和 bg.js(根据主机过滤器的需要进行编辑)

chrome.downloads.onCreated.addListener(function(downloadId) {
var expr = /\.jnlp$/;
//this is to limit where we apply the auto-launch.
//for our use, i only wanted it for internal jnlps.
var hostExpr = /(http|https):\/\/internal.company.com\//;
if (hostExpr.test(downloadId.url)) {
if (downloadId.state == "in_progress") {
console.log(downloadId.url);
chrome.downloads.cancel(downloadId.id,function() {
console.log("cancelled");
});
chrome.runtime.sendNativeMessage("com.hcs.jnlplauncher",
{url:downloadId.url},
function(response)
{
console.log(chrome.runtime.lastError);
console.log(response);
}
);
}
}

})

将 manifest.json 和 bg.js 放在一个文件夹中,并在 chrome://extensions 下的开发者模式下将其作为 Unpacked 扩展程序加载到 chrome 中

从 chrome://extensions 页面获取扩展的 ID。

接下来是扩展和 shell 脚本之间的桥梁。

文件:com.hcs.jnlplauncher.json

{
"name": "com.hcs.jnlplauncher",
"description": "JNLP Launcher",
"path": "/usr/local/bin/jnlp-launcher",
"type": "stdio",
"allowed_origins": [
"chrome-extension://iacomlhfiphkdfjjjmlgckdkhmkhkibe/"
]
}

将它放在“~/.config/google-chrome/NativeMessagingHosts”下(适用于 Linux)。请参阅 google 以获取 Windows 位置。

将上一步中的扩展程序 ID 放入该文件。

确保 javaws 在路径中。 (与 chrome 一起运行)。链接到/usr/bin 是最简单的方法。

单击 jnlp 文件并享受!!!没有提示,没有 ClickToOpen,也没有文件保存在下载目录中。!

如果有人想将这些全部捆绑到一个漂亮的打包安装程序和/或 chrome 扩展程序中,请随意。请相信我 (Chris Holt -- hobie744@gmail.com) 并让我知道。乍一看,我看不出如何将 NativeMessagingHosts 部分捆绑到扩展中。也许它必须是 2 件?这是我在 Chrome 扩展和 NativeMessaging 方面的第一次冒险。大部分代码来自 API 文档和示例,可能存在一些错误。

关于java - 启动 webstart 而不下载...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11679373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com