Repository URL to install this package:
Version:
2.0.11-7 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const electron_1 = require("electron");
require("isomorphic-fetch");
require("./crashReporter");
require("./autoUpdater");
const systemMenu_1 = require("./systemMenu");
require("./security");
const schemeHandler_1 = require("./schemeHandler");
const createWindow_1 = require("./createWindow");
const createPopup_1 = require("./createPopup");
const createGoogleDrivePicker_1 = require("./createGoogleDrivePicker");
const config_1 = require("../config");
const notionIpc = require("../helpers/notionIpc");
const loggly_1 = require("../helpers/loggly");
const assetCache_1 = require("./assetCache");
const schemeHelpers = require("../shared/schemeHelpers");
const urlHelpers = require("../shared/urlHelpers");
const fs = require("fs");
const localizationHelper_1 = require("../helpers/localizationHelper");
const notion_intl_1 = require("notion-intl");
electron_1.dialog.showErrorBox = function (title, content) { };
function makeRelativeUrl(url) {
try {
new URL(url);
}
catch (error) {
return;
}
const fixedUrl = schemeHelpers.fixSchemeUrl({
url: url,
protocol: config_1.default.protocol,
baseUrl: config_1.default.baseURL,
});
const httpUrl = schemeHelpers.getHttpUrl({
schemeUrl: fixedUrl,
baseUrl: config_1.default.baseURL,
});
const relativeUrl = urlHelpers.removeBaseUrl(httpUrl);
return relativeUrl;
}
function handleActivate(relativeUrl) {
const allWindows = electron_1.BrowserWindow.getAllWindows();
if (allWindows.length === 1) {
const win = allWindows[0];
if (relativeUrl) {
win.webContents.loadURL(createWindow_1.getIndexUrl(relativeUrl));
}
win.focus();
}
else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);
win.focus();
}
}
async function handleReady() {
const locale = localizationHelper_1.getNotionLocaleFromElectronLocale(electron_1.app.getLocale());
const intl = localizationHelper_1.createIntlShape(locale);
const messages = notion_intl_1.defineMessages({
invalidInstallMessage: {
id: "desktopInstaller.invalidInstallDialog.title",
defaultMessage: "Invalid Install",
},
invalidInstallDetail: {
id: "desktopInstaller.invalidInstallDialog.message",
defaultMessage: "Your Notion application is not installed properly. You need to move your Notion app into your Applications folder.",
},
okButton: {
id: "desktopInstaller.invalidInstallDialog.okButton.label",
defaultMessage: "OK",
},
});
if (isOpenedFromNonWritableDirectory()) {
await electron_1.dialog.showMessageBox({
type: "error",
buttons: [intl.formatMessage(messages.okButton)],
message: intl.formatMessage(messages.invalidInstallMessage),
detail: [intl.formatMessage(messages.invalidInstallDetail)].join("\n"),
});
const helpUrl = locale === "ko-KR"
? "https://www.notion.so/fe244a58c73b4174a89effb4828b86c5"
: "https://www.notion.so/b2be23041a0b4b948aa675184abc9165";
await electron_1.shell.openExternal(helpUrl);
electron_1.app.quit();
return;
}
let relativeUrl;
if (process.platform === "linux") {
const { argv } = process;
const url = argv.find(arg => arg.startsWith(config_1.default.protocol + ":"));
if (url) {
relativeUrl = makeRelativeUrl(url);
}
}
startup(relativeUrl);
}
async function startup(relativeUrl) {
const locale = localizationHelper_1.getNotionLocaleFromElectronLocale(electron_1.app.getLocale());
systemMenu_1.setupSystemMenu(locale);
await schemeHandler_1.migrateCookies();
await assetCache_1.assetCache.initialize();
schemeHandler_1.registerUrlSchemeProxy();
handleActivate(relativeUrl);
}
electron_1.app.on("ready", handleReady);
electron_1.app.setAppUserModelId(config_1.default.desktopAppId);
electron_1.app.setAsDefaultProtocolClient(config_1.default.protocol);
electron_1.app.on("open-url", (event, url) => {
event.preventDefault();
const relativeUrl = makeRelativeUrl(url);
if (electron_1.app.isReady()) {
const focusedWindow = electron_1.BrowserWindow.getFocusedWindow();
const allWindows = electron_1.BrowserWindow.getAllWindows();
const targetWindow = focusedWindow || allWindows.length === 1 ? allWindows[0] : undefined;
if (targetWindow && relativeUrl) {
notionIpc.sendMainToNotionWindow(targetWindow, "notion:navigate-to-url", relativeUrl);
targetWindow.focus();
}
else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);
win.focus();
}
}
else {
electron_1.app.removeListener("ready", handleReady);
electron_1.app.on("ready", async () => startup(relativeUrl));
}
});
if (electron_1.app.requestSingleInstanceLock()) {
electron_1.app.on("second-instance", (event, argv, workingDirectory) => {
if (process.platform === "linux") {
const url = argv.find(arg => arg.startsWith(config_1.default.protocol + ":"));
const urlPath = url && makeRelativeUrl(url);
handleActivate(urlPath);
}
});
}
else {
electron_1.app.quit();
}
electron_1.app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
electron_1.app.quit();
}
});
electron_1.app.on("activate", () => {
if (electron_1.BrowserWindow.getAllWindows().length === 0) {
createWindow_1.createWindow();
}
});
notionIpc.receiveMainFromRenderer.addListener("notion:create-window", (event, urlPath) => {
createWindow_1.createWindow(urlPath);
});
notionIpc.receiveMainFromRenderer.addListener("notion:create-popup", (event, args) => {
createPopup_1.createPopup(args);
});
notionIpc.receiveMainFromRenderer.addListener("notion:create-google-drive-picker", (event, args) => {
createGoogleDrivePicker_1.createGoogleDrivePicker(args);
});
notionIpc.receiveMainFromRenderer.addListener("notion:broadcast", (event, args) => {
notionIpc.sendMainToNotion("notion:broadcast", args);
});
process.on("uncaughtException", error => {
loggly_1.loggly.log({
level: "error",
from: "main",
type: "uncaughtException",
error: error,
});
});
process.on("unhandledRejection", error => {
loggly_1.loggly.log({
level: "error",
from: "main",
type: "unhandledRejection",
error: error,
});
});
function isOpenedFromNonWritableDirectory() {
if (process.platform === "darwin") {
try {
fs.accessSync(electron_1.app.getPath("exe"), fs.constants.W_OK);
return false;
}
catch (error) {
return true;
}
}
return false;
}
//# sourceMappingURL=main.js.map
//notion-enhancer
require('notion-enhancer/pkg/loader.js')(__filename, exports);