mirror of
https://github.com/felixrieseberg/macintosh.js.git
synced 2025-02-06 18:30:13 +00:00
fix: Ensure we run from the applications folder
This commit is contained in:
parent
3698e7387b
commit
3b23ad828d
46
src/main/appfolder.js
Normal file
46
src/main/appfolder.js
Normal file
@ -0,0 +1,46 @@
|
||||
const { app, dialog } = require("electron");
|
||||
|
||||
// If the app doesn't run from the /Applications folder,
|
||||
// we don't get to create files, which keeps the emulator from
|
||||
// running.
|
||||
function moveToAppFolderMaybe() {
|
||||
if (process.platform !== "darwin") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (app.isInApplicationsFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldMove = dialog.showMessageBoxSync({
|
||||
type: "question",
|
||||
buttons: ["Move to Applications Folder", "Quit"],
|
||||
defaultId: 0,
|
||||
message:
|
||||
"macintosh.js can only run from the Applications folder. Do you want to move the app there now?",
|
||||
cancelId: 1,
|
||||
});
|
||||
|
||||
if (shouldMove === 0) {
|
||||
app.moveToApplicationsFolder({
|
||||
conflictHandler: (conflictType) => {
|
||||
if (conflictType === "exists") {
|
||||
return (
|
||||
dialog.showMessageBoxSync({
|
||||
type: "question",
|
||||
buttons: ["Halt Move", "Continue Move"],
|
||||
defaultId: 0,
|
||||
message: "An app of this name already exists",
|
||||
}) === 1
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
moveToAppFolderMaybe,
|
||||
};
|
@ -5,10 +5,12 @@ const { createWindow } = require("./windows");
|
||||
const { getIsDevMode } = require("./devmode");
|
||||
const { shouldQuit } = require("./squirrel");
|
||||
const { setupUpdates } = require("./update");
|
||||
const { moveToAppFolderMaybe } = require("./appfolder");
|
||||
|
||||
async function onReady() {
|
||||
if (!getIsDevMode()) process.env.NODE_ENV = "production";
|
||||
|
||||
moveToAppFolderMaybe();
|
||||
registerIpcHandlers();
|
||||
createWindow();
|
||||
setupUpdates();
|
||||
|
Loading…
x
Reference in New Issue
Block a user