Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
feat(App): Change recipe theme when changing Franz theme
Browse files Browse the repository at this point in the history
resolves #2
  • Loading branch information
MikeDabrowski committed Nov 3, 2018
1 parent 830abfa commit a240113
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/actions/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ export default {
serviceId: PropTypes.string.isRequired,
},
openDevToolsForActiveService: {},
changeServicesTheme: {},
};
10 changes: 10 additions & 0 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class ServicesStore extends Store {
this.actions.service.toggleAudio.listen(this._toggleAudio.bind(this));
this.actions.service.openDevTools.listen(this._openDevTools.bind(this));
this.actions.service.openDevToolsForActiveService.listen(this._openDevToolsForActiveService.bind(this));
this.actions.service.changeServicesTheme.listen(this._changeServicesTheme.bind(this));
this.registerReactions([
this._focusServiceReaction.bind(this),
Expand Down Expand Up @@ -477,6 +478,15 @@ export default class ServicesStore extends Store {
});
}

@action _changeServicesTheme(newTheme) {
const services = this.all;
services.forEach((service) => {
if (service.webview) {
service.webview.send('change-theme', newTheme);
}
});
}

@action _openDevTools({ serviceId }) {
const service = this.one(serviceId);

Expand Down
1 change: 1 addition & 0 deletions src/stores/UIStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class UIStore extends Store {
document.body.classList.remove(c);
}
});
this.actions.service.changeServicesTheme(themeName);
if (name === 'theme-regular') {
return;
}
Expand Down
23 changes: 23 additions & 0 deletions src/webview/lib/RecipeWebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@ class RecipeWebview {
ipcRenderer.on('poll', () => {
this.loopFunc();
});

ipcRenderer.on('change-theme', (eventEmitter, newTheme) => {
this.changeTheme(newTheme);
});
}

changeTheme = (themeName) => {
const currentClassList = document.body.classList;
if (themeName && !currentClassList.contains(themeName)) {
let name = themeName;
if (!themeName.startsWith('theme-')) {
name = `theme-${themeName}`;
}
[...currentClassList].forEach((c) => {
if (c && c.startsWith('theme-')) {
document.body.classList.remove(c);
}
});
if (name === 'theme-regular') {
return;
}
document.body.classList.add(name);
}
};

loopFunc = () => null;

/**
Expand Down

0 comments on commit a240113

Please sign in to comment.