mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-19 11:09:03 +00:00
Merge branch 'dev' of https://github.com/dragonwocky/notion-enhancer into dev
This commit is contained in:
commit
2029a3bc19
@ -230,6 +230,12 @@ module.exports = (store, __exports) => {
|
|||||||
electron.ipcRenderer.sendToHost('enhancer:set-tab-title', title);
|
electron.ipcRenderer.sendToHost('enhancer:set-tab-title', title);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
__electronApi.openInNewWindow = (urlPath) => {
|
||||||
|
electron.ipcRenderer.sendToHost(
|
||||||
|
'enhancer:new-tab',
|
||||||
|
`notion://www.notion.so${urlPath}`
|
||||||
|
);
|
||||||
|
};
|
||||||
} else if (store().frameless && !store().tiling_mode) {
|
} else if (store().frameless && !store().tiling_mode) {
|
||||||
let sidebar_width;
|
let sidebar_width;
|
||||||
function setSidebarWidth(list) {
|
function setSidebarWidth(list) {
|
||||||
|
@ -79,7 +79,6 @@ module.exports = (store, __exports) => {
|
|||||||
});
|
});
|
||||||
electron.app.on('before-quit', () => (intended_quit = true));
|
electron.app.on('before-quit', () => (intended_quit = true));
|
||||||
window.loadURL(__exports.getIndexUrl(relativeUrl));
|
window.loadURL(__exports.getIndexUrl(relativeUrl));
|
||||||
// window.webContents.openDevTools();
|
|
||||||
return window;
|
return window;
|
||||||
};
|
};
|
||||||
return __exports.createWindow;
|
return __exports.createWindow;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
transform: rotate(360deg);
|
transform: rotate(360deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@keyframes tabSlideIn {
|
@keyframes tabSlide {
|
||||||
from {
|
from {
|
||||||
width: 0;
|
width: 0;
|
||||||
}
|
}
|
||||||
@ -137,7 +137,11 @@ body,
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
#tabs .tab.slideIn span:not(.close) {
|
#tabs .tab.slideIn span:not(.close) {
|
||||||
animation: tabSlideIn 100ms ease-in-out;
|
animation: tabSlide 100ms ease-in-out;
|
||||||
|
}
|
||||||
|
#tabs .tab.slideOut {
|
||||||
|
width: 0;
|
||||||
|
animation: tabSlide 100ms ease-in-out reverse;
|
||||||
}
|
}
|
||||||
#tabs .tab .close {
|
#tabs .tab .close {
|
||||||
padding: 0 0.35em 0.1em 0.3em;
|
padding: 0 0.35em 0.1em 0.3em;
|
||||||
|
@ -335,7 +335,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* normalise inline-table size */
|
/* normalise inline-table size */
|
||||||
.notion-page-content .notion-collection_view-block {
|
.notion-page-content .notion-collection_view-block[style*=' width'],
|
||||||
|
.notion-page-content .notion-collection_view-block[style^='width'] {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
.notion-page-content
|
.notion-page-content
|
||||||
|
@ -132,7 +132,6 @@ window['__start'] = async () => {
|
|||||||
if (hotkey[prop] !== event[prop]) triggered = false;
|
if (hotkey[prop] !== event[prop]) triggered = false;
|
||||||
if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w'))
|
if (triggered || ((event.ctrlKey || event.metaKey) && event.key === 'w'))
|
||||||
electron.remote.getCurrentWindow().close();
|
electron.remote.getCurrentWindow().close();
|
||||||
console.log(event.ctrlKey, event.key);
|
|
||||||
// focus search
|
// focus search
|
||||||
const meta =
|
const meta =
|
||||||
!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey;
|
!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey;
|
||||||
|
@ -42,8 +42,9 @@ module.exports = (store, __exports) => {
|
|||||||
searching: false,
|
searching: false,
|
||||||
searchingPeekView: false,
|
searchingPeekView: false,
|
||||||
zoomFactor: 1,
|
zoomFactor: 1,
|
||||||
tabs: new Map([[0, ['notion.so', true]]]),
|
tabs: new Map([[0, { title: 'notion.so', open: true }]]),
|
||||||
slideIn: new Set(),
|
slideIn: new Set(),
|
||||||
|
slideOut: new Set(),
|
||||||
};
|
};
|
||||||
this.$titlebar = null;
|
this.$titlebar = null;
|
||||||
this.$dragging = null;
|
this.$dragging = null;
|
||||||
@ -118,9 +119,11 @@ module.exports = (store, __exports) => {
|
|||||||
} else {
|
} else {
|
||||||
const list = [...this.state.tabs],
|
const list = [...this.state.tabs],
|
||||||
fromIndex = list.findIndex(
|
fromIndex = list.findIndex(
|
||||||
([id, [title, open]]) => id === from[0]
|
([id, { title, open }]) => id === from[0]
|
||||||
),
|
),
|
||||||
toIndex = list.findIndex(([id, [title, open]]) => id === to[0]);
|
toIndex = list.findIndex(
|
||||||
|
([id, { title, open }]) => id === to[0]
|
||||||
|
);
|
||||||
list.splice(
|
list.splice(
|
||||||
toIndex > fromIndex ? toIndex - 1 : toIndex,
|
toIndex > fromIndex ? toIndex - 1 : toIndex,
|
||||||
0,
|
0,
|
||||||
@ -215,32 +218,47 @@ module.exports = (store, __exports) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
newTab() {
|
newTab(url = '') {
|
||||||
let id = 0;
|
let id = 0;
|
||||||
const list = new Map(this.state.tabs);
|
const list = new Map(this.state.tabs);
|
||||||
while (this.state.tabs.get(id) && this.state.tabs.get(id)[1]) id++;
|
while (this.state.tabs.get(id) && this.state.tabs.get(id).open) id++;
|
||||||
list.delete(id);
|
list.delete(id);
|
||||||
this.openTab(id, list, true);
|
this.openTab(id, { state: list, load: url || true });
|
||||||
}
|
}
|
||||||
openTab(id, state = new Map(this.state.tabs), load) {
|
openTab(
|
||||||
|
id,
|
||||||
|
{
|
||||||
|
state = new Map(this.state.tabs),
|
||||||
|
slideOut = new Set(this.state.slideOut),
|
||||||
|
load,
|
||||||
|
} = {
|
||||||
|
state: new Map(this.state.tabs),
|
||||||
|
slideOut: new Set(this.state.slideOut),
|
||||||
|
load: false,
|
||||||
|
}
|
||||||
|
) {
|
||||||
if (!id && id !== 0) {
|
if (!id && id !== 0) {
|
||||||
if (state.get(this.views.current.id)[1]) return;
|
if (state.get(this.views.current.id).open) return;
|
||||||
const currentIndex = [...state].findIndex(
|
const currentIndex = [...state].findIndex(
|
||||||
([id, [title, open]]) => id === this.views.current.id
|
([id, { title, open }]) => id === this.views.current.id
|
||||||
);
|
);
|
||||||
id = ([...state].find(
|
id = (
|
||||||
([id, [title, open]], tabIndex) => open && tabIndex > currentIndex
|
[...state].find(
|
||||||
) || [...state].find(([id, [title, open]]) => open))[0];
|
([id, { title, open }], tabIndex) =>
|
||||||
|
open && tabIndex > currentIndex
|
||||||
|
) || [...state].find(([id, { title, open }]) => open)
|
||||||
|
).title;
|
||||||
}
|
}
|
||||||
const current_src = this.views.current.$el().src;
|
const current_src = this.views.current.$el().src;
|
||||||
this.views.current.id = id;
|
this.views.current.id = id;
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
tabs: state.set(id, [
|
tabs: state.set(id, {
|
||||||
state.get(id) ? state.get(id)[0] : 'notion.so',
|
title: state.get(id) ? state.get(id).title : 'notion.so',
|
||||||
true,
|
open: true,
|
||||||
]),
|
}),
|
||||||
slideIn: load ? this.state.slideIn.add(id) : this.state.slideIn,
|
slideIn: load ? this.state.slideIn.add(id) : this.state.slideIn,
|
||||||
|
slideOut: slideOut,
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
this.focusTab();
|
this.focusTab();
|
||||||
@ -264,29 +282,29 @@ module.exports = (store, __exports) => {
|
|||||||
};
|
};
|
||||||
this.views.html[id].addEventListener('did-stop-loading', unhide);
|
this.views.html[id].addEventListener('did-stop-loading', unhide);
|
||||||
this.views.html[id].loadURL(
|
this.views.html[id].loadURL(
|
||||||
store().default_page
|
typeof load === 'string'
|
||||||
|
? load
|
||||||
|
: store().default_page
|
||||||
? idToNotionURL(store().default_page)
|
? idToNotionURL(store().default_page)
|
||||||
: current_src
|
: current_src
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
|
||||||
const slideIn = new Set(this.state.slideIn);
|
|
||||||
slideIn.delete(id);
|
|
||||||
this.setState({ slideIn });
|
|
||||||
}, 100);
|
|
||||||
// this.views.html[id].getWebContents().openDevTools();
|
// this.views.html[id].getWebContents().openDevTools();
|
||||||
}
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setState({ slideIn: new Set(), slideOut: new Set() });
|
||||||
|
}, 150);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
closeTab(id) {
|
closeTab(id) {
|
||||||
if ((!id && id !== 0) || !this.state.tabs.get(id)) return;
|
if ((!id && id !== 0) || !this.state.tabs.get(id)) return;
|
||||||
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), open: false });
|
||||||
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(
|
this.openTab(
|
||||||
this.views.current.id === id ? null : this.views.current.id,
|
this.views.current.id === id ? null : this.views.current.id,
|
||||||
list
|
{ state: list, slideOut: this.state.slideOut.add(id) }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
focusTab() {
|
focusTab() {
|
||||||
@ -297,11 +315,20 @@ module.exports = (store, __exports) => {
|
|||||||
for (const id in this.views.loaded) {
|
for (const id in this.views.loaded) {
|
||||||
if (this.views.loaded.hasOwnProperty(id) && this.views.loaded[id]) {
|
if (this.views.loaded.hasOwnProperty(id) && this.views.loaded[id]) {
|
||||||
const selected =
|
const selected =
|
||||||
id == this.views.current.id && this.state.tabs.get(+id);
|
id == this.views.current.id &&
|
||||||
|
this.state.tabs.get(+id) &&
|
||||||
|
this.state.tabs.get(+id).open;
|
||||||
this.views.loaded[id].style.display = selected ? 'flex' : 'none';
|
this.views.loaded[id].style.display = selected ? 'flex' : 'none';
|
||||||
if (selected) {
|
if (selected) {
|
||||||
this.views.active = this.views.current.id;
|
this.views.active = +id;
|
||||||
this.views.loaded[id].focus();
|
this.views.loaded[id].focus();
|
||||||
|
const electronWindow = electron.remote.getCurrentWindow();
|
||||||
|
if (
|
||||||
|
electronWindow &&
|
||||||
|
electronWindow.getTitle() !== this.state.tabs.get(+id).title
|
||||||
|
) {
|
||||||
|
electronWindow.setTitle(this.state.tabs.get(+id).title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,10 +369,10 @@ module.exports = (store, __exports) => {
|
|||||||
if (this.state.tabs.get(+event.target.id)) {
|
if (this.state.tabs.get(+event.target.id)) {
|
||||||
this.setState({
|
this.setState({
|
||||||
tabs: new Map(
|
tabs: new Map(
|
||||||
this.state.tabs.set(+event.target.id, [
|
this.state.tabs.set(+event.target.id, {
|
||||||
event.args[0],
|
...this.state.tabs.get(+event.target.id),
|
||||||
this.state.tabs.get(+event.target.id)[1],
|
title: event.args[0],
|
||||||
])
|
})
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
const electronWindow = electron.remote.getCurrentWindow();
|
const electronWindow = electron.remote.getCurrentWindow();
|
||||||
@ -360,7 +387,7 @@ module.exports = (store, __exports) => {
|
|||||||
this.selectTab(event.args[0]);
|
this.selectTab(event.args[0]);
|
||||||
break;
|
break;
|
||||||
case 'enhancer:new-tab':
|
case 'enhancer:new-tab':
|
||||||
this.newTab();
|
this.newTab(event.args[0]);
|
||||||
break;
|
break;
|
||||||
case 'enhancer:close-tab':
|
case 'enhancer:close-tab':
|
||||||
if (document.querySelector('.tab.current .close'))
|
if (document.querySelector('.tab.current .close'))
|
||||||
@ -513,6 +540,7 @@ module.exports = (store, __exports) => {
|
|||||||
Object.entries(this.views.html)
|
Object.entries(this.views.html)
|
||||||
.filter(([id, $notion]) => !this.views.loaded[id] && $notion)
|
.filter(([id, $notion]) => !this.views.loaded[id] && $notion)
|
||||||
.forEach(([id, $notion]) => {
|
.forEach(([id, $notion]) => {
|
||||||
|
if (!$notion) return;
|
||||||
this.views.loaded[id] = $notion;
|
this.views.loaded[id] = $notion;
|
||||||
$notion.addEventListener('did-fail-load', (error) => {
|
$notion.addEventListener('did-fail-load', (error) => {
|
||||||
// logger.info('Failed to load:', error);
|
// logger.info('Failed to load:', error);
|
||||||
@ -628,20 +656,26 @@ module.exports = (store, __exports) => {
|
|||||||
'div',
|
'div',
|
||||||
{ id: 'tabs' },
|
{ id: 'tabs' },
|
||||||
...[...this.state.tabs]
|
...[...this.state.tabs]
|
||||||
.filter(([id, [title, open]]) => open)
|
.filter(
|
||||||
.map(([id, [title, open]]) =>
|
([id, { title, open }]) => open || this.state.slideOut.has(id)
|
||||||
|
)
|
||||||
|
.map(([id, { title, open }]) =>
|
||||||
React.createElement(
|
React.createElement(
|
||||||
'button',
|
'button',
|
||||||
{
|
{
|
||||||
className:
|
className:
|
||||||
'tab' +
|
'tab' +
|
||||||
(id === this.views.current.id ? ' current' : '') +
|
(id === this.views.current.id ? ' current' : '') +
|
||||||
(this.state.slideIn.has(id) ? ' slideIn' : ''),
|
(this.state.slideIn.has(id) ? ' slideIn' : '') +
|
||||||
|
(this.state.slideOut.has(id) ? ' slideOut' : ''),
|
||||||
draggable: true,
|
draggable: true,
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
if (!e.target.classList.contains('close'))
|
if (!e.target.classList.contains('close'))
|
||||||
this.openTab(id);
|
this.openTab(id);
|
||||||
},
|
},
|
||||||
|
onMouseUp: (e) => {
|
||||||
|
if (window.event.which === 2) this.closeTab(id);
|
||||||
|
},
|
||||||
ref: ($tab) => {
|
ref: ($tab) => {
|
||||||
this.views.tabs[id] = $tab;
|
this.views.tabs[id] = $tab;
|
||||||
},
|
},
|
||||||
@ -674,7 +708,7 @@ module.exports = (store, __exports) => {
|
|||||||
}
|
}
|
||||||
renderNotionContainer() {
|
renderNotionContainer() {
|
||||||
this.views.react = Object.fromEntries(
|
this.views.react = Object.fromEntries(
|
||||||
[...this.state.tabs].map(([id, [title, open]]) => {
|
[...this.state.tabs].map(([id, { title, open }]) => {
|
||||||
return [
|
return [
|
||||||
id,
|
id,
|
||||||
this.views.react[id] ||
|
this.views.react[id] ||
|
||||||
|
@ -76,8 +76,8 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
|||||||
await fs.outputFile(
|
await fs.outputFile(
|
||||||
bin_path,
|
bin_path,
|
||||||
bin_script
|
bin_script
|
||||||
.replace('electron app.asar\n', 'electron app\n')
|
.replace('electron app.asar', 'electron app')
|
||||||
.replace('electron6 app.asar\n', 'electron6 app\n')
|
.replace('electron6 app.asar', 'electron6 app')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,9 @@ module.exports = async function ({
|
|||||||
await fs.outputFile(
|
await fs.outputFile(
|
||||||
bin_path,
|
bin_path,
|
||||||
bin_script
|
bin_script
|
||||||
.replace('electron app\n', 'electron app.asar\n')
|
.replace('electron app', 'electron app.asar')
|
||||||
.replace('electron6 app\n', 'electron6 app.asar\n')
|
.replace('electron6 app', 'electron6 app.asar')
|
||||||
|
.replace(/(.asar)+/g, '.asar')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user