mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-10 15:39:01 +00:00
taken control of createWindow
This commit is contained in:
parent
0621a5710c
commit
a3e55c6121
1
repo/core/icons/alwaysontop_off.svg
Normal file
1
repo/core/icons/alwaysontop_off.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><path fill="#000" d="M124.859 234.52L67.5474 135.736H102.683V12.184H147.323V135.736H182.459L124.859 234.52Z"/></svg>
|
After (image error) Size: 215 B |
1
repo/core/icons/alwaysontop_on.svg
Normal file
1
repo/core/icons/alwaysontop_on.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><path fill="#000" d="M102.683 234.52V110.968H67.5474L124.859 12.184L182.459 110.968H147.323V234.52H102.683Z"/></svg>
|
After (image error) Size: 215 B |
1
repo/core/icons/close.svg
Normal file
1
repo/core/icons/close.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><line x1="21.393" x2="233.525" y1="229.525" y2="17.393" stroke="#000" stroke-miterlimit="4.139" stroke-width="30"/><line x1="17.607" x2="229.739" y1="17.393" y2="229.525" stroke="#000" stroke-linejoin="round" stroke-width="30"/></svg>
|
After (image error) Size: 333 B |
Before ![]() (image error) Size: 7.0 KiB After ![]() (image error) Size: 7.0 KiB ![]() ![]() |
1
repo/core/icons/maximise_off.svg
Normal file
1
repo/core/icons/maximise_off.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><path fill="#000" d="M14.7346 227.26V7.03998H235.215V227.26H14.7346ZM46.4546 195.8H203.495V70.48H46.4546V195.8Z"/></svg>
|
After (image error) Size: 219 B |
1
repo/core/icons/maximise_on.svg
Normal file
1
repo/core/icons/maximise_on.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><path fill="#000" d="M16.1311 225.96V76.72H84.5111V8.07999H233.751V157.32H165.371V225.96H16.1311ZM110.771 53.58V76.72H165.371V131.32H207.491V53.58H110.771ZM42.3911 199.96H139.111V122.22H42.3911V199.96Z"/></svg>
|
After (image error) Size: 309 B |
1
repo/core/icons/minimise.svg
Normal file
1
repo/core/icons/minimise.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="250" height="250" fill="none" viewBox="0 0 250 250"><path fill="#000" d="M17.8021 138.04V106.072H232.074V138.04H17.8021Z"/></svg>
|
After (image error) Size: 176 B |
Before (image error) Size: 110 KiB After (image error) Size: 110 KiB |
@ -7,7 +7,8 @@
|
|||||||
const defaults = {
|
const defaults = {
|
||||||
openhidden: false,
|
openhidden: false,
|
||||||
maximized: false,
|
maximized: false,
|
||||||
tray: false,
|
close_to_tray: false,
|
||||||
|
frameless: true,
|
||||||
hotkey: 'CmdOrCtrl+Shift+A',
|
hotkey: 'CmdOrCtrl+Shift+A',
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,10 +25,13 @@ module.exports = {
|
|||||||
options: [],
|
options: [],
|
||||||
hacks: {
|
hacks: {
|
||||||
'main/main.js': require('./tray.js')(defaults),
|
'main/main.js': require('./tray.js')(defaults),
|
||||||
'renderer/preload.js': function (store) {
|
'main/createWindow.js': require('./window.js')(defaults),
|
||||||
const data = store({ name: 'dragonwocky' });
|
'renderer/preload.js': function (store, __exports) {
|
||||||
console.log(data.name);
|
const window = require('electron').remote.getCurrentWindow();
|
||||||
data.name = 'tom';
|
document.defaultView.addEventListener('keyup', (event) => {
|
||||||
|
if (event.code === 'F5') window.reload();
|
||||||
|
// if (event.code === 'F4' && event.altKey) window.close();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
let tray;
|
let tray;
|
||||||
|
|
||||||
module.exports = (defaults) =>
|
module.exports = (defaults) =>
|
||||||
function (store) {
|
function (store, __exports) {
|
||||||
const electron = require('electron'),
|
const electron = require('electron'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
is_mac = process.platform === 'darwin',
|
is_mac = process.platform === 'darwin',
|
||||||
@ -18,9 +18,9 @@ module.exports = (defaults) =>
|
|||||||
electron.app.on('ready', () => {
|
electron.app.on('ready', () => {
|
||||||
tray = new electron.Tray(
|
tray = new electron.Tray(
|
||||||
is_win
|
is_win
|
||||||
? path.normalize(`${__dirname}/windows.ico`)
|
? path.resolve(`${__dirname}/icons/windows.ico`)
|
||||||
: new electron.nativeImage.createFromPath(
|
: new electron.nativeImage.createFromPath(
|
||||||
path.normalize(`${__dirname}/mac+linux.png`)
|
path.resolve(`${__dirname}/icons/mac+linux.png`)
|
||||||
).resize({
|
).resize({
|
||||||
width: 16,
|
width: 16,
|
||||||
height: 16,
|
height: 16,
|
||||||
@ -31,10 +31,20 @@ module.exports = (defaults) =>
|
|||||||
{
|
{
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
label: 'Bug Report',
|
label: 'Bug Report',
|
||||||
|
click: () => {
|
||||||
|
electron.shell.openExternal(
|
||||||
|
'https://github.com/dragonwocky/notion-enhancer/issues/new?labels=bug&template=bug-report.md'
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
label: 'Feature Request',
|
label: 'Feature Request',
|
||||||
|
click: () => {
|
||||||
|
electron.shell.openExternal(
|
||||||
|
'https://github.com/dragonwocky/notion-enhancer/issues/new?labels=enhancement&template=feature-request.md'
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'separator',
|
type: 'separator',
|
||||||
@ -42,6 +52,11 @@ module.exports = (defaults) =>
|
|||||||
{
|
{
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
label: 'Docs',
|
label: 'Docs',
|
||||||
|
click: () => {
|
||||||
|
electron.shell.openExternal(
|
||||||
|
'https://github.com/dragonwocky/notion-enhancer/tree/js'
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
@ -70,6 +85,7 @@ module.exports = (defaults) =>
|
|||||||
windows.forEach((win) => [win.isFocused() && win.blur(), win.hide()]);
|
windows.forEach((win) => [win.isFocused() && win.blur(), win.hide()]);
|
||||||
if (is_mac) electron.app.hide();
|
if (is_mac) electron.app.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
tray.on('click', () => {
|
tray.on('click', () => {
|
||||||
const windows = electron.BrowserWindow.getAllWindows();
|
const windows = electron.BrowserWindow.getAllWindows();
|
||||||
if (windows.some((win) => win.isVisible())) hideWindows();
|
if (windows.some((win) => win.isVisible())) hideWindows();
|
||||||
|
85
repo/core/window.js
Normal file
85
repo/core/window.js
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* notion-enhancer
|
||||||
|
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com>
|
||||||
|
* (c) 2020 TarasokUA
|
||||||
|
* (https://dragonwocky.me/) under the MIT license
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = (defaults) =>
|
||||||
|
function (store, __exports) {
|
||||||
|
const electron = require('electron'),
|
||||||
|
allWindows = electron.BrowserWindow.getAllWindows,
|
||||||
|
createWindow = __exports.createWindow,
|
||||||
|
path = require('path'),
|
||||||
|
is_mac = process.platform === 'darwin',
|
||||||
|
settings = store(defaults),
|
||||||
|
helpers = require('../../pkg/helpers.js'),
|
||||||
|
__notion = helpers.getNotion();
|
||||||
|
|
||||||
|
__exports.createWindow = function (relativeUrl) {
|
||||||
|
if (!relativeUrl) relativeUrl = '';
|
||||||
|
const window_state = require(`${__notion.replace(
|
||||||
|
/\\/g,
|
||||||
|
'/'
|
||||||
|
)}/app/node_modules/electron-window-state/index.js`)({
|
||||||
|
defaultWidth: 1320,
|
||||||
|
defaultHeight: 860,
|
||||||
|
}),
|
||||||
|
rect = {
|
||||||
|
x: window_state.x,
|
||||||
|
y: window_state.y,
|
||||||
|
width: window_state.width,
|
||||||
|
height: window_state.height,
|
||||||
|
},
|
||||||
|
focused_window = electron.BrowserWindow.getFocusedWindow();
|
||||||
|
if (focused_window && !focused_window.isMaximized()) {
|
||||||
|
rect.x = focused_window.getPosition()[0] + 20;
|
||||||
|
rect.y = focused_window.getPosition()[1] + 20;
|
||||||
|
rect.width = focused_window.getSize()[0];
|
||||||
|
rect.height = focused_window.getSize()[1];
|
||||||
|
}
|
||||||
|
const window = new electron.BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
backgroundColor: '#ffffff',
|
||||||
|
titleBarStyle: 'hiddenInset',
|
||||||
|
frame: !settings.frameless,
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.resolve(`${__notion}/app/renderer/index.js`),
|
||||||
|
webviewTag: true,
|
||||||
|
session: electron.session.fromPartition('persist:notion'),
|
||||||
|
},
|
||||||
|
...rect,
|
||||||
|
});
|
||||||
|
window.once('ready-to-show', function () {
|
||||||
|
if (
|
||||||
|
!settings.openhidden ||
|
||||||
|
allWindows().some((win) => win.isVisible() && win.id != window.id)
|
||||||
|
) {
|
||||||
|
window.show();
|
||||||
|
if (settings.maximized) window.maximize();
|
||||||
|
if (
|
||||||
|
(focused_window && focused_window.isFullScreen()) ||
|
||||||
|
window_state.isFullScreen
|
||||||
|
)
|
||||||
|
window.setFullScreen(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let intended_quit = false;
|
||||||
|
window.on('close', (e) => {
|
||||||
|
if (
|
||||||
|
intended_quit ||
|
||||||
|
!settings.close_to_tray ||
|
||||||
|
allWindows().length > 1
|
||||||
|
) {
|
||||||
|
window_state.saveState(window);
|
||||||
|
window = null;
|
||||||
|
} else {
|
||||||
|
e.preventDefault();
|
||||||
|
window.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
electron.app.on('before-quit', () => (intended_quit = true));
|
||||||
|
window.loadURL(__exports.getIndexUrl(relativeUrl));
|
||||||
|
return window;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user