Skip to content

Commit

Permalink
fix: dashboard icon inject and refactor some init code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzombiee2361 committed Sep 3, 2023
1 parent fe11ca3 commit f9729f5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/Renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const Settings = require('./Settings');
const Instance = require('./Instance');
const AppLock = require('./AppLock');
const { whatsappReady } = require('./whatsapp-inject');
const Deferred = require('./Deferred');

class App {
constructor() {
console.log('Initializing WALC');
this.initialized = false;
this.awaitApp();
ipcRenderer.on('renderTray', () => this.renderTray());
ipcRenderer.on('ready', () => this.init());
ipcRenderer.on('setFullWidth', (e, status) => this.setFullWidth(status));

window.WALC = {
Expand All @@ -19,12 +19,12 @@ class App {
};
}

awaitApp() {
async awaitApp() {
const pageReady = new Deferred();
const observer = new MutationObserver(() => {
const sidebar = document.querySelector('#app [data-testid=chatlist-header]');
if(sidebar) {
setTimeout(() => this.init(), 1000);
observer.disconnect();
const isReady = document.querySelector('#app [data-icon=\'chat\']');
if(isReady) {
setTimeout(() => pageReady.resolve(), 2000);
}
});

Expand All @@ -34,6 +34,15 @@ class App {
subtree: true,
});
}, 2000);

await Promise.race([
pageReady.promise,
new Promise((resolve) => {
ipcRenderer.once('ready', () => resolve());
}),
]);
this.init();
observer.disconnect();
}

async init() {
Expand Down
3 changes: 3 additions & 0 deletions src/Renderer/AppLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class AppLock {
}

async _initWhatsapp() {
if (!window.Store) {
return;
}
const user = window.Store.User.getMeUser() || {};
const myContact = await window.Store.Contact.find(user._serialized);
this.overlay.querySelector('.app-lock-user h1').textContent = myContact.displayName;
Expand Down
8 changes: 8 additions & 0 deletions src/Renderer/Deferred.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = class Deferred {
constructor() {
this.promise = new Promise((resolve, reject)=> {
this.reject = reject
this.resolve = resolve
})
}
}
3 changes: 2 additions & 1 deletion src/Renderer/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class Instance {
}

installDashboardIcon(icon) {
const container = document.querySelector('[data-testid=chatlist-header] div:first-child');
const profilePhoto = document.querySelector('[aria-label="profile photo"]');
const container = profilePhoto.parentElement;
this.image = document.createElement('div');
container.style.display = 'flex';
container.style.alignItems = 'center';
Expand Down

0 comments on commit f9729f5

Please sign in to comment.