dotherightthing / focalpoint-multi-cropper

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

Add ability to restore session (at least folderIn and folderOut paths) #28

Closed dotherightthing closed 1 year ago

dotherightthing commented 1 year ago

Cookies would be ideal, but cannot get these to work with the file:// protocol.

See:

dotherightthing commented 1 year ago

Tried:

// main.js
const { app, net, protocol } = require('electron');

// tried with and without this:
protocol.registerSchemesAsPrivileged([ {
  scheme: 'file',
  privileges: {
    standard: true,
    secure: true
  }
} ]);

const createWindow = () => {
  ...
  mainWindow.loadURL('file:///Users/dan/Websites/crop-renamer/index.html'); // replaces mainWindow.loadFile('index.html');
};

app.whenReady().then(() => {
  protocol.handle('file', (request) => {
    console.log('file://' + request.url.substring(7));

    return net.fetch('file://' + request.url.substring(7));
  });

  ...

  createWindow();
});
// CrFile.selectFolder

const cookie = {
  url: 'file://index.html', // also tried file:///, file:///Users/dan/Websites/crop-renamer/, file:///Users/dan/Websites/crop-renamer/index.html, file:///Users/dan/Websites/crop-renamer
  name: 'test', // cookieName,
  value: 'test' // folderPath
};

session.defaultSession.cookies.set(cookie)
  .then(() => {
    console.log('cookie set');
  }, (error) => {
    console.log(error); // [Error: Cannot set cookie for current scheme]
  });
dotherightthing commented 1 year ago

Resolved by writing to a JSON file using https://cameronnokes.com/blog/how-to-store-user-data-in-electron/