mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/window
This commit is contained in:
parent
ddcbb29a67
commit
330334dcb4
@ -3,7 +3,7 @@
|
|||||||
const {app, globalShortcut, BrowserWindow} = require('electron');
|
const {app, globalShortcut, BrowserWindow} = require('electron');
|
||||||
const sqlInit = require('./src/services/sql_init');
|
const sqlInit = require('./src/services/sql_init');
|
||||||
const appIconService = require('./src/services/app_icon.js');
|
const appIconService = require('./src/services/app_icon.js');
|
||||||
const windowService = require('./src/services/window.js');
|
const windowService = require('./src/services/window');
|
||||||
const tray = require('./src/services/tray.js');
|
const tray = require('./src/services/tray.js');
|
||||||
|
|
||||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||||
|
@ -9,7 +9,7 @@ const appPath = require('../services/app_path');
|
|||||||
function setupPage(req, res) {
|
function setupPage(req, res) {
|
||||||
if (sqlInit.isDbInitialized()) {
|
if (sqlInit.isDbInitialized()) {
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
const windowService = require('../services/window.js');
|
const windowService = require('../services/window');
|
||||||
const {app} = require('electron');
|
const {app} = require('electron');
|
||||||
windowService.createMainWindow(app);
|
windowService.createMainWindow(app);
|
||||||
windowService.closeSetupWindow();
|
windowService.closeSetupWindow();
|
||||||
|
@ -230,7 +230,7 @@ function getClient(opts: ClientOpts): Client {
|
|||||||
// it's not clear how to explicitly configure proxy (as opposed to system proxy),
|
// it's not clear how to explicitly configure proxy (as opposed to system proxy),
|
||||||
// so in that case, we always use node's modules
|
// so in that case, we always use node's modules
|
||||||
if (utils.isElectron() && !opts.proxy) {
|
if (utils.isElectron() && !opts.proxy) {
|
||||||
return require('electron').net;
|
return require('electron').net as Client;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const {protocol} = url.parse(opts.url);
|
const {protocol} = url.parse(opts.url);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const { Menu, Tray } = require('electron');
|
const { Menu, Tray } = require('electron');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const windowService = require('./window.js');
|
const windowService = require('./window');
|
||||||
const optionService = require('./options');
|
const optionService = require('./options');
|
||||||
|
|
||||||
const UPDATE_TRAY_EVENTS = [
|
const UPDATE_TRAY_EVENTS = [
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
const path = require('path');
|
import path = require('path');
|
||||||
const url = require("url");
|
import url = require("url");
|
||||||
const port = require('./port.ts');
|
import port = require('./port');
|
||||||
const optionService = require('./options');
|
import optionService = require('./options');
|
||||||
const env = require('./env');
|
import env = require('./env');
|
||||||
const log = require('./log');
|
import log = require('./log');
|
||||||
const sqlInit = require('./sql_init');
|
import sqlInit = require('./sql_init');
|
||||||
const cls = require('./cls');
|
import cls = require('./cls');
|
||||||
const keyboardActionsService = require('./keyboard_actions');
|
import keyboardActionsService = require('./keyboard_actions');
|
||||||
const {ipcMain} = require('electron');
|
import remoteMain = require("@electron/remote/main")
|
||||||
|
import { App, BrowserWindow, WebContents, ipcMain } from 'electron';
|
||||||
|
|
||||||
// Prevent the window being garbage collected
|
// Prevent the window being garbage collected
|
||||||
/** @type {Electron.BrowserWindow} */
|
let mainWindow: BrowserWindow | null;
|
||||||
let mainWindow;
|
let setupWindow: BrowserWindow | null;
|
||||||
/** @type {Electron.BrowserWindow} */
|
|
||||||
let setupWindow;
|
|
||||||
|
|
||||||
async function createExtraWindow(extraWindowHash) {
|
async function createExtraWindow(extraWindowHash: string) {
|
||||||
const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled');
|
const spellcheckEnabled = optionService.getOptionBool('spellCheckEnabled');
|
||||||
|
|
||||||
const {BrowserWindow} = require('electron');
|
const {BrowserWindow} = require('electron');
|
||||||
@ -25,7 +24,6 @@ async function createExtraWindow(extraWindowHash) {
|
|||||||
height: 800,
|
height: 800,
|
||||||
title: 'Trilium Notes',
|
title: 'Trilium Notes',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
enableRemoteModule: true,
|
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
spellcheck: spellcheckEnabled
|
spellcheck: spellcheckEnabled
|
||||||
@ -44,7 +42,7 @@ ipcMain.on('create-extra-window', (event, arg) => {
|
|||||||
createExtraWindow(arg.extraWindowHash);
|
createExtraWindow(arg.extraWindowHash);
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createMainWindow(app) {
|
async function createMainWindow(app: App) {
|
||||||
const windowStateKeeper = require('electron-window-state'); // should not be statically imported
|
const windowStateKeeper = require('electron-window-state'); // should not be statically imported
|
||||||
|
|
||||||
const mainWindowState = windowStateKeeper({
|
const mainWindowState = windowStateKeeper({
|
||||||
@ -64,7 +62,6 @@ async function createMainWindow(app) {
|
|||||||
height: mainWindowState.height,
|
height: mainWindowState.height,
|
||||||
title: 'Trilium Notes',
|
title: 'Trilium Notes',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
enableRemoteModule: true,
|
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
spellcheck: spellcheckEnabled,
|
spellcheck: spellcheckEnabled,
|
||||||
@ -95,8 +92,12 @@ async function createMainWindow(app) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function configureWebContents(webContents, spellcheckEnabled) {
|
function configureWebContents(webContents: WebContents, spellcheckEnabled: boolean) {
|
||||||
require("@electron/remote/main").enable(webContents);
|
if (!mainWindow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteMain.enable(webContents);
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
require("electron").shell.openExternal(details.url);
|
require("electron").shell.openExternal(details.url);
|
||||||
@ -108,8 +109,7 @@ function configureWebContents(webContents, spellcheckEnabled) {
|
|||||||
const parsedUrl = url.parse(targetUrl);
|
const parsedUrl = url.parse(targetUrl);
|
||||||
|
|
||||||
// we still need to allow internal redirects from setup and migration pages
|
// we still need to allow internal redirects from setup and migration pages
|
||||||
if (!['localhost', '127.0.0.1'].includes(parsedUrl.hostname) || (parsedUrl.path && parsedUrl.path !== '/' && parsedUrl.path !== '/?')) {
|
if (!['localhost', '127.0.0.1'].includes(parsedUrl.hostname || "") || (parsedUrl.path && parsedUrl.path !== '/' && parsedUrl.path !== '/?')) {
|
||||||
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -168,6 +168,10 @@ async function registerGlobalShortcuts() {
|
|||||||
const translatedShortcut = shortcut.substr(7);
|
const translatedShortcut = shortcut.substr(7);
|
||||||
|
|
||||||
const result = globalShortcut.register(translatedShortcut, cls.wrap(() => {
|
const result = globalShortcut.register(translatedShortcut, cls.wrap(() => {
|
||||||
|
if (!mainWindow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// window may be hidden / not in focus
|
// window may be hidden / not in focus
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
|
|
||||||
@ -189,8 +193,7 @@ function getMainWindow() {
|
|||||||
return mainWindow;
|
return mainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export = {
|
||||||
module.exports = {
|
|
||||||
createMainWindow,
|
createMainWindow,
|
||||||
createSetupWindow,
|
createSetupWindow,
|
||||||
closeSetupWindow,
|
closeSetupWindow,
|
@ -45,7 +45,7 @@ function startTrilium() {
|
|||||||
* instead of the new one. This is complicated by the fact that it is possible to run multiple instances of Trilium
|
* instead of the new one. This is complicated by the fact that it is possible to run multiple instances of Trilium
|
||||||
* if port and data dir are configured separately. This complication is the source of the following weird usage.
|
* if port and data dir are configured separately. This complication is the source of the following weird usage.
|
||||||
*
|
*
|
||||||
* The line below makes sure that the "second-instance" (process in window.js) is fired. Normally it returns a boolean
|
* The line below makes sure that the "second-instance" (process in window) is fired. Normally it returns a boolean
|
||||||
* indicating whether another instance is running or not, but we ignore that and kill the app only based on the port conflict.
|
* indicating whether another instance is running or not, but we ignore that and kill the app only based on the port conflict.
|
||||||
*
|
*
|
||||||
* A bit weird is that "second-instance" is triggered also on the valid usecases (different port/data dir) and
|
* A bit weird is that "second-instance" is triggered also on the valid usecases (different port/data dir) and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user