Skip to content

Commit

Permalink
Version 1.0.3 (#102)
Browse files Browse the repository at this point in the history
* Bump webpack from 5.74.0 to 5.76.0 (#94)

Bumps [webpack](https://github.com/webpack/webpack) from 5.74.0 to 5.76.0.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.74.0...v5.76.0)

---
updated-dependencies:
- dependency-name: webpack
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Write downloaded files directly to disk (#95)

* Write downloaded files directly to disk

Avoids storing temporarily in memory, resolving issues with
big-ish files.

* Fix abort and http error handling during sync

* Remove flags to increase V8's default max heap size

Not needed anymore, we shouldn't be using big amounts
of memory now that we write files directly to disk.

* Bump electron from 21.1.1 to 22.3.21 (#99)

Bumps [electron](https://github.com/electron/electron) from 21.1.1 to 22.3.21.
- [Release notes](https://github.com/electron/electron/releases)
- [Changelog](https://github.com/electron/electron/blob/main/docs/breaking-changes.md)
- [Commits](electron/electron@v21.1.1...v22.3.21)

---
updated-dependencies:
- dependency-name: electron
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump word-wrap from 1.2.3 to 1.2.4 (#98)

Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](jonschlinkert/word-wrap@1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump semver from 5.7.1 to 5.7.2 (#97)

Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md)
- [Commits](npm/node-semver@v5.7.1...v5.7.2)

---
updated-dependencies:
- dependency-name: semver
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Only set login element when it's changed (#101)

* bump version to 1.0.3

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ferlo <[email protected]>
  • Loading branch information
3 people committed Sep 13, 2023
1 parent 4f52f09 commit 94d56ce
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 236 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webeep-sync",
"productName": "WeBeep Sync",
"version": "1.0.2",
"version": "1.0.3",
"description": "keep your webeep files synced",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,7 +43,7 @@
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.1",
"dotenv": "^16.0.3",
"electron": "^21.1.1",
"electron": "^22.3.21",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.20.0",
Expand All @@ -56,7 +56,7 @@
"svg-inline-loader": "^0.8.2",
"ts-loader": "^9.4.1",
"typescript": "^4.8.4",
"webpack": "^5.74.0"
"webpack": "^5.76.0"
},
"dependencies": {
"dompurify": "^2.4.0",
Expand All @@ -73,4 +73,4 @@
"sass": "^1.55.0",
"sass-loader": "^13.1.0"
}
}
}
22 changes: 13 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ const { debug, log, error } = createLogger("APP")

const DEV = process.argv.includes("--dev")

// Increase the max heap size
app.commandLine.appendSwitch("js-flags", "--max-old-space-size=4096")

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require("electron-squirrel-startup")) {
// eslint-disable-line global-require
Expand Down Expand Up @@ -75,12 +72,19 @@ async function setLoginItem(openAtLogin: boolean) {
if (process.platform === "linux") return

await app.whenReady()
debug(`Setting openAtLogin to ${openAtLogin}`)
app.setLoginItemSettings({
openAtLogin,
openAsHidden: true,
...windowsLoginSettings,
})

const loginItemSettings = app.getLoginItemSettings(windowsLoginSettings)
// only set the login item if it's different from the current one
if (openAtLogin !== loginItemSettings.openAtLogin) {
debug(`Setting openAtLogin to ${openAtLogin}`)
app.setLoginItemSettings({
openAtLogin,
openAsHidden: true,
...windowsLoginSettings,
})
} else {
debug(`openAtLogin is already ${openAtLogin}`)
}
}

loginManager.on("token", async () => {
Expand Down
30 changes: 22 additions & 8 deletions src/modules/download.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from "path"
import fs from "fs/promises"
import { createWriteStream } from "fs"
import stream from "stream/promises"
import { EventEmitter } from "events"
import got, { CancelableRequest, Response } from "got"
import got from "got"

import { createLogger } from "./logger"
import { FileInfo, moodleClient } from "./moodle"
Expand Down Expand Up @@ -57,7 +59,7 @@ export class DownloadManager extends EventEmitter {
private totalUntilNow = 0 // size of all completed downloads

currentDownloads: {
request: CancelableRequest<Response<string>>
cancel: () => void
progress: FileProgress
}[] = []

Expand Down Expand Up @@ -92,7 +94,7 @@ export class DownloadManager extends EventEmitter {
}

private cancelAllRequests() {
for (const download of this.currentDownloads) download.request.cancel()
for (const download of this.currentDownloads) download.cancel()
}

/**
Expand Down Expand Up @@ -167,7 +169,8 @@ export class DownloadManager extends EventEmitter {
const absolutePath = path.join(downloadPath, fullpath)

// make the request to get the file
const request = got.get(file.fileurl, {
const reqAc = new AbortController()
const request = got.stream(file.fileurl, {
searchParams: {
token: loginManager.token, // for some god forsaken reason it's token and not wstoken
},
Expand All @@ -176,7 +179,7 @@ export class DownloadManager extends EventEmitter {
// prepare the download object, this is what will be pushed in the current downloads
// to keep track of the progress
const download: (typeof this.currentDownloads)[number] = {
request,
cancel: () => reqAc.abort(),
progress: {
absolutePath,
filename: file.filename,
Expand All @@ -191,17 +194,27 @@ export class DownloadManager extends EventEmitter {
download.progress.downloaded = transferred
})

const res = await request

try {
await fs.mkdir(path.dirname(absolutePath), { recursive: true })
await fs.writeFile(absolutePath, res.rawBody)
await stream.pipeline(request, createWriteStream(absolutePath), {
signal: reqAc.signal,
})
await fs.utimes(
absolutePath,
new Date(),
new Date(file.timemodified * 1000)
)
} catch (e) {
switch (e.name) {
case "AbortError":
debug(`Cancelled request for file ${fullpath}`)
throw e
case "RequestError":
case "HTTPError":
case "TimeoutError":
throw e
}

if (e.code === "EISDIR") {
try {
await fs.rm(e.path, { recursive: true, force: true })
Expand Down Expand Up @@ -272,6 +285,7 @@ export class DownloadManager extends EventEmitter {
this.cancelAllRequests()
switch (e.name) {
case "CancelError":
case "AbortError":
return SyncResult.stopped

case "RequestError":
Expand Down
Loading

0 comments on commit 94d56ce

Please sign in to comment.