Repository URL to install this package:
Version:
2.0.11-7 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const process = require("process");
const electron = require("electron");
const notionIpc = require("../helpers/notionIpc");
const notion_intl_1 = require("notion-intl");
const localizationHelper_1 = require("../helpers/localizationHelper");
const urlHelpers = require("../shared/urlHelpers");
const messages = notion_intl_1.defineMessages({
dialogYesButton: {
id: "desktop.confirmationDialog.yesButton",
defaultMessage: "Yes",
},
dialogNoButton: {
id: "desktop.confirmationDialog.noButton",
defaultMessage: "No",
},
dialogTitle: {
id: "desktop.confirmationDialog.title",
defaultMessage: "Confirm",
},
});
const locale = window.navigator.language;
const notionLocale = localizationHelper_1.getNotionLocaleFromElectronLocale(locale);
const intl = localizationHelper_1.createIntlShape(notionLocale);
const electronApi = {
openInNewWindow(urlPath) {
notionIpc.sendToMain("notion:create-window", urlPath);
},
openExternalUrl(url) {
const sanitizedUrl = urlHelpers.sanitizeUrl({
str: url,
allowNoProtocol: false,
});
if (sanitizedUrl !== undefined) {
electron.shell.openExternal(url);
}
},
clearBrowserHistory() {
electron.remote.getCurrentWebContents().clearHistory();
},
getAppVersion() {
return electron.remote.app.getVersion();
},
setBadge(str) {
const dock = electron.remote.app.dock;
if (dock) {
dock.setBadge(str);
return;
}
const win = electron.remote.getCurrentWindow();
if (win.setOverlayIcon) {
if (str === "") {
win.setOverlayIcon(null, "");
return;
}
const canvas = document.createElement("canvas");
canvas.width = 16 * window.devicePixelRatio;
canvas.height = 16 * window.devicePixelRatio;
const ctx = canvas.getContext("2d");
if (!ctx) {
return;
}
const scale = 18 / 20;
const centerX = canvas.width / 2 / scale;
const centerY = canvas.height / 2 / scale;
const radius = (canvas.width / 2) * scale * scale;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = "rgba(247,94,79,0.95)";
ctx.fill();
ctx.font = 9 * scale * window.devicePixelRatio + "px sans-serif";
ctx.fillStyle = "white";
ctx.textAlign = "center";
ctx.fillText(str, centerX, centerY + 3.5 * scale * window.devicePixelRatio);
const pngData = electron.remote.nativeImage
.createFromDataURL(canvas.toDataURL("image/png"))
.toPNG();
const img = electron.remote.nativeImage.createFromBuffer(pngData, {
scaleFactor: window.devicePixelRatio,
});
win.setOverlayIcon(img, `${str} unread notifications`);
}
},
windowFocus: {
addListener(fn) {
electron.remote.app.addListener("browser-window-focus", fn);
},
removeListener(fn) {
electron.remote.app.removeListener("browser-window-focus", fn);
},
},
fullscreen: {
get() {
const window = electron.remote.getCurrentWindow();
return window && window.isFullScreen();
},
addListener(fn) {
notionIpc.receiveNotionFromIndex.addListener("notion:full-screen-changed", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromIndex.removeListener("notion:full-screen-changed", fn);
},
},
inPageSearch: {
start(isPeekView) {
notionIpc.sendNotionToIndex("search:start", isPeekView);
},
stop() {
notionIpc.sendNotionToIndex("search:stop");
},
started: {
addListener(fn) {
notionIpc.receiveNotionFromIndex.addListener("search:started", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromIndex.removeListener("search:started", fn);
},
},
stopped: {
addListener(fn) {
notionIpc.receiveNotionFromIndex.addListener("search:stopped", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromIndex.removeListener("search:stopped", fn);
},
},
},
zoom: {
set(scale) {
notionIpc.sendNotionToIndex("zoom", scale);
},
get() {
return electron.webFrame.getZoomFactor();
},
},
loadSpellcheck: () => {
try {
const cld = require("cld");
electronApi.cld = {
detect: (text, fn) => {
cld.detect(text, fn);
},
};
}
catch (error) {
console.error("Failed to load spellchecker", error);
}
},
setSpellCheckerLanguages: languages => {
const session = electron.remote.getCurrentWebContents().session;
session.setSpellCheckerLanguages(languages.filter(language => session.availableSpellCheckerLanguages.includes(language)));
},
contextMenu: {
addListener: fn => {
electron.remote.getCurrentWebContents().addListener("context-menu", fn);
},
removeListener: fn => {
electron.remote.getCurrentWebContents().removeListener("context-menu", fn);
},
},
replaceMisspelling: (word) => {
electron.remote.getCurrentWebContents().replaceMisspelling(word);
},
cut: () => {
electron.remote.getCurrentWebContents().cut();
},
copy: () => {
electron.remote.getCurrentWebContents().copy();
},
paste: () => {
electron.remote.getCurrentWebContents().paste();
},
inspectElement: (x, y) => {
electron.remote.getCurrentWebContents().inspectElement(x, y);
},
copyText: (text) => {
electron.clipboard.writeText(text);
},
copyImage: (src) => {
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
let img = new Image();
img.crossOrigin = "Anonymous";
img.onload = () => {
canvas.height = img.height;
canvas.width = img.width;
if (ctx) {
ctx.drawImage(img, 0, 0);
let dataURL = canvas.toDataURL("image/png");
electron.clipboard.writeImage(electron.nativeImage.createFromDataURL(dataURL));
}
};
img.src = src;
},
openDevTools: () => {
electron.remote.getCurrentWebContents().openDevTools();
},
setWindowTitle: title => {
const browserWindow = electron.remote.getCurrentWindow();
if (browserWindow.getTitle() !== title) {
browserWindow.setTitle(title);
}
},
toggleMaximized: () => {
const win = electron.remote.getCurrentWindow();
if (win.isMaximized()) {
win.unmaximize();
}
else {
win.maximize();
}
},
checkForUpdates() {
notionIpc.sendToMain("notion:check-for-updates");
},
updateReady: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:update-ready", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:update-ready", fn);
},
},
installUpdate() {
notionIpc.sendToMain("notion:install-update");
},
updateError: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:update-error", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:update-error", fn);
},
},
updateChecking: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:checking-for-update", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:checking-for-update", fn);
},
},
updateAvailable: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:update-available", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:update-available", fn);
},
},
updateProgress: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:update-progress", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:update-progress", fn);
},
},
updateNotAvailable: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:update-not-available", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:update-not-available", fn);
},
},
checkForAppUpdates() {
notionIpc.sendToMain("notion:check-for-app-updates");
},
appUpdateReady: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-ready", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-ready", fn);
},
},
appUpdateError: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-error", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-error", fn);
},
},
appUpdateChecking: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:checking-for-app-update", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:checking-for-app-update", fn);
},
},
appUpdateAvailable: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-available", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-available", fn);
},
},
appUpdateProgress: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-progress", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-progress", fn);
},
},
appUpdateNotAvailable: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-not-available", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-not-available", fn);
},
},
appUpdateFinished: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:app-update-finished", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:app-update-finished", fn);
},
},
getSubstitutions() {
return ((electron.remote.systemPreferences.getUserDefault &&
electron.remote.systemPreferences.getUserDefault("NSUserDictionaryReplacementItems", "array")) ||
[]);
},
isMainWindow() {
const currentWindow = electron.remote.getCurrentWindow();
const focusedWindow = electron.remote.BrowserWindow.getFocusedWindow();
if (focusedWindow) {
return focusedWindow.id === currentWindow.id;
}
const firstWindow = electron.remote.BrowserWindow.getAllWindows()[0];
return firstWindow && firstWindow.id === currentWindow.id;
},
setTheme(theme) {
notionIpc.sendNotionToIndex("search:set-theme", theme);
},
newWindow: {
addListener: fn => {
electron.remote.getCurrentWebContents().addListener("new-window", fn);
},
removeListener: fn => {
electron.remote.getCurrentWebContents().removeListener("new-window", fn);
},
},
openOauthPopup: async (args) => {
notionIpc.sendToMain("notion:create-popup", args);
return new Promise(resolve => {
const handlePopupCallback = (sender, url) => {
notionIpc.receiveNotionFromMain.removeListener("notion:popup-callback", handlePopupCallback);
resolve(url);
};
notionIpc.receiveNotionFromMain.addListener("notion:popup-callback", handlePopupCallback);
});
},
openGoogleDrivePickerPopup: async (args) => {
notionIpc.sendToMain("notion:create-google-drive-picker", args);
return new Promise(resolve => {
const handlePopupCallback = (sender, file) => {
notionIpc.receiveNotionFromMain.removeListener("notion:google-drive-picker-callback", handlePopupCallback);
resolve(file);
};
notionIpc.receiveNotionFromMain.addListener("notion:google-drive-picker-callback", handlePopupCallback);
});
},
getCookie: (cookieName) => {
notionIpc.sendToMain("notion:get-cookie", cookieName);
return new Promise(resolve => {
const handleCallback = (sender, result) => {
notionIpc.receiveNotionFromMain.removeListener("notion:get-cookie-response", handleCallback);
resolve(result);
};
notionIpc.receiveNotionFromMain.addListener("notion:get-cookie-response", handleCallback);
});
},
setLogglyData: data => {
notionIpc.sendToMain("notion:set-loggly-data", data);
},
clearCookies: () => {
notionIpc.sendToMain("notion:clear-cookies");
},
resetAppCache() {
notionIpc.sendToMain("notion:reset-app-cache");
},
appUpdateReload: {
emit: info => {
notionIpc.broadcast.emit("notion:app-update-reload", info);
},
addListener(fn) {
notionIpc.broadcast.addListener("notion:app-update-reload", fn);
},
removeListener(fn) {
notionIpc.broadcast.removeListener("notion:app-update-reload", fn);
},
},
getAppPath() {
return electron.remote.app.getAppPath();
},
clearAllCookies: () => {
notionIpc.sendToMain("notion:clear-all-cookies");
},
downloadUrl(url) {
electron.remote.getCurrentWebContents().downloadURL(url);
},
onNavigate: {
addListener(fn) {
notionIpc.receiveNotionFromMain.addListener("notion:navigate-to-url", fn);
},
removeListener(fn) {
notionIpc.receiveNotionFromMain.removeListener("notion:navigate-to-url", fn);
},
},
};
window["__electronApi"] = electronApi;
window["__isElectron"] = true;
window["__platform"] = process.platform;
//# sourceMappingURL=preload.js.map