Skip to content
This repository was archived by the owner on Jul 14, 2023. It is now read-only.

Commit c9d37fd

Browse files
authored
Merge pull request #121 from education/moveToApplicationsFolder
Move to Applications folder for Updater
2 parents ad5f513 + 4e5654f commit c9d37fd

4 files changed

Lines changed: 72 additions & 27 deletions

File tree

app/main-process/letsMove.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

app/main-process/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const updater = require("./updater")
1313
const {initLogger} = require("./logger")
1414
const {authorizeUser, setAccessTokenFromCode, loadAccessToken, deleteAccessToken} = require("./userAuthentication")
1515
const {generateMenu} = require("./menu")
16+
const {moveToApplicationsFolder} = require("./letsMove")
1617

1718
let mainWindow
1819
let loadOnReady = null
@@ -138,6 +139,7 @@ app.on("ready", async () => {
138139

139140
if (anotherInstanceRunning) app.quit()
140141

142+
moveToApplicationsFolder()
141143
loadAccessToken()
142144
createWindow()
143145
})

package-lock.json

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "classroom-assistant",
33
"productName": "Classroom Assistant",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "Desktop helper for GitHub Classroom",
66
"main": "app/main-process/main.js",
77
"scripts": {

0 commit comments

Comments
 (0)