Closed Zaeche closed 6 years ago
Oh you're right! I've never implemented something like this before. Have you managed this with an electron app before?
Ah, no, I've never built an Electron app before, haha ... ha ...
That said, I have managed to pick up on the generalities of Electron since I posted this, and I've been messing around with the code to see how the various pieces fit together.
I did come across a suggested fix elsewhere, something along the lines of creating a open-file event that funnels the file-path after the app is ready (so afterapp.on('ready', () =>
). But this (from what I understand) is a main.js
t thing.
With Left, you're handling file read-write operations solely within the source.js
file--so it might just be a matter of digging into it and checking why the path isn't communicated properly. I feel like the logic is there but it might not be triggering for whatever reason.
I think I found a way to make it work actually, I will push a new build in a few. I'd like it if you could give it a try :)
Ooh, for sure. I'll keep an eye out!
Howdy - any updates to this? if not, I'd also take a shwing
Go for it :) What platform are you using?
MacOS, high sierra - I had the same issue so I hope I can get it done, although I don't have experience with electron app. But that is what the internet is for!
That's the spirit! I'm fixing some Dotgrid at the moment, but I'm available if you have any question or want to run some stuff by me :)
@neauoire I actually am facing an issue loading themes by dragging them onto Left.app
on macOS. I believe this is related.
@Axel-Jacobsen Any progress on this? I'm here to help if needed!
Are you saying that dragging themes onto Left doesn't work for you?
Yes that's correct. Maybe I'm doing it incorrectly? I'll investigate further tonight. I tried adding the battlestation and it didn't seem to change anything. I'll try with a more colorful theme tonight.
What should be that greenish color in Left when battlestation is applied?
Battlestation is the default Left theme.
On Feb 10, 2018, at 8:46 AM, Angel J Piscola notifications@github.com wrote:
Yes that's correct. Maybe I'm doing it incorrectly? I'll investigate further tonight. I tried adding the battlestation and it didn't seem to change anything. I'll try with a more colorful theme tonight.
What should be that greenish color in Left when battlestation is applied?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/hundredrabbits/Left/issues/34#issuecomment-364542546, or mute the thread https://github.com/notifications/unsubscribe-auth/ABY2buvFtpTGIwIIW3-BRwO1ksAHeYViks5tTKCCgaJpZM4QS02c.
Haha whoops! I'll test with a different theme tonight. This is a good candidate for a docs change :)
I got it to work by unzipping the theme before dragging it (on windows).
Can't test macOS tonight, will do so tomorrow
Hello again folks! I've been chipping away at the ElectronJS boulder when I've had the time and I've slowly come to the point where I think I've almost got the open-with stuff working in Left? Almost.
From what I've seen online, what I have working in a CLI setting ought to carry over after packaging too (but naturally it's not).
I've also run into some conflicts when packaging with a couple of modules which frustrates me, (especially tmp since I was using that to handle zero argv cases in my tests), but these are easily circumvented.
A quick sampling of the code below. I added this inside app.on("ready", () => in main.js
const fs = require('fs'); // put this all the way at the top
const {webContents} = require('electron'); // put this all the way at the top
if (process.argv.length < 3) { //add copy to packaged dir + replace with tmp stuff when module works...
var file_path = __dirname + "/LICENSE.md";
} else {
var file_path = fs.realpathSync(process.argv[2],[]);
}
fs.readFile(file_path, 'utf8', function(err, data) {
if (err) throw err;
preloaded_data = data;
console.log(data); //DEBUG
console.log("PATH" + file_path); //DEBUG
})
app.win.webContents.on('did-finish-load', () => {
app.win.webContents.send('file_contents', preloaded_data)
})
And this to index.html:
require('electron').ipcRenderer.on('file_contents', (event, data) => {
left.write_to_left(data);
})
_Quick note: the 'write_toleft' function is simply a call to left.load(path) inside left.js.
I thought I'd throw my progress out there and see if I can't get some help with this. I'm currently stuck at getting the file_path when opening a file with a packaged version of Left--unfortunately, it currently just defaults to the zero argument handler I've set up above.
I believe this might be an OS-specfiic quirk but I haven't been able to track down a solution so far that works.
There are some other--minor--foibles which I'll tackle at some other time.
Using Nodejs + Windows 10 (64-bit). Making use of the latest electron-packager to package.
Let me try on OSX :)
This works on Windows (although the "Open With" menu says "Electron" instead of "Left", not sure how to fix it):
// index.html
const remote = require('electron').remote;
var left = new Left(); left.start();
if (remote.process.argv.length > 1) {
left.project.add(remote.process.argv[1]);
}
Thanks @JakubValtar! That did it for me :)
It's part of the release version now :)
Haha, I noticed :) I was going to run a quick build but it was quicker to just pull the latest release!
As this has solved my specific request, I'm going to consider this done and close the issue 👌
I think this is a success, well done everyone :) 🥇
While the app wasn't running, I tried setting Left as the default app for my .txt files, but it seems this doesn't work. Even dragging and dropping the text-file on top of the Left executable doesn't communicate the text file's path to the app. It loads the last file opened by either a) dragging and dropping into the window b) loaded via ctrl+open when Left was actually running.
I don't know if this is an issue that's particularly critical but from the scant reading I've done on the issue here for instance it seems this should just be baked into the open-file event. It also appears to be an issue on Macs, though I haven't been able to confirm it on Windows.
I'm trying to see if I can mend this on my own, but I haven't been able to crack precisely what's wrong so far (my lack of experience with this general framework notwithstanding).
Is there a fix for this I've overlooked? Alternatively, if I can be set on the right path, I wouldn't mind trying to sort this out on my own.