-
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.
improve bundling and asset resolution
- Loading branch information
Showing
7 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
import { app, protocol } from "electron"; | ||
import * as path from "path"; | ||
import * as fs from "fs"; | ||
import * as mime from "mime-types"; | ||
|
||
export function registerFileProtocol() { | ||
async function respondWithFile(filePath: string) { | ||
const fileContent = await fs.promises.readFile(filePath); | ||
const contentType = mime.lookup(filePath) || "application/octet-stream"; | ||
|
||
return new Response(fileContent, { | ||
status: 200, | ||
headers: { "Content-Type": contentType } | ||
}); | ||
} | ||
|
||
async function handleFileRequest(fileUrl: string): Promise<Response> { | ||
const concantatedFilePath = path.join(app.getAppPath(), ".webpack", "renderer", fileUrl); | ||
|
||
if (!fs.existsSync(concantatedFilePath)) { | ||
return respondWithFile(fileUrl); | ||
} | ||
|
||
try { | ||
return respondWithFile(concantatedFilePath); | ||
} catch (error) { | ||
console.error(`Error reading file: ${error.message}`); | ||
return new Response(JSON.stringify({ error: "Internal server error" }), { | ||
status: 500, | ||
headers: { "Content-Type": "application/json" } | ||
}); | ||
} | ||
} | ||
|
||
protocol.handle("file", async (request) => { | ||
const fileUrl = request.url.substring(7); // Remove the "file://" prefix | ||
if (fileUrl.startsWith("/")) { | ||
return handleFileRequest(fileUrl); | ||
} | ||
return respondWithFile(fileUrl); | ||
}); | ||
} |
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