~dricottone/noticable

4b97a2063521d8141db21bede185d4b71ef8e21e — Dominic Ricottone 3 years ago 1dfbf68
Styling updates and removing dependencies

 + Resize actually does work now
 + Custom menu bar
 + Refactored out electron-localshortcut
5 files changed, 120 insertions(+), 146 deletions(-)

M Makefile
M main.js
M package-lock.json
M package.json
M renderer.js
M Makefile => Makefile +1 -1
@@ 5,7 5,7 @@ clean:
	rm node_modules/* -rf

build: clean
	npm install monaco-editor electron-localshortcut jquery markdown-it github-markdown-css
	npm install monaco-editor jquery markdown-it github-markdown-css
	npm install --save-dev electron electron-builder

build-windows: build

M main.js => main.js +101 -22
@@ 4,14 4,112 @@ function debug(message) {
}

// constants
const { app, BrowserWindow, ipcMain, dialog } = require("electron");
const shortcut = require("electron-localshortcut");
const { app, BrowserWindow, ipcMain, dialog, shell, Menu } = require("electron");
const os = require("os");
const path = require("path");
let win;

// configuration
const notesDir = path.join(os.homedir(), "notes");

// manu
const template = [
  {
    label: "File",
    submenu: [
      {
        label: "Save and Render",
        accelerator: "CmdOrCtrl+S",
        click: () => {
          win.webContents.send("key-render-markdown", "");
        }
      },
      {
        label: "Save",
        accelerator: "CmdOrCtrl+Shift+S",
        click: () => {
          win.webContents.send("key-save-text", "");
        }
      },
      { type: "separator" },
      {
        label: "Show Notes Directory",
        click: async () => {
          await shell.openPath(notesDir);
        }
      },
      {
        label: "Show Installation Directory",
        click: async () => {
          await shell.openPath(app.getAppPath());
        }
      },
      { type: "separator" },
      { role: "quit" }
    ]
  },
  {
    label: "Edit",
    submenu: [
      { role: "undo" },
      { role: "redo" },
      { type: "separator" },
      { role: "cut" },
      { role: "copy" },
      { role: "paste" },
      { role: "delete" },
      { type: "separator" },
      { role: "selectAll" }
    ]
  },
  {
    label: "View",
    submenu: [
      {
        label: "Focus Editor Mode",
        accelerator: "CmdOrCtrl+E",
        click: () => {
          win.webContents.send("key-focus-editor", "");
        }
      },
      { type: "separator" },
      { role: "reload" },
      { role: "forceReload" },
      { role: "toggleDevTools" },
      { type: "separator" },
      { role: "resetZoom" },
      { role: "zoomIn" },
      { role: "zoomOut" },
      { type: "separator" },
      { role: "togglefullscreen" },
    ]
  },
  {
    label: "Window",
    submenu: [
      { role: "minimize" }
    ]
  },
  {
    label: "Help",
    submenu: [
      {
        label: "About",
        click: async () => {
          await shell.openExternal("https://github.com/dricottone/noticable");
        }
      },
      {
        label: "Report Bugs",
        click: async () => {
          await shell.openExternal("https://github.com/dricottone/noticable/issues");
        }
      }
    ]
  }
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));

// messaging
function postFileName(window, event) {
  dialog.showSaveDialog(window, {


@@ 33,8 131,7 @@ function postFileName(window, event) {
}

// utilities
let win;
function createWindow() {
function initializeWindow() {
  win = new BrowserWindow({
    width: 800,
    height: 600,


@@ 46,10 143,6 @@ function createWindow() {
  });

  win.loadFile(path.join(__dirname, "index.html"));
}
function initializeWindow() {
  createWindow();
  registerShortCuts(win);

  ipcMain.on("request-local-filename", (event) => {
    debug("caught request for local filename");


@@ 60,20 153,6 @@ function initializeWindow() {
    win = null;
  });
};
function registerShortCuts(window) {
  shortcut.register(window, "CmdOrCtrl+E", () => {
    debug("keypress focus editor");
    window.webContents.send("key-focus-editor", "");
  });
  shortcut.register(window, "CmdOrCtrl+S", () => {
    debug("keypress save text and render markdown");
    window.webContents.send("key-render-markdown", "");
  });
  shortcut.register(window, "CmdOrCtrl+Shift+S", () => {
    debug("keypress save text");
    window.webContents.send("key-save-text", "");
  });
}

// app event loop
app.on("ready", initializeWindow);

M package-lock.json => package-lock.json +15 -118
@@ 1,23 1,20 @@
{
  "name": "noticable",
  "version": "0.0.3",
  "version": "0.0.4",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "": {
      "version": "0.0.3",
      "version": "0.0.4",
      "license": "GPL-3.0",
      "dependencies": {
        "cash-dom": "^8.1.0",
        "electron-localshortcut": "^3.2.1",
        "electron-prompt": "^1.6.0",
        "github-markdown-css": "^4.0.0",
        "jquery": "^3.6.0",
        "markdown-it": "^12.2.0",
        "monaco-editor": "^0.26.1"
      },
      "devDependencies": {
        "electron": "^13.1.7",
        "electron": "^13.1.9",
        "electron-builder": "^22.11.7"
      }
    },


@@ 853,11 850,6 @@
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/cash-dom": {
      "version": "8.1.0",
      "resolved": "https://registry.npmjs.org/cash-dom/-/cash-dom-8.1.0.tgz",
      "integrity": "sha512-QTa50rFuPaX8klEDEbwLr+jVutwpvZEBQ0NpMMyng+je7gNe9Bz/JsOLHIG24tvNSSSIN/Q1QD0bnF6PQzWKHA=="
    },
    "node_modules/chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",


@@ 1122,6 1114,7 @@
      "version": "4.3.2",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
      "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
      "dev": true,
      "dependencies": {
        "ms": "2.1.2"
      },


@@ 1300,14 1293,6 @@
        "node": ">=8"
      }
    },
    "node_modules/doc-ready": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/doc-ready/-/doc-ready-1.0.4.tgz",
      "integrity": "sha1-N/U5GWnP+ZQwP9/vLl1QNX+BZNM=",
      "dependencies": {
        "eventie": "^1"
      }
    },
    "node_modules/dot-prop": {
      "version": "5.3.0",
      "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz",


@@ 1357,9 1342,9 @@
      }
    },
    "node_modules/electron": {
      "version": "13.1.7",
      "resolved": "https://registry.npmjs.org/electron/-/electron-13.1.7.tgz",
      "integrity": "sha512-sVfpP/0s6a82FK32LMuEe9L+aWZw15u3uYn9xUJArPjy4OZHteE6yM5871YCNXNiDnoCLQ5eqQWipiVgHsf8nQ==",
      "version": "13.1.9",
      "resolved": "https://registry.npmjs.org/electron/-/electron-13.1.9.tgz",
      "integrity": "sha512-By4Zb72XNQLrPb70BXdIW3NtEHFwybP5DIQjohnCxOYONq5vojuHjNcTuWnBgMvwQ2qwykk6Tw5EwF2Pt0CWjA==",
      "dev": true,
      "hasInstallScript": true,
      "dependencies": {


@@ 1436,30 1421,6 @@
        "node": ">= 10.0.0"
      }
    },
    "node_modules/electron-is-accelerator": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/electron-is-accelerator/-/electron-is-accelerator-0.1.2.tgz",
      "integrity": "sha1-UJ5RDCala1Xhf4Y6SwThEYRqsns="
    },
    "node_modules/electron-localshortcut": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/electron-localshortcut/-/electron-localshortcut-3.2.1.tgz",
      "integrity": "sha512-DWvhKv36GsdXKnaFFhEiK8kZZA+24/yFLgtTwJJHc7AFgDjNRIBJZ/jq62Y/dWv9E4ypYwrVWN2bVrCYw1uv7Q==",
      "dependencies": {
        "debug": "^4.0.1",
        "electron-is-accelerator": "^0.1.0",
        "keyboardevent-from-electron-accelerator": "^2.0.0",
        "keyboardevents-areequal": "^0.2.1"
      }
    },
    "node_modules/electron-prompt": {
      "version": "1.6.2",
      "resolved": "https://registry.npmjs.org/electron-prompt/-/electron-prompt-1.6.2.tgz",
      "integrity": "sha512-gC9ZpMopIgz1kW92J7UfsXarkLdPH2zhr77bnJFlDSduYjRlr9nEPm4ux1vyzJsO72AdOyvuPPIQB0j+gWsncQ==",
      "dependencies": {
        "doc-ready": "^1.0.4"
      }
    },
    "node_modules/electron-publish": {
      "version": "22.11.7",
      "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-22.11.7.tgz",


@@ 1590,11 1551,6 @@
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/eventie": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/eventie/-/eventie-1.0.6.tgz",
      "integrity": "sha1-1P/IsMK15JPCqhsiy+kY067nRDc="
    },
    "node_modules/extract-zip": {
      "version": "1.7.0",
      "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz",


@@ 2237,16 2193,6 @@
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/keyboardevent-from-electron-accelerator": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/keyboardevent-from-electron-accelerator/-/keyboardevent-from-electron-accelerator-2.0.0.tgz",
      "integrity": "sha512-iQcmNA0M4ETMNi0kG/q0h/43wZk7rMeKYrXP7sqKIJbHkTU8Koowgzv+ieR/vWJbOwxx5nDC3UnudZ0aLSu4VA=="
    },
    "node_modules/keyboardevents-areequal": {
      "version": "0.2.2",
      "resolved": "https://registry.npmjs.org/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz",
      "integrity": "sha512-Nv+Kr33T0mEjxR500q+I6IWisOQ0lK1GGOncV0kWE6n4KFmpcu7RUX5/2B0EUtX51Cb0HjZ9VJsSY3u4cBa0kw=="
    },
    "node_modules/keyv": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",


@@ 2416,7 2362,8 @@
    "node_modules/ms": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
      "dev": true
    },
    "node_modules/node-addon-api": {
      "version": "1.7.2",


@@ 4159,11 4106,6 @@
      "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==",
      "dev": true
    },
    "cash-dom": {
      "version": "8.1.0",
      "resolved": "https://registry.npmjs.org/cash-dom/-/cash-dom-8.1.0.tgz",
      "integrity": "sha512-QTa50rFuPaX8klEDEbwLr+jVutwpvZEBQ0NpMMyng+je7gNe9Bz/JsOLHIG24tvNSSSIN/Q1QD0bnF6PQzWKHA=="
    },
    "chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",


@@ 4377,6 4319,7 @@
      "version": "4.3.2",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
      "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
      "dev": true,
      "requires": {
        "ms": "2.1.2"
      }


@@ 4514,14 4457,6 @@
        "verror": "^1.10.0"
      }
    },
    "doc-ready": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/doc-ready/-/doc-ready-1.0.4.tgz",
      "integrity": "sha1-N/U5GWnP+ZQwP9/vLl1QNX+BZNM=",
      "requires": {
        "eventie": "^1"
      }
    },
    "dot-prop": {
      "version": "5.3.0",
      "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz",


@@ 4559,9 4494,9 @@
      }
    },
    "electron": {
      "version": "13.1.7",
      "resolved": "https://registry.npmjs.org/electron/-/electron-13.1.7.tgz",
      "integrity": "sha512-sVfpP/0s6a82FK32LMuEe9L+aWZw15u3uYn9xUJArPjy4OZHteE6yM5871YCNXNiDnoCLQ5eqQWipiVgHsf8nQ==",
      "version": "13.1.9",
      "resolved": "https://registry.npmjs.org/electron/-/electron-13.1.9.tgz",
      "integrity": "sha512-By4Zb72XNQLrPb70BXdIW3NtEHFwybP5DIQjohnCxOYONq5vojuHjNcTuWnBgMvwQ2qwykk6Tw5EwF2Pt0CWjA==",
      "dev": true,
      "requires": {
        "@electron/get": "^1.0.1",


@@ 4618,30 4553,6 @@
        }
      }
    },
    "electron-is-accelerator": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/electron-is-accelerator/-/electron-is-accelerator-0.1.2.tgz",
      "integrity": "sha1-UJ5RDCala1Xhf4Y6SwThEYRqsns="
    },
    "electron-localshortcut": {
      "version": "3.2.1",
      "resolved": "https://registry.npmjs.org/electron-localshortcut/-/electron-localshortcut-3.2.1.tgz",
      "integrity": "sha512-DWvhKv36GsdXKnaFFhEiK8kZZA+24/yFLgtTwJJHc7AFgDjNRIBJZ/jq62Y/dWv9E4ypYwrVWN2bVrCYw1uv7Q==",
      "requires": {
        "debug": "^4.0.1",
        "electron-is-accelerator": "^0.1.0",
        "keyboardevent-from-electron-accelerator": "^2.0.0",
        "keyboardevents-areequal": "^0.2.1"
      }
    },
    "electron-prompt": {
      "version": "1.6.2",
      "resolved": "https://registry.npmjs.org/electron-prompt/-/electron-prompt-1.6.2.tgz",
      "integrity": "sha512-gC9ZpMopIgz1kW92J7UfsXarkLdPH2zhr77bnJFlDSduYjRlr9nEPm4ux1vyzJsO72AdOyvuPPIQB0j+gWsncQ==",
      "requires": {
        "doc-ready": "^1.0.4"
      }
    },
    "electron-publish": {
      "version": "22.11.7",
      "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-22.11.7.tgz",


@@ 4745,11 4656,6 @@
      "dev": true,
      "optional": true
    },
    "eventie": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/eventie/-/eventie-1.0.6.tgz",
      "integrity": "sha1-1P/IsMK15JPCqhsiy+kY067nRDc="
    },
    "extract-zip": {
      "version": "1.7.0",
      "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz",


@@ 5248,16 5154,6 @@
        "graceful-fs": "^4.1.6"
      }
    },
    "keyboardevent-from-electron-accelerator": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/keyboardevent-from-electron-accelerator/-/keyboardevent-from-electron-accelerator-2.0.0.tgz",
      "integrity": "sha512-iQcmNA0M4ETMNi0kG/q0h/43wZk7rMeKYrXP7sqKIJbHkTU8Koowgzv+ieR/vWJbOwxx5nDC3UnudZ0aLSu4VA=="
    },
    "keyboardevents-areequal": {
      "version": "0.2.2",
      "resolved": "https://registry.npmjs.org/keyboardevents-areequal/-/keyboardevents-areequal-0.2.2.tgz",
      "integrity": "sha512-Nv+Kr33T0mEjxR500q+I6IWisOQ0lK1GGOncV0kWE6n4KFmpcu7RUX5/2B0EUtX51Cb0HjZ9VJsSY3u4cBa0kw=="
    },
    "keyv": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz",


@@ 5391,7 5287,8 @@
    "ms": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
      "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
      "dev": true
    },
    "node-addon-api": {
      "version": "1.7.2",

M package.json => package.json +2 -5
@@ 5,20 5,17 @@
    "name": "Dominic Ricottone",
    "email": "me@dominic-ricottone.com"
  },
  "version": "0.0.3",
  "version": "0.0.4",
  "license": "GPL-3.0",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "devDependencies": {
    "electron": "^13.1.7",
    "electron": "^13.1.9",
    "electron-builder": "^22.11.7"
  },
  "dependencies": {
    "cash-dom": "^8.1.0",
    "electron-localshortcut": "^3.2.1",
    "electron-prompt": "^1.6.0",
    "github-markdown-css": "^4.0.0",
    "jquery": "^3.6.0",
    "markdown-it": "^12.2.0",

M renderer.js => renderer.js +1 -0
@@ 7,6 7,7 @@ function debug(message) {
require.config({ paths: { vs: 'node_modules/monaco-editor/min/vs' } });
require(['vs/editor/editor.main'], function () {
  window.editor = monaco.editor.create(document.getElementById('container-editor'), {
    automaticLayout: true,
    language: 'markdown',
    minimap: {
      enabled: false