forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move file to jan root (janhq#598)
* feat: move necessary files to jan root Signed-off-by: James <[email protected]> * chore: check model dir --------- Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: Louis <[email protected]>
- Loading branch information
1 parent
9c5c03b
commit 52d56a8
Showing
54 changed files
with
608 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"quoteProps": "consistent", | ||
"trailingComma": "es5", | ||
"endOfLine": "auto", | ||
"plugins": ["prettier-plugin-tailwindcss"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,108 @@ | ||
import { app, ipcMain } from "electron"; | ||
import { DownloadManager } from "../managers/download"; | ||
import { resolve, join } from "path"; | ||
import { WindowManager } from "../managers/window"; | ||
import request from "request"; | ||
import { createWriteStream, unlink } from "fs"; | ||
const progress = require("request-progress"); | ||
import { app, ipcMain } from 'electron' | ||
import { DownloadManager } from '../managers/download' | ||
import { resolve, join } from 'path' | ||
import { WindowManager } from '../managers/window' | ||
import request from 'request' | ||
import { createWriteStream, unlink } from 'fs' | ||
const progress = require('request-progress') | ||
|
||
export function handleDownloaderIPCs() { | ||
/** | ||
* Handles the "pauseDownload" IPC message by pausing the download associated with the provided fileName. | ||
* @param _event - The IPC event object. | ||
* @param fileName - The name of the file being downloaded. | ||
*/ | ||
ipcMain.handle("pauseDownload", async (_event, fileName) => { | ||
DownloadManager.instance.networkRequests[fileName]?.pause(); | ||
}); | ||
ipcMain.handle('pauseDownload', async (_event, fileName) => { | ||
DownloadManager.instance.networkRequests[fileName]?.pause() | ||
}) | ||
|
||
/** | ||
* Handles the "resumeDownload" IPC message by resuming the download associated with the provided fileName. | ||
* @param _event - The IPC event object. | ||
* @param fileName - The name of the file being downloaded. | ||
*/ | ||
ipcMain.handle("resumeDownload", async (_event, fileName) => { | ||
DownloadManager.instance.networkRequests[fileName]?.resume(); | ||
}); | ||
ipcMain.handle('resumeDownload', async (_event, fileName) => { | ||
DownloadManager.instance.networkRequests[fileName]?.resume() | ||
}) | ||
|
||
/** | ||
* Handles the "abortDownload" IPC message by aborting the download associated with the provided fileName. | ||
* The network request associated with the fileName is then removed from the networkRequests object. | ||
* @param _event - The IPC event object. | ||
* @param fileName - The name of the file being downloaded. | ||
*/ | ||
ipcMain.handle("abortDownload", async (_event, fileName) => { | ||
const rq = DownloadManager.instance.networkRequests[fileName]; | ||
DownloadManager.instance.networkRequests[fileName] = undefined; | ||
const userDataPath = app.getPath("userData"); | ||
const fullPath = join(userDataPath, fileName); | ||
rq?.abort(); | ||
let result = "NULL"; | ||
ipcMain.handle('abortDownload', async (_event, fileName) => { | ||
const rq = DownloadManager.instance.networkRequests[fileName] | ||
DownloadManager.instance.networkRequests[fileName] = undefined | ||
const userDataPath = app.getPath('userData') | ||
const fullPath = join(userDataPath, fileName) | ||
rq?.abort() | ||
let result = 'NULL' | ||
unlink(fullPath, function (err) { | ||
if (err && err.code == "ENOENT") { | ||
result = `File not exist: ${err}`; | ||
if (err && err.code == 'ENOENT') { | ||
result = `File not exist: ${err}` | ||
} else if (err) { | ||
result = `File delete error: ${err}`; | ||
result = `File delete error: ${err}` | ||
} else { | ||
result = "File deleted successfully"; | ||
result = 'File deleted successfully' | ||
} | ||
console.log(`Delete file ${fileName} from ${fullPath} result: ${result}`); | ||
}); | ||
}); | ||
console.debug( | ||
`Delete file ${fileName} from ${fullPath} result: ${result}` | ||
) | ||
}) | ||
}) | ||
|
||
/** | ||
* Downloads a file from a given URL. | ||
* @param _event - The IPC event object. | ||
* @param url - The URL to download the file from. | ||
* @param fileName - The name to give the downloaded file. | ||
*/ | ||
ipcMain.handle("downloadFile", async (_event, url, fileName) => { | ||
const userDataPath = app.getPath("userData"); | ||
const destination = resolve(userDataPath, fileName); | ||
const rq = request(url); | ||
ipcMain.handle('downloadFile', async (_event, url, fileName) => { | ||
const userDataPath = join(app.getPath('home'), 'jan') | ||
const destination = resolve(userDataPath, fileName) | ||
const rq = request(url) | ||
|
||
progress(rq, {}) | ||
.on("progress", function (state: any) { | ||
.on('progress', function (state: any) { | ||
WindowManager?.instance.currentWindow?.webContents.send( | ||
"FILE_DOWNLOAD_UPDATE", | ||
'FILE_DOWNLOAD_UPDATE', | ||
{ | ||
...state, | ||
fileName, | ||
} | ||
); | ||
) | ||
}) | ||
.on("error", function (err: Error) { | ||
.on('error', function (err: Error) { | ||
WindowManager?.instance.currentWindow?.webContents.send( | ||
"FILE_DOWNLOAD_ERROR", | ||
'FILE_DOWNLOAD_ERROR', | ||
{ | ||
fileName, | ||
err, | ||
} | ||
); | ||
) | ||
}) | ||
.on("end", function () { | ||
.on('end', function () { | ||
if (DownloadManager.instance.networkRequests[fileName]) { | ||
WindowManager?.instance.currentWindow?.webContents.send( | ||
"FILE_DOWNLOAD_COMPLETE", | ||
'FILE_DOWNLOAD_COMPLETE', | ||
{ | ||
fileName, | ||
} | ||
); | ||
DownloadManager.instance.setRequest(fileName, undefined); | ||
) | ||
DownloadManager.instance.setRequest(fileName, undefined) | ||
} else { | ||
WindowManager?.instance.currentWindow?.webContents.send( | ||
"FILE_DOWNLOAD_ERROR", | ||
'FILE_DOWNLOAD_ERROR', | ||
{ | ||
fileName, | ||
err: "Download cancelled", | ||
err: 'Download cancelled', | ||
} | ||
); | ||
) | ||
} | ||
}) | ||
.pipe(createWriteStream(destination)); | ||
.pipe(createWriteStream(destination)) | ||
|
||
DownloadManager.instance.setRequest(fileName, rq); | ||
}); | ||
DownloadManager.instance.setRequest(fileName, rq) | ||
}) | ||
} |
Oops, something went wrong.