Skip to content

Commit

Permalink
Merge pull request #118 from imolorhe/add-forge-config-file
Browse files Browse the repository at this point in the history
Add forge config file
  • Loading branch information
imolorhe committed Aug 14, 2017
2 parents bad50aa + 566521c commit b2107ce
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 107 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ build: off # We do not intend to build using MS Build

# Run build in after_test to generate artifacts
after_test:
- ps: (Get-Content .\dist\index.html) | ForEach-Object { $_ -replace '<base href="/">', '<base href="./">' } | Set-Content .\dist\index.html
- npm run make

deploy:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ script:
- ng lint
- if [[ "$TRAVIS_OS_NAME" = "linux" ]]; then karma start karma.conf.js --single-run; fi
before_deploy:
- npm run make
- npm run build-electron
deploy:
provider: releases
api_key:
Expand Down
5 changes: 5 additions & 0 deletions electron/fix-base-path-windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

OLD_BASE='<base href="/">'
NEW_BASE='<base href="./">'
sed -i '' "s|$OLD_BASE|$NEW_BASE|g" .\dist\index.html
131 changes: 72 additions & 59 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,68 @@ let win

function createWindow () {

// TODO - Use the altair protocol to replace the file protocol
protocol.registerBufferProtocol('altair', (request, callback) => {
const url = request.url.substr(7);
fs.readFile(path.normalize(`${url}`), '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(url), data: new Buffer(data) });
// console.log(data);
});
// callback({path: path.normalize(`${__dirname}/${url}`)})
}, (error) => {
if (error) console.error('Failed to register protocol')
});
/**
* 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);
}

// Create the browser window.
win = new BrowserWindow({
width: 1280,
height: 800,
titleBarStyle: 'hidden-inset'
});
// Maybe this could work?
// console.log('::>>', path.join(__dirname, '../dist', path.basename(request.url)));

// Populate the application menu
createMenu();

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

// Open the DevTools.
// win.webContents.openDevTools()

// Prevent the app from navigating away from the app
win.webContents.on('will-navigate', (e, url) => e.preventDefault());

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
})
fs.readFile(path.normalize(`${url}`), '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(url), data: new Buffer(data) });
// console.log(data);
});
// callback({path: path.normalize(`${__dirname}/${url}`)})
}, (error) => {
if (error) console.error('Failed to register protocol')
});

// Create the browser window.
win = new BrowserWindow({
width: 1280,
height: 800,
// titleBarStyle: 'hidden-inset'
});

// Populate the application menu
createMenu();

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

// Open the DevTools.
// win.webContents.openDevTools()

// Prevent the app from navigating away from the app
win.webContents.on('will-navigate', (e, url) => e.preventDefault());

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
})
}

function createMenu () {
Expand Down Expand Up @@ -136,24 +149,24 @@ protocol.registerStandardSchemes(['altair']);
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
});

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
59 changes: 59 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
make_targets: {
win32: [
'squirrel'
],
darwin: [
'zip'
],
linux: [
'deb',
'rpm'
]
},
electronPackagerConfig: {
asar: true,
quiet: true,
protocol: 'altair://',
protocolName: 'Altair GraphQL Client File',
icon: './electron/logo',
prune: true,
// "ignore": [
// "idea",
// "bin",
// "chrome-ext-files",
// "docs",
// "e2e",
// "src"
// ],
ignore: (path) => {
const tests = [
// Ignore git directory
() => /^\/\.git\/.*/g,
// Ignore idea directory
() => /^\/\.idea\/.*/g,
// Ignore root dev FileDescription
() => /^\/(bin|chrome-ext-files|docs|e2e|src|test|.cert.pfx|.editorconfig|.eslintignore|.eslintrc|.gitignore|.travis.yml|appveyor.yml|circle.yml|CONTRIBUTING.md|Gruntfile.js|gulpfile.js|ISSUE_TEMPLATE.md|LICENSE|README.md)(\/|$)/g, // eslint-disable-line
];
for (let i = 0; i < tests.length; i++) {
if (tests[i]().test(path)) {
return true;
}
}
return false;
},
},
electronWinstallerConfig: {
name: 'Altair',
setupIcon: './electron/logo.ico'
},
electronInstallerDebian: {},
electronInstallerRedhat: {},
github_repository: {
owner: 'imolorhe',
name: 'altair'
},
windowsStoreConfig: {
packageName: 'Altair GraphQL Client'
}
};
62 changes: 18 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
"author": "[email protected]",
"description": "The best graphQL client you will ever need",
"homepage": "https://imolorhe.github.io/altair/",
"keywords": ["graphql", "altair", "wysiwyg", "editor", "client"],
"keywords": [
"graphql",
"altair",
"wysiwyg",
"editor",
"client"
],
"main": "electron/main.js",
"scripts": {
"ng": "ng",
Expand Down Expand Up @@ -83,48 +89,16 @@
"typescript": "~2.2.0"
},
"config": {
"forge": {
"make_targets": {
"win32": [
"squirrel"
],
"darwin": [
"zip"
],
"linux": [
"deb",
"rpm"
]
},
"electronPackagerConfig": {
"asar": true,
"quiet": true,
"protocol": "altair://",
"protocolName": "Altair GraphQL Client File",
"icon": "./electron/logo",
"prune": true,
"ignore": [
"idea",
"bin",
"chrome-ext-files",
"docs",
"e2e",
"src"
]
},
"electronWinstallerConfig": {
"name": "Altair",
"setupIcon": "./electron/logo.ico"
},
"electronInstallerDebian": {},
"electronInstallerRedhat": {},
"github_repository": {
"owner": "imolorhe",
"name": "altair"
},
"windowsStoreConfig": {
"packageName": "Altair GraphQL Client"
}
}
"forge": "./forge.config.js"
},
"directories": {
"doc": "docs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/imolorhe/altair.git"
},
"bugs": {
"url": "https://github.com/imolorhe/altair/issues"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="app-window-switcher-container">
<div class="app-window-switcher-electron-stub" *ngIf="isElectron">
<div class="app-window-switcher-input">&nbsp;</div>
</div>
<!--<div class="app-window-switcher-electron-stub" *ngIf="isElectron">-->
<!--<div class="app-window-switcher-input">&nbsp;</div>-->
<!--</div>-->
<!--<div class="app-window-switcher active">
window 1
</div>-->
Expand Down

0 comments on commit b2107ce

Please sign in to comment.