Skip to content

Commit

Permalink
updater and fix splash themes
Browse files Browse the repository at this point in the history
  • Loading branch information
doggybootsy committed Jun 22, 2022
1 parent 863b321 commit 485ffae
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drdiscord",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"asar": "^3.1.0",
"electron-devtools-installer": "^3.2.0",
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
20 changes: 19 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void function() {
}()

window.DrApi = {
request: (url, callback) => fetch(url).then(async request => callback(await request.text(), request)),
request: (url, callback) => fetch(url).then(request => callback(request)),
webpack,
Patcher,
storage: {
Expand All @@ -56,6 +56,24 @@ void async function() {
function onOpen() {
logger.log("Plugins", "Initializing all plugins")
plugins()

logger.log("Updater", "Checking for new update")
const package = DrApiNative.require(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "package.json"))
DrApi.request("https://api.github.com/repos/Dr-Discord/dev/releases", async request => {
const json = (await request.json()).shift()
if (package.version > json.tag_name) return
DrApi.modals.confirmModal("You version is out of date!", [
"Do you want to update Discord Re-envisioned",
"This will restart discord too"
], {
confirmText: "Update",
onConfirm: () => {
const hash = json.assets.find(a => a.name.endsWith(".asar")).url.split("/").pop()
DrApiNative.downloadAsar(hash, (err) => err ? null : DrApiNative.quit(true))
}
})
})

dispatcher.unsubscribe("CONNECTION_OPEN", onOpen)
}
dispatcher.subscribe("CONNECTION_OPEN", onOpen)
Expand Down
2 changes: 2 additions & 0 deletions src/main/modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ module.exports = async (React) => {
}))
}
}

logger.log("Releases", "Checking github for a new release")
}
11 changes: 6 additions & 5 deletions src/main/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ module.exports = async (React) => {
id: `open-${filter ? "theme" : "plugin"}-folder`,
label: `Open ${filter ? "Theme" : "Plugin"} Folder`,
icon: () => React.createElement(Folder, { className: iconMenu }),
action: () => () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "themes"))
action: () => () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "..", filter ? "theme" : "plugin"))
})
]
})
Expand Down Expand Up @@ -645,7 +645,7 @@ module.exports = async (React) => {
children: [
React.createElement(Icon, {
icon: () => React.createElement(Folder, { className: iconToolbar }),
onClick: () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "themes")),
onClick: () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "..", "themes")),
tooltip: "Open Theme Folder"
}),
React.createElement(SearchBar, {
Expand Down Expand Up @@ -786,7 +786,7 @@ module.exports = async (React) => {
children: [
React.createElement(Icon, {
icon: () => React.createElement(Folder, { className: iconToolbar }),
onClick: () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "plugins")),
onClick: () => shell.openPath(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "..", "plugins")),
tooltip: "Open Plugin Folder"
}),
React.createElement(SearchBar, {
Expand Down Expand Up @@ -903,6 +903,7 @@ module.exports = async (React) => {
sections.splice(index, 0, ...settings)
})

const package = DrApiNative.require(DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "package.json"))
patcher.after("DrApi", webpack.getModuleByDisplayName("ClientDebugInfo"), "default", (that, args, res) => {
res.props.children.push(React.createElement(Text, {
className: line,
Expand All @@ -914,8 +915,8 @@ module.exports = async (React) => {
" (",
React.createElement("span", {
onClick: () => {},
children: "ALPHA",
style: { color: "var(--status-danger)", cursor: "pointer" }
children: package.version,
style: { cursor: "pointer" }
}),
")"
]
Expand Down
17 changes: 17 additions & 0 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const electron = require("electron")
const { ipcRenderer, contextBridge } = electron
const fs = require("fs")
const path = require("path")
const ofs = require("original-fs")

require("module").globalPaths.push(path.join(process.resourcesPath, "app.asar/node_modules"))

// Replace electron renderer so we can mess with 'DiscordNative'
delete require.cache.electron.exports
Expand Down Expand Up @@ -42,6 +45,20 @@ const Native = {
runInNative(code) { return eval(code) },
quit(restart = false) { ipcRenderer.send("@DrApi/quit", restart) },
platform: process.platform,
downloadAsar(id, callback) {
require("request")(`https://api.github.com/repos/Dr-Discord/dev/releases/assets/${id}`, {
encoding: null,
headers: {
"User-Agent": "Updater",
"Accept": "application/octet-stream"
}
}, (err, resp, body) => {
if (err || resp.statusCode != 200) return callback(true)
ofs.unlinkSync(__dirname)
ofs.writeFileSync(__dirname, body)
callback(false)
})
},
fileSystem: {
dirName: __dirname,
join: (...paths) => path.join(...paths),
Expand Down
2 changes: 1 addition & 1 deletion src/splash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const storage = require("../storage")

const enabledThemes = storage.getData("internal", "enabledSplashThemes", [])

const themesFolder = DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "themes")
const themesFolder = DrApiNative.fileSystem.join(DrApiNative.fileSystem.dirName, "..", "themes")

if (!DrApiNative.fileSystem.exists(themesFolder)) DrApiNative.fileSystem.mkdir(themesFolder)

Expand Down

0 comments on commit 485ffae

Please sign in to comment.