Skip to content

Commit

Permalink
Snapshot from scm.treehouse.uc/fs-v source correlation id:39ea017e-bb…
Browse files Browse the repository at this point in the history
…e2-45b0-921e-75077c84a5e8; job:38861ad3-768f-43e0-9940-2519ce94f66a
  • Loading branch information
unreadablewxy committed May 16, 2020
1 parent cb866fa commit d8dd287
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function createWindow(): void {
}

function onReady(): void {
registerThumbnailProtocol();
createWindow();
}

Expand All @@ -60,6 +61,4 @@ app.on("activate", () => {
// dock icon is clicked and there are no other windows open.
if (mainWindow === null)
createWindow();
});

registerThumbnailProtocol();
});
12 changes: 9 additions & 3 deletions src/main/thumbnail.linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ function handleThumbnailRequest(
request: Request,
callback: RequestCallback,
): void {
const suffixIndex = request.url.indexOf("?", 8);
const size = suffixIndex > 0 && request.url.slice(suffixIndex + 3);
const path = request.url.slice(8 /* len("thumb://") */, suffixIndex);
const prefixLength = 8; // len("thumb://")
let suffixOffset = request.url.indexOf("?", prefixLength);
let size: string | undefined;
if (suffixOffset > 0)
size = request.url.slice(suffixOffset + 3)
else
suffixOffset = request.url.length;

const path = request.url.slice(prefixLength, suffixOffset);
const mimeType = getMimeType(path);
if (!mimeType) return callback("");

Expand Down
14 changes: 10 additions & 4 deletions src/main/thumbnail.win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ function handleThumbnailRequest(request: Request, complete: ResponseCallback): v
return;
}

const suffixIndex = request.url.indexOf("?", 8);
const size = suffixIndex > 0 && request.url.slice(suffixIndex + 3);
const resolution = resolutionMapping[size as ThumbnailResolution] || 256;
const requestPath = request.url.slice(8 /* len("thumb://") */, suffixIndex)
const prefixLength = 8; // len("thumb://")
let suffixOffset = request.url.indexOf("?", prefixLength);
let size: string | undefined;
if (suffixOffset > 0)
size = request.url.slice(suffixOffset + 3)
else
suffixOffset = request.url.length;

const resolution = resolutionMapping[size as ThumbnailResolution] || resolutionMapping.default;
const requestPath = request.url.slice(prefixLength, suffixOffset)
.replace("/", "\\");

getImageForPath(requestPath, {
Expand Down

0 comments on commit d8dd287

Please sign in to comment.