|
| 1 | +import isDev from "electron-is-dev" |
| 2 | + |
| 3 | +const {app, dialog} = require("electron") |
| 4 | +const log = require("electron-log") |
| 5 | +const Store = require("electron-store") |
| 6 | + |
| 7 | +export const moveToApplicationsFolder = () => { |
| 8 | + if (!app.isInApplicationsFolder() && !isDev && shouldRemindUser()) { |
| 9 | + dialog.showMessageBox({ |
| 10 | + type: "question", |
| 11 | + buttons: ["Move to Applications", "Do Not Move"], |
| 12 | + message: "Move to Applications Folder?", |
| 13 | + detail: "I can move myself to the Applications folder if you'd like. This will ensure that future updates will be installed correctly.", |
| 14 | + checkboxLabel: "Do not ask me again", |
| 15 | + defaultId: 0 |
| 16 | + }, (response, checkboxChecked) => { |
| 17 | + if (response === 0) { |
| 18 | + try { |
| 19 | + if (!app.moveToApplicationsFolder()) { |
| 20 | + throw new Error("Failed to move to Applications Folder.") |
| 21 | + } |
| 22 | + } catch (e) { |
| 23 | + log.warn(`Failed to move application to Applications Folder: ${e}`) |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + if (checkboxChecked) { |
| 28 | + // Don't remind user again |
| 29 | + setReminder(false) |
| 30 | + } |
| 31 | + }) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +const shouldRemindUser = () => { |
| 36 | + const store = new Store() |
| 37 | + return !store.get("classroom-assistant-move-to-app-folder") |
| 38 | +} |
| 39 | + |
| 40 | +const setReminder = (value) => { |
| 41 | + const store = new Store() |
| 42 | + store.set("classroom-assistant-move-to-app-folder", !value) |
| 43 | +} |
0 commit comments