mirror of
https://github.com/heyman/heynote.git
synced 2025-03-09 12:31:40 +01:00
* Add window.heynote.mainProcess.on() and off() which can be used in browser land to communicate with the main process. Use these methods to remove intermediate onOpenSettings() and onSettingsChange() methods from window.heynote objects.
* Convert some pesky TypeScript to JavaScript
This commit is contained in:
parent
64740192bf
commit
9bf3a5dacc
@ -1,5 +1,5 @@
|
||||
const { app, Menu } = require("electron")
|
||||
import { OPEN_SETTINGS_EVENT } from "@/src/common/constants";
|
||||
import { OPEN_SETTINGS_EVENT, REDO_EVENT } from '@/src/common/constants'
|
||||
import { openAboutWindow } from "./about";
|
||||
import { quit } from "./index"
|
||||
|
||||
@ -63,7 +63,15 @@ const template = [
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
//{ role: 'undo' },
|
||||
{
|
||||
label: 'Redo',
|
||||
accelerator: 'CommandOrControl+Shift+z',
|
||||
click: (menuItem, window, event) => {
|
||||
window?.webContents.send(REDO_EVENT)
|
||||
console.log("redo")
|
||||
},
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
@ -2,10 +2,7 @@ const { contextBridge } = require('electron')
|
||||
import themeMode from "./theme-mode"
|
||||
import { isMac, isWindows, isLinux, isDev } from "../detect-platform"
|
||||
import { ipcRenderer } from "electron"
|
||||
import {
|
||||
WINDOW_CLOSE_EVENT,
|
||||
OPEN_SETTINGS_EVENT,
|
||||
SETTINGS_CHANGE_EVENT,
|
||||
import {
|
||||
UPDATE_AVAILABLE_EVENT,
|
||||
UPDATE_ERROR,
|
||||
UPDATE_DOWNLOAD_PROGRESS,
|
||||
@ -43,12 +40,14 @@ contextBridge.exposeInMainWorld("heynote", {
|
||||
})
|
||||
},
|
||||
|
||||
onWindowClose(callback) {
|
||||
ipcRenderer.on(WINDOW_CLOSE_EVENT, callback)
|
||||
},
|
||||
|
||||
onOpenSettings(callback) {
|
||||
ipcRenderer.on(OPEN_SETTINGS_EVENT, callback)
|
||||
mainProcess: {
|
||||
on(event, callback) {
|
||||
ipcRenderer.on(event, callback)
|
||||
},
|
||||
|
||||
off(event, callback) {
|
||||
ipcRenderer.off(event, callback)
|
||||
},
|
||||
},
|
||||
|
||||
buffer: {
|
||||
@ -125,10 +124,6 @@ contextBridge.exposeInMainWorld("heynote", {
|
||||
return await getCurrencyData()
|
||||
},
|
||||
|
||||
onSettingsChange(callback) {
|
||||
ipcRenderer.on(SETTINGS_CHANGE_EVENT, (event, settings) => callback(settings))
|
||||
},
|
||||
|
||||
autoUpdate: {
|
||||
callbacks(callbacks) {
|
||||
ipcRenderer.on(UPDATE_AVAILABLE_EVENT, (event, info) => callbacks?.updateAvailable(info))
|
||||
@ -163,7 +158,7 @@ contextBridge.exposeInMainWorld("heynote", {
|
||||
})
|
||||
|
||||
|
||||
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
||||
function domReady(condition=['complete', 'interactive']) {
|
||||
return new Promise((resolve) => {
|
||||
if (condition.includes(document.readyState)) {
|
||||
resolve(true)
|
||||
@ -178,12 +173,12 @@ function domReady(condition: DocumentReadyState[] = ['complete', 'interactive'])
|
||||
}
|
||||
|
||||
const safeDOM = {
|
||||
append(parent: HTMLElement, child: HTMLElement) {
|
||||
append(parent, child) {
|
||||
if (!Array.from(parent.children).find(e => e === child)) {
|
||||
return parent.appendChild(child)
|
||||
}
|
||||
},
|
||||
remove(parent: HTMLElement, child: HTMLElement) {
|
||||
remove(parent, child) {
|
||||
if (Array.from(parent.children).find(e => e === child)) {
|
||||
return parent.removeChild(child)
|
||||
}
|
@ -5,6 +5,8 @@
|
||||
import { useHeynoteStore } from "../stores/heynote-store"
|
||||
import { useErrorStore } from "../stores/error-store"
|
||||
|
||||
import { OPEN_SETTINGS_EVENT, SETTINGS_CHANGE_EVENT } from '@/src/common/constants'
|
||||
|
||||
import StatusBar from './StatusBar.vue'
|
||||
import Editor from './Editor.vue'
|
||||
import LanguageSelector from './LanguageSelector.vue'
|
||||
@ -52,10 +54,10 @@
|
||||
}
|
||||
onThemeChange(window.heynote.themeMode.initial)
|
||||
window.heynote.themeMode.onChange(onThemeChange)
|
||||
window.heynote.onSettingsChange((settings) => {
|
||||
window.heynote.mainProcess.on(SETTINGS_CHANGE_EVENT, (event, settings) => {
|
||||
this.settings = settings
|
||||
})
|
||||
window.heynote.onOpenSettings(() => {
|
||||
window.heynote.mainProcess.on(OPEN_SETTINGS_EVENT, () => {
|
||||
this.showSettings = true
|
||||
})
|
||||
},
|
||||
|
@ -6,6 +6,7 @@
|
||||
import { useErrorStore } from "../stores/error-store"
|
||||
import { useHeynoteStore } from "../stores/heynote-store.js"
|
||||
import { useEditorCacheStore } from "../stores/editor-cache"
|
||||
import { REDO_EVENT, WINDOW_CLOSE_EVENT } from '@/src/common/constants';
|
||||
|
||||
const NUM_EDITOR_INSTANCES = 5
|
||||
|
||||
@ -46,6 +47,7 @@
|
||||
return {
|
||||
syntaxTreeDebugContent: null,
|
||||
editor: null,
|
||||
onWindowClose: null,
|
||||
}
|
||||
},
|
||||
|
||||
@ -53,12 +55,13 @@
|
||||
this.loadBuffer(this.currentBufferPath)
|
||||
|
||||
// set up window close handler that will save the buffer and quit
|
||||
window.heynote.onWindowClose(() => {
|
||||
this.onWindowClose = () => {
|
||||
window.heynote.buffer.saveAndQuit([
|
||||
[this.editor.path, this.editor.getContent()],
|
||||
])
|
||||
})
|
||||
}
|
||||
|
||||
window.heynote.mainProcess.on(WINDOW_CLOSE_EVENT, this.onWindowClose)
|
||||
window.document.addEventListener("currenciesLoaded", this.onCurrenciesLoaded)
|
||||
|
||||
// if debugSyntaxTree prop is set, display syntax tree for debugging
|
||||
@ -82,6 +85,7 @@
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
window.heynote.mainProcess.off(WINDOW_CLOSE_EVENT, this.onWindowClose)
|
||||
window.document.removeEventListener("currenciesLoaded", this.onCurrenciesLoaded)
|
||||
},
|
||||
|
||||
|
@ -84,7 +84,7 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
{
|
||||
entry: 'electron/preload/index.ts',
|
||||
entry: 'electron/preload/index.js',
|
||||
onstart(options) {
|
||||
// Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
|
||||
// instead of restarting the entire Electron App.
|
||||
|
@ -64,6 +64,12 @@ class IpcRenderer {
|
||||
this.callbacks[event].push(callback)
|
||||
}
|
||||
|
||||
off(event, callback) {
|
||||
if (this.callbacks[event]) {
|
||||
this.callbacks[event] = this.callbacks[event].filter(cb => cb !== callback)
|
||||
}
|
||||
}
|
||||
|
||||
send(event, ...args) {
|
||||
if (this.callbacks[event]) {
|
||||
for (const callback of this.callbacks[event]) {
|
||||
@ -213,20 +219,18 @@ const Heynote = {
|
||||
},
|
||||
},
|
||||
|
||||
onWindowClose(callback) {
|
||||
//ipcRenderer.on(WINDOW_CLOSE_EVENT, callback)
|
||||
mainProcess: {
|
||||
on(event, callback) {
|
||||
ipcRenderer.on(event, callback)
|
||||
},
|
||||
|
||||
off(event, callback) {
|
||||
ipcRenderer.off(event, callback)
|
||||
},
|
||||
},
|
||||
|
||||
settings: initialSettings,
|
||||
|
||||
onOpenSettings(callback) {
|
||||
ipcRenderer.on(OPEN_SETTINGS_EVENT, callback)
|
||||
},
|
||||
|
||||
onSettingsChange(callback) {
|
||||
ipcRenderer.on(SETTINGS_CHANGE_EVENT, (event, settings) => callback(settings))
|
||||
},
|
||||
|
||||
setSettings(settings) {
|
||||
localStorage.setItem("settings", JSON.stringify(settings))
|
||||
ipcRenderer.send(SETTINGS_CHANGE_EVENT, settings)
|
||||
|
Loading…
Reference in New Issue
Block a user