dotherightthing / focalpoint-multi-cropper

Add a focalpoint to an image and generate project-specific crops.
0 stars 0 forks source link

appDebugDir is a global rather than a class property #10

Closed dotherightthing closed 1 year ago

dotherightthing commented 1 year ago

Test 1

// preload.cjs

selectFolder: () => ipcRenderer.invoke('dialog:selectFolder'),

// main.cjs

app.whenReady().then(() => {
  const CrFileInstance = new CrFile({
    appDebugDir: "/Volumes/DanHDD4TB1/Don't Believe The Hype/2022.12.31 - 2023.01.08 - Wellington to Acheron, St James, Rainbow, to Wellington/Day 04 - 2023.01.03 - Aratere Valley to Acheron Campsite"
  });

  ipcMain.handle('dialog:selectFolder', CrFileInstance.handleSelectFolder);
});

// renderer.mjs

async function uiSelectFolder() {
  const data = await window.electronAPI.selectFolder();
  ...
}

// CrFile.cjs

/**
 * @function handleSelectFolder
 * @returns {object} folderData
 * @memberof CrFile
 */
async handleSelectFolder() {
  const { appDebugDir } = this;
  ...
}

Result: CrFileInstance cannot access this.appDebugDir

Test 2

// preload.cjs

selectFolder: () => ipcRenderer.invoke('dialog:selectFolder'),

// main.cjs

app.whenReady().then(() => {
  const CrFileInstance = new CrFile({
    appDebugDir: "/Volumes/DanHDD4TB1/Don't Believe The Hype/2022.12.31 - 2023.01.08 - Wellington to Acheron, St James, Rainbow, to Wellington/Day 04 - 2023.01.03 - Aratere Valley to Acheron Campsite"
  });

  ipcMain.handle('dialog:selectFolder', () => { CrFileInstance.handleSelectFolder(); });
});

// renderer.mjs

async function uiSelectFolder() {
  const data = await window.electronAPI.selectFolder();
  ...
}

// CrFile.cjs

/**
 * @function handleSelectFolder
 * @returns {object} folderData
 * @memberof CrFile
 */
async handleSelectFolder() {
  const { appDebugDir } = this;
  ...
}

Result: Data retrieved but nothing returned to window.electronAPI.selectFolder

Test 3

// preload.cjs

selectFolder: () => ipcRenderer.invoke('dialog:selectFolder'),

// main.cjs

app.whenReady().then(() => {
  // Use a global for appDebugDir
  ipcMain.handle('dialog:selectFolder', CrFile.handleSelectFolder);
});

// renderer.mjs

async function uiSelectFolder() {
  const data = await window.electronAPI.selectFolder();
  ...
}

// CrFile.cjs

async handleSelectFolder() {
 // appDebugDir is accessible as a global
  ...
}

Result: works

Test 4

// preload.cjs

contextBridge.exposeInMainWorld('electronAPI', {
  selectFolder: (data) => ipcRenderer.invoke('dialog:selectFolder', data), // pass data
});

// main.cjs

ipcMain.handle('dialog:selectFolder', CrFile.handleSelectFolder);

// renderer.mjs
// could also be in a class with global as a property instead
// as some of my classes are using this pattern

const appDebugDir = "/Volumes/DanHDD4TB1/Don't Believe The Hype/2022.12.31 - 2023.01.08 - Wellington to Acheron, St James, Rainbow, to Wellington/Day 04 - 2023.01.03 - Aratere Valley to Acheron Campsite";

async function uiSelectFolder() {
  const data = await window.electronAPI.selectFolder({
    appDebugDir
  }); // pass data

  ...
}

// CrFile.cjs
static async handleSelectFolder(data) {
  const { appDebugDir } = data; // receive data
  ...
}

Result: Works

dotherightthing commented 1 year ago

appDebugDir removed in 5832490263932b07c7d9158fbd45df1a8d062d06