Prompt user to move to applications folder on first run

This commit is contained in:
Will Chen
2025-04-21 16:27:07 -07:00
parent d8b52a5d5f
commit 09b3bf3fee
3 changed files with 38 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { app, BrowserWindow } from "electron";
import { app, BrowserWindow, dialog } from "electron";
import * as path from "node:path";
import { registerIpcHandlers } from "./ipc/ipc_host";
import dotenv from "dotenv";
@@ -6,6 +6,7 @@ import dotenv from "dotenv";
import started from "electron-squirrel-startup";
import { updateElectronApp } from "update-electron-app";
import log from "electron-log";
import { readSettings, writeSettings } from "./main/settings";
log.errorHandler.startCatching();
log.eventLogger.startLogging();
@@ -24,6 +25,40 @@ if (started) {
app.quit();
}
/**
* Is this the first run of Fiddle? If so, perform
* tasks that we only want to do in this case.
*/
export async function onFirstRunMaybe() {
const settings = readSettings();
if (!settings.hasRunBefore) {
await promptMoveToApplicationsFolder();
writeSettings({
hasRunBefore: true,
});
}
}
/**
* Ask the user if the app should be moved to the
* applications folder.
*/
async function promptMoveToApplicationsFolder(): Promise<void> {
if (process.platform !== "darwin") return;
if (app.isInApplicationsFolder()) return;
const { response } = await dialog.showMessageBox({
type: "question",
buttons: ["Move to Applications Folder", "Do Not Move"],
defaultId: 0,
message: "Move to Applications Folder? (required for auto-update)",
});
if (response === 0) {
app.moveToApplicationsFolder();
}
}
declare global {
const MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
}