fix tab opening/closing/titles

This commit is contained in:
dragonwocky 2020-10-15 22:34:51 +11:00
parent b23b928289
commit 796fac9466
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D

View File

@ -213,7 +213,7 @@ module.exports = (store, __exports) => {
} }
openTab(id, state = new Map(this.state.tabs), load) { openTab(id, state = new Map(this.state.tabs), load) {
if (!id && id !== 0) { if (!id && id !== 0) {
if (this.views.current.$el().style.display === 'flex') return; if (state.get(this.views.current.id)[1]) return;
id = [...state].find(([id, [title, open]]) => open)[0]; id = [...state].find(([id, [title, open]]) => open)[0];
} }
const current_src = this.views.current.$el().src; const current_src = this.views.current.$el().src;
@ -258,13 +258,16 @@ module.exports = (store, __exports) => {
} }
closeTab(id) { closeTab(id) {
if ((!id && id !== 0) || !this.state.tabs.get(id)) return; if ((!id && id !== 0) || !this.state.tabs.get(id)) return;
console.log(id);
const list = new Map(this.state.tabs); const list = new Map(this.state.tabs);
list.set(id, [list.get(id)[0], false]); list.set(id, [list.get(id)[0], false]);
console.log(list);
if (![...list].filter(([id, [title, open]]) => open).length) if (![...list].filter(([id, [title, open]]) => open).length)
return electron.remote.getCurrentWindow().close(); return electron.remote.getCurrentWindow().close();
this.openTab(null, list); this.openTab(
this.views.current.id === id
? null
: [...list].find(([id, [title, open]]) => open)[0],
list
);
} }
focusTab() { focusTab() {
if (this.views.active === this.views.current.id) return; if (this.views.active === this.views.current.id) return;
@ -316,15 +319,16 @@ module.exports = (store, __exports) => {
document.body.style.setProperty(style[0], style[1]); document.body.style.setProperty(style[0], style[1]);
break; break;
case 'enhancer:set-tab-title': case 'enhancer:set-tab-title':
if (this.state.tabs.get(event.target.id)) { if (this.state.tabs.get(+event.target.id)) {
const list = new Map(this.state.tabs);
list.set(event.target.id, [
event.args[0],
this.state.tabs.get(event.target.id)[1],
]);
this.setState({ this.setState({
tabs: list, tabs: new Map(
this.state.tabs.set(+event.target.id, [
event.args[0],
this.state.tabs.get(+event.target.id)[1],
])
),
}); });
// this.forceUpdate();
const electronWindow = electron.remote.getCurrentWindow(); const electronWindow = electron.remote.getCurrentWindow();
if ( if (
event.target.id == this.views.current.id && event.target.id == this.views.current.id &&
@ -587,7 +591,6 @@ module.exports = (store, __exports) => {
} }
renderTitlebar() { renderTitlebar() {
console.log('title');
return React.createElement( return React.createElement(
'header', 'header',
{ {