mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-07 05:59:02 +00:00
un-break titlebar+menu (not sure how it was broken?)
This commit is contained in:
parent
01fe0d6782
commit
cb4407279e
@ -14,47 +14,43 @@ const store = require('../../pkg/store.js'),
|
|||||||
{ toKeyEvent } = require('keyboardevent-from-electron-accelerator');
|
{ toKeyEvent } = require('keyboardevent-from-electron-accelerator');
|
||||||
|
|
||||||
window['__start'] = async () => {
|
window['__start'] = async () => {
|
||||||
|
// mod loader
|
||||||
|
const modules = helpers.getEnhancements();
|
||||||
|
if (modules.loaded.length)
|
||||||
|
console.info(
|
||||||
|
`<notion-enhancer> enhancements loaded: ${modules.loaded
|
||||||
|
.map((mod) => mod.name)
|
||||||
|
.join(', ')}.`
|
||||||
|
);
|
||||||
|
if (modules.invalid.length) {
|
||||||
|
createAlert(
|
||||||
|
'error',
|
||||||
|
`invalid mods found: ${modules.invalid
|
||||||
|
.map((mod) => `<b>${mod}</b>`)
|
||||||
|
.join(', ')}.`
|
||||||
|
).append();
|
||||||
|
}
|
||||||
|
const coreStore = (...args) => {
|
||||||
|
const mod = modules.loaded.find(
|
||||||
|
(m) => m.id === '0f0bf8b6-eae6-4273-b307-8fc43f2ee082'
|
||||||
|
);
|
||||||
|
return !args.length
|
||||||
|
? store(mod.id, mod.defaults)
|
||||||
|
: args.length === 1 && typeof args[0] === 'object'
|
||||||
|
? store(mod.id, { ...mod.defaults, ...args[0] })
|
||||||
|
: store(args[0], { ...mod.defaults, ...args[1] });
|
||||||
|
};
|
||||||
|
|
||||||
const buttons = require('./buttons.js')(() => ({
|
const buttons = require('./buttons.js')(() => ({
|
||||||
'72886371-dada-49a7-9afc-9f275ecf29d3': {
|
'72886371-dada-49a7-9afc-9f275ecf29d3': {
|
||||||
enabled: (store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {})
|
enabled: (store('mods')['72886371-dada-49a7-9afc-9f275ecf29d3'] || {})
|
||||||
.enabled,
|
.enabled,
|
||||||
},
|
},
|
||||||
tiling_mode: store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082').tiling_mode,
|
tiling_mode: coreStore().tiling_mode,
|
||||||
frameless: store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082').frameless,
|
frameless: coreStore().frameless,
|
||||||
}));
|
}));
|
||||||
document.querySelector('#titlebar').appendChild(buttons.element);
|
document.querySelector('#titlebar').appendChild(buttons.element);
|
||||||
|
|
||||||
document.defaultView.addEventListener('keyup', (event) => {
|
|
||||||
if (event.code === 'F5') location.reload();
|
|
||||||
const meta =
|
|
||||||
!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey;
|
|
||||||
if (
|
|
||||||
meta &&
|
|
||||||
document.activeElement.parentElement.id === 'tags' &&
|
|
||||||
event.key === 'Enter'
|
|
||||||
)
|
|
||||||
document.activeElement.click();
|
|
||||||
if (document.activeElement.tagName.toLowerCase() === 'input') {
|
|
||||||
if (document.activeElement.type === 'checkbox' && event.key === 'Enter')
|
|
||||||
document.activeElement.checked = !document.activeElement.checked;
|
|
||||||
if (
|
|
||||||
['Escape', 'Enter'].includes(event.key) &&
|
|
||||||
document.activeElement.type !== 'checkbox' &&
|
|
||||||
(document.activeElement.parentElement.id !== 'search' ||
|
|
||||||
event.key === 'Escape')
|
|
||||||
)
|
|
||||||
document.activeElement.blur();
|
|
||||||
} else if (meta && event.key === '/')
|
|
||||||
document.querySelector('#search > input').focus();
|
|
||||||
if (
|
|
||||||
(event.ctrlKey || event.metaKey) &&
|
|
||||||
event.key === 'f' &&
|
|
||||||
!event.altKey &&
|
|
||||||
!event.shiftKey
|
|
||||||
)
|
|
||||||
document.querySelector('#search > input').focus();
|
|
||||||
});
|
|
||||||
|
|
||||||
electron.ipcRenderer.send('enhancer:get-menu-theme');
|
electron.ipcRenderer.send('enhancer:get-menu-theme');
|
||||||
electron.ipcRenderer.on('enhancer:set-menu-theme', (event, theme) => {
|
electron.ipcRenderer.on('enhancer:set-menu-theme', (event, theme) => {
|
||||||
for (const style of theme)
|
for (const style of theme)
|
||||||
@ -120,26 +116,10 @@ window['__start'] = async () => {
|
|||||||
).prepend();
|
).prepend();
|
||||||
});
|
});
|
||||||
|
|
||||||
// mod loader
|
|
||||||
const modules = helpers.getEnhancements();
|
|
||||||
if (modules.loaded.length)
|
|
||||||
console.info(
|
|
||||||
`<notion-enhancer> enhancements loaded: ${modules.loaded
|
|
||||||
.map((mod) => mod.name)
|
|
||||||
.join(', ')}.`
|
|
||||||
);
|
|
||||||
if (modules.invalid.length) {
|
|
||||||
createAlert(
|
|
||||||
'error',
|
|
||||||
`invalid mods found: ${modules.invalid
|
|
||||||
.map((mod) => `<b>${mod}</b>`)
|
|
||||||
.join(', ')}.`
|
|
||||||
).append();
|
|
||||||
}
|
|
||||||
|
|
||||||
// further-configuration popup
|
|
||||||
const $popup = document.querySelector('#popup');
|
const $popup = document.querySelector('#popup');
|
||||||
document.addEventListener('keyup', (event) => {
|
document.addEventListener('keyup', (event) => {
|
||||||
|
if (event.code === 'F5') location.reload();
|
||||||
|
// further-configuration popup
|
||||||
if (
|
if (
|
||||||
$popup.classList.contains('visible') &&
|
$popup.classList.contains('visible') &&
|
||||||
['Enter', 'Escape'].includes(event.key)
|
['Enter', 'Escape'].includes(event.key)
|
||||||
@ -147,18 +127,41 @@ window['__start'] = async () => {
|
|||||||
$popup.classList.remove('visible');
|
$popup.classList.remove('visible');
|
||||||
// close window on hotkey toggle
|
// close window on hotkey toggle
|
||||||
console.log();
|
console.log();
|
||||||
const hotkey = toKeyEvent(
|
const hotkey = toKeyEvent(coreStore().menu_toggle);
|
||||||
store('0f0bf8b6-eae6-4273-b307-8fc43f2ee082', {
|
|
||||||
menu_toggle: modules.loaded
|
|
||||||
.find((m) => m.id === '0f0bf8b6-eae6-4273-b307-8fc43f2ee082')
|
|
||||||
.options.find((o) => o.key === 'menu_toggle').value,
|
|
||||||
}).menu_toggle
|
|
||||||
);
|
|
||||||
let triggered = true;
|
let triggered = true;
|
||||||
for (let prop in hotkey)
|
for (let prop in hotkey)
|
||||||
if (hotkey[prop] !== event[prop]) triggered = false;
|
if (hotkey[prop] !== event[prop]) triggered = false;
|
||||||
if (triggered) electron.remote.getCurrentWindow().close();
|
if (triggered) electron.remote.getCurrentWindow().close();
|
||||||
|
// focus search
|
||||||
|
const meta =
|
||||||
|
!(event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey;
|
||||||
|
if (
|
||||||
|
meta &&
|
||||||
|
document.activeElement.parentElement.id === 'tags' &&
|
||||||
|
event.key === 'Enter'
|
||||||
|
)
|
||||||
|
document.activeElement.click();
|
||||||
|
if (document.activeElement.tagName.toLowerCase() === 'input') {
|
||||||
|
if (document.activeElement.type === 'checkbox' && event.key === 'Enter')
|
||||||
|
document.activeElement.checked = !document.activeElement.checked;
|
||||||
|
if (
|
||||||
|
['Escape', 'Enter'].includes(event.key) &&
|
||||||
|
document.activeElement.type !== 'checkbox' &&
|
||||||
|
(document.activeElement.parentElement.id !== 'search' ||
|
||||||
|
event.key === 'Escape')
|
||||||
|
)
|
||||||
|
document.activeElement.blur();
|
||||||
|
} else if (meta && event.key === '/')
|
||||||
|
document.querySelector('#search > input').focus();
|
||||||
|
if (
|
||||||
|
(event.ctrlKey || event.metaKey) &&
|
||||||
|
event.key === 'f' &&
|
||||||
|
!event.altKey &&
|
||||||
|
!event.shiftKey
|
||||||
|
)
|
||||||
|
document.querySelector('#search > input').focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
let colorpicker_target = null;
|
let colorpicker_target = null;
|
||||||
const $colorpicker = colorjoe
|
const $colorpicker = colorjoe
|
||||||
.rgb('colorpicker')
|
.rgb('colorpicker')
|
||||||
@ -171,7 +174,6 @@ window['__start'] = async () => {
|
|||||||
store(colorpicker_target.id)[colorpicker_target.key] = color.css();
|
store(colorpicker_target.id)[colorpicker_target.key] = color.css();
|
||||||
})
|
})
|
||||||
.update();
|
.update();
|
||||||
|
|
||||||
document
|
document
|
||||||
.querySelector('#colorpicker')
|
.querySelector('#colorpicker')
|
||||||
.appendChild(
|
.appendChild(
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
const url = require('url'),
|
const url = require('url'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
electron = require('electron'),
|
electron = require('electron'),
|
||||||
browserWindow = electron.remote.getCurrentWindow(),
|
|
||||||
{ __notion } = require('../../pkg/helpers.js'),
|
{ __notion } = require('../../pkg/helpers.js'),
|
||||||
config = require(`${__notion}/app/config.js`),
|
config = require(`${__notion}/app/config.js`),
|
||||||
constants = require(`${__notion}/app/shared/constants.js`),
|
constants = require(`${__notion}/app/shared/constants.js`),
|
||||||
@ -219,11 +218,12 @@ module.exports = (store, __exports) => {
|
|||||||
) {
|
) {
|
||||||
this.views.tabs[event.target.id].children[0].innerText =
|
this.views.tabs[event.target.id].children[0].innerText =
|
||||||
event.args[0];
|
event.args[0];
|
||||||
|
const electronWindow = electron.remote.getCurrentWindow();
|
||||||
if (
|
if (
|
||||||
event.target.id == this.views.current.id &&
|
event.target.id == this.views.current.id &&
|
||||||
browserWindow.getTitle() !== event.args[0]
|
electronWindow.getTitle() !== event.args[0]
|
||||||
)
|
)
|
||||||
browserWindow.setTitle(event.args[0]);
|
electronWindow.setTitle(event.args[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startSearch(isPeekView) {
|
startSearch(isPeekView) {
|
||||||
@ -426,25 +426,41 @@ module.exports = (store, __exports) => {
|
|||||||
this.setState({ zoomFactor });
|
this.setState({ zoomFactor });
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
let electronWindow;
|
||||||
|
try {
|
||||||
|
electronWindow = electron.remote.getCurrentWindow();
|
||||||
|
} catch (error) {
|
||||||
|
notionIpc.sendToMain('notion:log-error', {
|
||||||
|
level: 'error',
|
||||||
|
from: 'index',
|
||||||
|
type: 'GetCurrentWindowError',
|
||||||
|
error: error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!electronWindow) {
|
||||||
|
this.setState({ error: true });
|
||||||
|
this.handleReload();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const sendFullScreenChangeEvent = () => {
|
const sendFullScreenChangeEvent = () => {
|
||||||
notionIpc.sendIndexToNotion(
|
notionIpc.sendIndexToNotion(
|
||||||
$notion,
|
$notion,
|
||||||
'notion:full-screen-changed'
|
'notion:full-screen-changed'
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
browserWindow.addListener(
|
electronWindow.addListener(
|
||||||
'enter-full-screen',
|
'enter-full-screen',
|
||||||
sendFullScreenChangeEvent
|
sendFullScreenChangeEvent
|
||||||
);
|
);
|
||||||
browserWindow.addListener(
|
electronWindow.addListener(
|
||||||
'leave-full-screen',
|
'leave-full-screen',
|
||||||
sendFullScreenChangeEvent
|
sendFullScreenChangeEvent
|
||||||
);
|
);
|
||||||
browserWindow.addListener(
|
electronWindow.addListener(
|
||||||
'enter-html-full-screen',
|
'enter-html-full-screen',
|
||||||
sendFullScreenChangeEvent
|
sendFullScreenChangeEvent
|
||||||
);
|
);
|
||||||
browserWindow.addListener(
|
electronWindow.addListener(
|
||||||
'leave-html-full-screen',
|
'leave-html-full-screen',
|
||||||
sendFullScreenChangeEvent
|
sendFullScreenChangeEvent
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user