Skip to content

Commit

Permalink
v1.2.5 - Fixes for user data path location, and by extension, the ima…
Browse files Browse the repository at this point in the history
…ge upload control type.
  • Loading branch information
marchantweb committed Sep 29, 2022
1 parent fc29f2e commit 1918fd6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mit-illuminations",
"version": "v1.2.4",
"version": "v1.2.5",
"private": true,
"description": "Illuminations by MIT - Turn P5 Code into Light Shows",
"author": "Sosolimited in collaboration with MIT",
Expand Down
9 changes: 6 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ function createWindow() {
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
preload: path.join(__dirname, 'preload.js')
preload: path.join(__dirname, 'preload.js'),
devTools: true,
additionalArguments: [userDataPath]
}
});

if (process.env.WEBPACK_DEV_SERVER_URL) {
splash.loadURL(`file://${__dirname}/bundled/splash.html`).catch(console.log);
win.loadURL(`${process.env.WEBPACK_DEV_SERVER_URL}?userDataPath=${encodeURIComponent(userDataPath)}`).catch(console.log);
win.loadURL(`${process.env.WEBPACK_DEV_SERVER_URL}`).catch(console.log);
win.webContents.openDevTools();
} else {
createProtocol('app');
splash.loadURL(`app://./splash.html`).catch(console.log);
win.loadURL(`app://./index.html?userDataPath=${encodeURIComponent(userDataPath)}`).catch(error => {
win.loadURL(`app://./index.html`).catch(error => {
throw new Error(error.message);
});
}
Expand Down
23 changes: 13 additions & 10 deletions src/components/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
</v-img>
<v-file-input
v-if="controlObj.type.toLowerCase() === 'image'"
:clearable="false"
:clearable="true"
accept=".png"
class="mx-3"
dense
prepend-icon="mdi-file-upload"
showsize
@change="copyAsset"
></v-file-input>

Expand Down Expand Up @@ -117,15 +118,17 @@ export default {
console.log(`[control] delete unused control ${this.controlObj.id}`)
},
copyAsset(src) {
const newId = nanoid(10)
const fse = window.fse
fse.copyAsset(src.path, newId)
// TODO: Make sure this emit happens *after* copyAsset completes.
setTimeout(
() =>
this.$emit('updateControlValue', `${newId}.png`, this.controlObj.id),
2000
);
console.log("Copy asset called.");
const newId = nanoid(10);
window.fse.copyAsset(src.path, newId).then((status) => {
if (status) {
setTimeout(() => {
this.$emit('updateControlValue', `${newId}.png`, this.controlObj.id);
}, 1000);
} else {
alert("This image was unable to be imported, please try again.");
}
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ControlForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default {
if (this.controlObj.type.toLowerCase() === 'color') {
return '#EC3131'
} else if (this.controlObj.type.toLowerCase() === 'image') {
return 'gray'
return 'gray.png'
} else {
return Math.round((this.controlObj.min + this.controlObj.max) / 30) || 0
}
Expand Down
26 changes: 14 additions & 12 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const dgram = require('dgram')
const electronStore = require('electron-store')
const fse = require('fs-extra')
const path = require('path')
const qs = require('querystring');

const kinetSocket = dgram.createSocket('udp4') // IPv4

Expand All @@ -17,10 +16,7 @@ const kinetSocket = dgram.createSocket('udp4') // IPv4
// Win: %APPDATA%/.local/share/mit-illuminations/config.json
// See https://issuehunt.io/r/sindresorhus/electron-store/issues/181.

// wes note: this is now being passed as a query string to the URL of this
// page (when loaded from the electron background process) -- this gets around
// the need to use IPC to look it up
const userDataPath = qs.decode(location.search.slice(1)).userDataPath;
const userDataPath = window.process.argv.slice(-1)[0];

/**
* Create the Electron Store
Expand All @@ -32,7 +28,7 @@ const estore = new electronStore({

window.dgram = {};
window.dgram.send = (buf, port, ip) => {
kinetSocket.send(buf, port, ip, function(error){
kinetSocket.send(buf, port, ip, function (error) {
if (error) {
console.log(error);
}
Expand All @@ -42,13 +38,19 @@ window.dgram.send = (buf, port, ip) => {
window.estore = estore;

window.fse = {};
window.fse.copyAsset = (src, id) => {
const ext = path.extname(src)
window.fse.copyAsset = async (src, id) => {
const ext = path.extname(src);
console.log(userDataPath, id, ext, src);
const dest = path.join(userDataPath, 'user_uploads', `${id}${ext}`);

fse.copy(src, dest, (err) => {
if (err) return console.error(err)
}).catch(console.log);
try {
await fse.copy(src, dest, (err) => {
if (err) return console.error(err)
});
return true;
} catch (error) {
console.error(error);
return false;
}
};


Expand Down

0 comments on commit 1918fd6

Please sign in to comment.