2020-04-12 04:06:04 +08:00
|
|
|
import appContext from "./services/app_context.js";
|
2018-12-29 17:04:59 +08:00
|
|
|
import utils from './services/utils.js';
|
|
|
|
import noteTooltipService from './services/note_tooltip.js';
|
2020-04-12 20:22:51 +08:00
|
|
|
import bundleService from "./services/bundle.js";
|
2018-12-29 17:04:59 +08:00
|
|
|
import noteAutocompleteService from './services/note_autocomplete.js';
|
2019-01-10 05:08:24 +08:00
|
|
|
import macInit from './services/mac_init.js';
|
2020-02-29 18:28:30 +08:00
|
|
|
import contextMenu from "./services/context_menu.js";
|
2020-04-26 05:52:13 +08:00
|
|
|
import DesktopMainWindowLayout from "./layouts/desktop_main_window_layout.js";
|
2020-04-12 20:22:51 +08:00
|
|
|
import glob from "./services/glob.js";
|
2020-04-26 05:52:13 +08:00
|
|
|
import DesktopExtraWindowLayout from "./layouts/desktop_extra_window_layout.js";
|
2020-04-12 20:22:51 +08:00
|
|
|
|
|
|
|
glob.setupGlobs();
|
2018-03-24 23:18:46 +08:00
|
|
|
|
2018-03-27 10:29:14 +08:00
|
|
|
if (utils.isElectron()) {
|
2020-04-12 20:22:51 +08:00
|
|
|
utils.dynamicRequire('electron').ipcRenderer.on('globalShortcut', async function(event, actionName) {
|
2020-03-18 04:39:26 +08:00
|
|
|
appContext.triggerCommand(actionName);
|
2018-03-27 10:29:14 +08:00
|
|
|
});
|
|
|
|
}
|
2018-03-26 10:37:02 +08:00
|
|
|
|
2019-02-24 18:36:01 +08:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({
|
|
|
|
html: true
|
|
|
|
});
|
|
|
|
|
2020-02-15 03:18:09 +08:00
|
|
|
macInit.init();
|
2019-01-26 05:18:34 +08:00
|
|
|
|
2020-03-17 04:16:09 +08:00
|
|
|
bundleService.getWidgetBundlesByParent().then(widgetBundles => {
|
2020-04-26 05:52:13 +08:00
|
|
|
const layout = window.glob.isMainWindow
|
|
|
|
? new DesktopMainWindowLayout(widgetBundles)
|
|
|
|
: new DesktopExtraWindowLayout(widgetBundles);
|
2020-03-17 04:16:09 +08:00
|
|
|
|
2020-04-26 05:52:13 +08:00
|
|
|
appContext.setLayout(layout);
|
2020-03-17 04:16:09 +08:00
|
|
|
appContext.start();
|
|
|
|
});
|
2018-03-27 10:29:14 +08:00
|
|
|
|
2018-12-23 03:57:09 +08:00
|
|
|
noteTooltipService.setupGlobalTooltip();
|
2018-03-27 10:29:14 +08:00
|
|
|
|
2020-02-29 05:07:08 +08:00
|
|
|
noteAutocompleteService.init();
|
|
|
|
|
|
|
|
if (utils.isElectron()) {
|
2020-04-12 20:22:51 +08:00
|
|
|
const electron = utils.dynamicRequire('electron');
|
2020-02-29 18:28:30 +08:00
|
|
|
const {webContents} = electron.remote.getCurrentWindow();
|
2020-02-29 05:07:08 +08:00
|
|
|
|
|
|
|
webContents.on('context-menu', (event, params) => {
|
2020-02-29 18:28:30 +08:00
|
|
|
const {editFlags} = params;
|
|
|
|
const hasText = params.selectionText.trim().length > 0;
|
|
|
|
const isMac = process.platform === "darwin";
|
|
|
|
const platformModifier = isMac ? 'Meta' : 'Ctrl';
|
2020-02-29 05:07:08 +08:00
|
|
|
|
2020-02-29 18:28:30 +08:00
|
|
|
const items = [];
|
2020-02-29 05:07:08 +08:00
|
|
|
|
2020-02-29 18:28:30 +08:00
|
|
|
if (params.misspelledWord) {
|
2020-02-29 05:07:08 +08:00
|
|
|
for (const suggestion of params.dictionarySuggestions) {
|
|
|
|
items.push({
|
|
|
|
title: suggestion,
|
|
|
|
command: "replaceMisspelling",
|
|
|
|
spellingSuggestion: suggestion,
|
2020-02-29 18:28:30 +08:00
|
|
|
uiIcon: "empty"
|
2020-02-29 05:07:08 +08:00
|
|
|
});
|
|
|
|
}
|
2020-02-29 18:28:30 +08:00
|
|
|
|
|
|
|
items.push({
|
|
|
|
title: `Add "${params.misspelledWord}" to dictionary`,
|
|
|
|
uiIcon: "plus",
|
|
|
|
handler: () => webContents.session.addWordToSpellCheckerDictionary(params.misspelledWord)
|
|
|
|
});
|
|
|
|
|
|
|
|
items.push({ title: `----` });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.isEditable) {
|
|
|
|
items.push({
|
|
|
|
enabled: editFlags.canCut && hasText,
|
|
|
|
title: `Cut <kbd>${platformModifier}+X`,
|
|
|
|
uiIcon: "cut",
|
|
|
|
handler: () => webContents.cut()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.isEditable || hasText) {
|
|
|
|
items.push({
|
|
|
|
enabled: editFlags.canCopy && hasText,
|
|
|
|
title: `Copy <kbd>${platformModifier}+C`,
|
|
|
|
uiIcon: "copy",
|
|
|
|
handler: () => webContents.copy()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-30 04:27:22 +08:00
|
|
|
if (!["", "javascript:", "about:blank#blocked"].includes(params.linkURL) && params.mediaType === 'none') {
|
2020-02-29 18:28:30 +08:00
|
|
|
items.push({
|
|
|
|
title: `Copy link`,
|
|
|
|
uiIcon: "copy",
|
|
|
|
handler: () => {
|
|
|
|
electron.clipboard.write({
|
|
|
|
bookmark: params.linkText,
|
|
|
|
text: params.linkURL
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.isEditable) {
|
|
|
|
items.push({
|
|
|
|
enabled: editFlags.canPaste,
|
|
|
|
title: `Paste <kbd>${platformModifier}+V`,
|
|
|
|
uiIcon: "paste",
|
|
|
|
handler: () => webContents.paste()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.isEditable) {
|
|
|
|
items.push({
|
|
|
|
enabled: editFlags.canPaste,
|
|
|
|
title: `Paste as plain text <kbd>${platformModifier}+Shift+V`,
|
|
|
|
uiIcon: "paste",
|
|
|
|
handler: () => webContents.pasteAndMatchStyle()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasText) {
|
|
|
|
const shortenedSelection = params.selectionText.length > 15
|
|
|
|
? (params.selectionText.substr(0, 13) + "…")
|
|
|
|
: params.selectionText;
|
|
|
|
|
|
|
|
items.push({
|
|
|
|
enabled: editFlags.canPaste,
|
|
|
|
title: `Search for "${shortenedSelection}" with DuckDuckGo`,
|
|
|
|
uiIcon: "search-alt",
|
|
|
|
handler: () => electron.shell.openExternal(`https://duckduckgo.com/?q=${encodeURIComponent(params.selectionText)}`)
|
|
|
|
});
|
2020-02-29 05:07:08 +08:00
|
|
|
}
|
|
|
|
|
2020-03-09 00:17:18 +08:00
|
|
|
if (items.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-29 18:28:30 +08:00
|
|
|
contextMenu.show({
|
2020-02-29 05:07:08 +08:00
|
|
|
x: params.x,
|
|
|
|
y: params.y,
|
|
|
|
items,
|
2020-02-29 18:28:30 +08:00
|
|
|
selectMenuItemHandler: ({command, spellingSuggestion}) => {
|
2020-02-29 05:07:08 +08:00
|
|
|
if (command === 'replaceMisspelling') {
|
2020-02-29 18:28:30 +08:00
|
|
|
webContents.insertText(spellingSuggestion);
|
2020-02-29 05:07:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|