Skip to content

Commit

Permalink
fix: improve favicons saving system
Browse files Browse the repository at this point in the history
  • Loading branch information
sentialx committed Oct 2, 2019
1 parent c738ddf commit df8f5d2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"gsap": "^3.0.0-beta.7",
"hard-source-webpack-plugin": "^0.13.1",
"html-webpack-plugin": "^3.2.0",
"icojs": "0.13.1",
"icojs": "^0.13.1",
"keytar": "^5.0.0-beta.0",
"mkdirp": "^0.5.1",
"mobx": "5.13.1",
Expand Down
2 changes: 0 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export const windowsManager = new WindowsManager();
// app.setAsDefaultProtocolClient('http');
// app.setAsDefaultProtocolClient('https');

console.time('Main start');

process.on('uncaughtException', error => {
console.error(error);
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/sessions-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class SessionsManager {
context.loadExtension(resolve(extensionsPath, dir));
}

// context.loadExtension(resolve(__dirname, 'extensions/wexond-darkreader'));
context.loadExtension(resolve(__dirname, 'extensions/wexond-darkreader'));

if (session === 'incognito') {
this.incognitoExtensionsLoaded = true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ export class View extends BrowserView {
async (e, favicons) => {
this.favicon = favicons[0];

this.window.webContents.send(
`update-tab-favicon-${this.webContents.id}`,
this.favicon,
);

try {
let fav = this.favicon;

Expand All @@ -150,11 +155,6 @@ export class View extends BrowserView {
this.favicon = '';
console.error(e);
}

this.window.webContents.send(
`update-tab-favicon-${this.webContents.id}`,
this.favicon,
);
},
);

Expand Down
26 changes: 4 additions & 22 deletions src/main/windows-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,8 @@ import { IFavicon } from '~/interfaces';
import fileType = require('file-type');
import icojs = require('icojs');

const convertIcoToPng = (icoData: Buffer) => {
return new Promise((resolve: (b: Buffer) => void) => {
icojs.parse(icoData, 'image/png').then((images: any) => {
resolve(images[0].buffer);
});
});
};

const readImage = (buffer: Buffer) => {
return new Promise((resolve: (b: Buffer) => void) => {
const reader = new FileReader();

reader.onload = () => {
resolve(Buffer.from(reader.result as any));
};

reader.readAsArrayBuffer(new Blob([buffer]));
});
const convertIcoToPng = async (icoData: Buffer): Promise<ArrayBuffer> => {
return (await icojs.parse(icoData, 'image/png'))[0].buffer;
};

export class WindowsManager {
Expand Down Expand Up @@ -122,8 +106,6 @@ export class WindowsManager {

this.createWindow();

console.timeEnd('Main start');

runAutoUpdaterService(this);

Menu.setApplicationMenu(getMainMenu(this));
Expand Down Expand Up @@ -170,10 +152,10 @@ export class WindowsManager {
const type = fileType(data);

if (type && type.ext === 'ico') {
data = await readImage(await convertIcoToPng(data));
data = Buffer.from(new Uint8Array(await convertIcoToPng(data)));
}

const str = `data:png;base64,${data.toString('base64')}`;
const str = `data:${type.ext};base64,${data.toString('base64')}`;

storage.insert({
scope: 'favicons',
Expand Down
4 changes: 4 additions & 0 deletions src/main/windows/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export class AppWindow extends BrowserWindow {
this.viewManager.fixBounds();
});

setTimeout(() => {
this.webContents.send('tabs-resize');
}, 500);

this.webContents.send('tabs-resize');
};

Expand Down

0 comments on commit df8f5d2

Please sign in to comment.