gpt4 book ai didi

javascript - 桌面应用程序上的共享设置位置

转载 作者:行者123 更新时间:2023-12-03 12:12:45 25 4
gpt4 key购买 nike

背景

我正在尝试使用NodeWebKit编写一个应用程序。该应用程序有两个部分。

第一个service ,它将安装在用户计算机上,该服务将在启动时运行并监视目录的更改。

第二个是 GUI 客户端,这将是指定要监视哪些目录的客户端。

所以我认为 GUI 客户端将保存指定要监视的目录列表的文件,并且服务将查看该文件以了解他要监视哪些目录。

这个想法是,当用户安装客户端 GUI 应用程序时,它也会安装该服务并运行该服务。

问题

我还需要支持跨平台。

  • 我如何知道在 OSX 和 Windows 中将设置文件保存在哪里?
  • 我应该重构架构吗?

最佳答案

关于您的架构:当然,这应该可以工作,尽管它在 Windows 上可能不如您希望的那么高效。 (Windows 不能很好地处理文件更改事件,但话又说回来,它在什么方面做得很好?;)

就应用程序配置文件而言:

为什么不将应用配置保存到用户的数据目录中?

来自node-webkit API docs描述nw.gui App对象:

nw.gui.App.dataPath

Get the application's data path in user's directory.

  • Windows: %LOCALAPPDATA%/<name>
  • Linux: ~/.config/<name>
  • OSX: ~/Library/Application Support/<name>

where <name> is the field in the manifest.

(注意:这意味着应用程序的 name 文件中的 package.json 字段。因此,如果您的应用程序名为“Foo”并且您在 Windows 7 下运行且用户名为“User”,则 nw.gui.App.dataPath将返回“C:\Users\User\AppData\Local\Foo”)

我建议您将所有应用配置数据保存为 JSON,以便于加载和访问。

来自node.js docs require的描述功能:

File Modules#

If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js, .json, and then .node.

.js files are interpreted as JavaScript text files, and .json files are parsed as JSON text files. .node files are interpreted as compiled addon modules loaded with dlopen.

(注意:为了清晰起见,添加了强调。)

瞧!这很简单!

关于javascript - 桌面应用程序上的共享设置位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24883281/

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