Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Updated toast style.
Updated electron loadURL functionality.
  • Loading branch information
imolorhe committed Sep 29, 2018
1 parent 1d0499e commit e621cff
Show file tree
Hide file tree
Showing 5 changed files with 2,080 additions and 2,005 deletions.
5 changes: 5 additions & 0 deletions electron/main.js
Expand Up @@ -3,6 +3,11 @@ const isDev = require('electron-is-dev');
const { setupAutoUpdates } = require('./updates');
const { instance, createWindow, getInstance } = require('./window');

// require('electron-debug')();
// try {
// require('electron-reloader')(module);
// } catch (err) {}

// Default Squirrel.Windows event handler for your Electron apps.
// if (require('electron-squirrel-startup')) return; // Not required when using NSIS target

Expand Down
63 changes: 42 additions & 21 deletions electron/window.js
@@ -1,4 +1,4 @@
const { BrowserWindow, protocol, ipcMain, session } = require('electron');
const { BrowserWindow, protocol, ipcMain, session, app } = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs');
Expand Down Expand Up @@ -34,33 +34,55 @@ const actions = {

const createWindow = () => {

const getFilePath = (filePath) => {
return new Promise((resolve, reject) => {

if (!filePath) {
return resolve();
}

console.log('checking stat..', filePath);
fs.stat(filePath, (err, stats) => {
if (err) {
return reject(err);
}
if (stats.isFile()) {
return resolve(filePath);
}

if (stats.isDirectory()) {
return resolve(getFilePath(path.join(filePath, 'index.html')));
}

return resolve();
});
});
};

/**
* Using a custom buffer protocol, instead of a file protocol because of restrictions with the file protocol.
*/
protocol.registerBufferProtocol('altair', (request, callback) => {
let url = request.url.substr(7);

// In windows, the url comes as altair://c/Users/Jackie/Documents/projects/altair/dist/index.html
// We also need to strip out the //c from the path
// TODO - Find a better way of handling this
if (process.platform === 'win32') {
url = request.url.substr(10);
}

// Maybe this could work?
// console.log('::>>', path.join(__dirname, '../dist', path.basename(request.url)));
const requestDirectory = path.resolve(app.getAppPath(), 'dist');
const filePath = path.join(requestDirectory, new url.URL(request.url).pathname);
const indexPath = path.join(requestDirectory, 'index.html');

fs.readFile(path.normalize(`${url}`), 'utf8', function (err, data) {
if (err) {
return console.log('Error loading file to buffer.', err);
getFilePath(filePath).then((filePath) => {
if (!filePath) {
filePath = indexPath;
}

// Load the data from the file into a buffer and pass it to the callback
// Using the mime package to get the mime type for the file, based on the file name
callback({ mimeType: mime.lookup(url), data: new Buffer(data) });
// console.log(data);
fs.readFile(filePath, 'utf8', function (err, data) {
if (err) {
return console.log('Error loading file to buffer.', err);
}

// Load the data from the file into a buffer and pass it to the callback
// Using the mime package to get the mime type for the file, based on the file name
callback({ mimeType: mime.lookup(filePath), data: new Buffer(data) });
});
});
// callback({path: path.normalize(`${__dirname}/${url}`)})
}, (error) => {
if (error) console.error('Failed to register protocol')
});
Expand All @@ -80,11 +102,10 @@ const createWindow = () => {

// and load the index.html of the app.
instance.loadURL(url.format({
pathname: path.join(__dirname, '../dist/index.html'),
pathname: '-',
protocol: 'altair:',
slashes: true
}));
// instance.loadURL('altair://' + __dirname + '/../dist/index.html');

// Open the DevTools.
// instance.webContents.openDevTools();
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -73,10 +73,12 @@
"dexie": "^2.0.4",
"downloadjs": "^1.4.7",
"electron-compile": "^6.4.1",
"electron-debug": "^2.0.0",
"electron-is-dev": "^1.0.0",
"electron-log": "^2.2.11",
"electron-squirrel-startup": "^1.0.0",
"electron-updater": "^3.1.1",
"electron-util": "^0.9.1",
"express": "^4.16.2",
"file-dialog": "^0.0.7",
"graphql": "^0.13.2",
Expand Down Expand Up @@ -112,8 +114,10 @@
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"codelyzer": "^4.0.2",
"devtron": "^1.4.0",
"electron-builder": "^20.27.1",
"electron-prebuilt-compile": "^3.0.0",
"electron-reloader": "^0.2.0",
"jasmine-core": "^3.1.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.0.0",
Expand Down
18 changes: 16 additions & 2 deletions src/scss/components/_alert.scss
Expand Up @@ -4,12 +4,26 @@
#toast-container {
& > .toast {
line-height: 1.4;
border-radius: 5px;
box-shadow: none;
border-radius: 2px;
background-position: 20px center;
padding: 15px 15px 15px 60px;
border-left: 5px solid white;
width: 100%;
max-width: 400px;

}
.toast-title {
line-height: 1.2;
text-transform: uppercase;
font-size: 13px;
font-size: 14px;
letter-spacing: .5px;
margin-bottom: 3px;
}
.toast-close-button {
font-weight: normal;
text-shadow: none;
transition: all .3s ease;
}
.toast-message {
font-size: 13px;
Expand Down

0 comments on commit e621cff

Please sign in to comment.