我们的一些用户似乎从dmg文件中运行该应用程序,并且从未将其移动到他们的/Applications
文件夹中:
这或许可以解释为什么我们在内部日志中看到这个消息:
Cannot update while running on a read-only volume. The application is on a read-only volume. Please move the application and try again. If you're on macOS Sierra or later, you'll need to move the application out of the Downloads directory. See https://github.com/Squirrel/Squirrel.Mac/issues/182 for more information.
(我访问了GitHub问题,但没有发现任何有用的东西。)
我肯定可以通过将dmg、cd挂载到其中并从命令行运行应用程序来再现此错误消息:
# I mounted the dmg and then cd into it, see:
$ pwd
/Volumes/**REDACTED**2.42.0-beta.5
# Then I launched the app from the command line, see:
$ ./**REDACTED**.app/Contents/MacOS/**REDACTED**
Found version 2.42.1-beta.0 (url: **REDACTED**-2.42.1-beta.0.zip, **REDACTED**-2.42.1-beta.0.dmg, **REDACTED**-2.42.1-beta.0.dmg)
Downloading update from **REDACTED**-2.42.1-beta.0.zip, **REDACTED**-2.42.1-beta.0.dmg, **REDACTED**-2.42.1-beta.0.dmg
updater cache dir: /Users/**REDACTED**/Library/Application Support/Caches/**REDACTED**-updater
Update has already been downloaded to /Users/**REDACTED**/Library/Application Support/Caches/**REDACTED**-updater/pending/**REDACTED**-2.42.1-beta.0.zip).
/ requested
[Error: Cannot update while running on a read-only volume. The application is on a read-only volume. Please move the application and try again. If you're on macOS Sierra or later, you'll need to move the application out of the Downloads directory. See https://github.com/Squirrel/Squirrel.Mac/issues/182 for more information.] {
code: 8,
domain: 'SQRLUpdaterErrorDomain'
}
当应用程序运行时,后台进程会检查更新情况。我们可以看到它找到了一个并下载了它。但是它不能应用它。
我们定期发布更新,但这些用户无法获得它们。我怀疑他们中的一些人甚至没有意识到他们没有“正确”安装这个应用程序。
,我们有办法用电子或Node.js?来检测吗?
发布于 2022-03-17 19:09:03
这个答案来自我的电子食谱库:
https://customcommander.github.io/electron-survival-guide/
TL;DR
您可以使用app.isInApplicationsFolder()
方法。
主要过程
渲染程序进程可以通过询问Applications
IPC通道来询问应用程序是否从in-app-folder
文件夹中运行。主要进程将在同一渠道作出反应。
const {app, BrowserWindow, ipcMain} = require('electron');
const path = require('path');
app.whenReady().then(async () => {
const bwin = new BrowserWindow({
width: 300,
height: 300,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.resolve(__dirname, 'preload.js')
}
});
// Must be registered **before** the renderer process starts.
ipcMain.handle('in-app-folder', () => app.isInApplicationsFolder());
await bwin.loadFile('renderer.html');
bwin.show();
});
预加载脚本
预加载脚本在MY_APP
命名空间下公开一个方法,呈现程序进程可以使用该方法来知道应用程序是否从Applications
文件夹运行。
const {contextBridge, ipcRenderer} = require('electron');
contextBridge.exposeInMainWorld('MY_APP', {
async isInApplicationsFolder() {
return ipcRenderer.invoke('in-app-folder');
}
});
渲染器
MY_APP
命名空间在预加载脚本中定义,并包含一个查询应用程序位置的方法。
<html>
<head>
<style>
body {background-color:black;color:limegreen}
</style>
</head>
<body>
<h1>Are you running this app from the Applications folder?</h1>
<div id="response"></div>
<script>
MY_APP.isInApplicationsFolder().then(yes => {
if (yes) {
document.querySelector('#response').innerHTML = 'Yes';
} else {
document.querySelector('#response').innerHTML = 'No';
}
});
</script>
</body>
</html>
https://stackoverflow.com/questions/65346127
复制相似问题