Skip to content

Commit

Permalink
Fix issues with setting folder, creating screensaver
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinista committed Dec 11, 2017
1 parent 2baae97 commit 1200797
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "before-dawn",
"productName": "Before Dawn",
"version": "0.9.13",
"version": "0.9.14",
"description": "A desktop screensaver app using web technologies",
"author": "Colin Mitchell <[email protected]> (http://muffinlabs.com)",
"license": "MIT",
Expand Down Expand Up @@ -111,6 +111,7 @@
"sass-loader": "^6.0.6",
"sinon": "^4.0.2",
"spectron": "^3.7.2",
"spectron-fake-dialog": "^0.0.1",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"vue": "^2.5.6",
Expand Down
9 changes: 1 addition & 8 deletions src/lib/savers.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ var systemSource = function() {
}



/**
* set config var k to value v
*/
Expand Down Expand Up @@ -566,11 +565,6 @@ var writeSync = function() {
nconf.save();
};

var getTemplatePath = function() {
var d = systemSource();
return path.join(d, "__template");
};

var getConfig = function(cb) {
var configPath = path.join(baseDir, config_file);
fs.readFile(configPath, function(err, data) {
Expand All @@ -596,8 +590,7 @@ var getConfigSync = function() {
/**
* generate a screensaver template
*/
var generateScreensaver = function(opts) {
var src = getTemplatePath();
var generateScreensaver = function(src, opts) {
var destDir = getLocalSource();

var contents = fs.readdirSync(src);
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 22 additions & 3 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,19 @@ var openPrefsOnFirstLoad = function() {
};


var getSystemDir = function() {
if ( process.env.BEFORE_DAWN_SYSTEM_DIR !== undefined ) {
return process.env.BEFORE_DAWN_SYSTEM_DIR;
}

if ( global.IS_DEV ) {
return __dirname;
}

return app.getAppPath();
}


/**
* handle initial startup of app
*/
Expand Down Expand Up @@ -644,9 +657,14 @@ var bootApp = function() {
closeRunningScreensavers();
});


let saverOpts = {
base: global.basePath,
systemDir: getSystemDir()
};

log.info("Load config from " + global.basePath);
global.savers.init(global.basePath, function() {
log.info("Load config with", saverOpts);
global.savers.init(saverOpts, function() {
configLoaded = true;
updateStateManager();

Expand Down Expand Up @@ -1215,7 +1233,8 @@ ipcMain.on("set-autostart", (event, value) => {
// generate screensaver template with specified attributes
//
ipcMain.on("generate-screensaver", (event, args) => {
var data = global.savers.generateScreensaver(args);
var src = path.join(getSystemDir(), "__template");
var data = global.savers.generateScreensaver(src, args);
event.sender.send("generate-screensaver", data);

global.savers.reset();
Expand Down
17 changes: 16 additions & 1 deletion src/renderer/Prefs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
</b-tab>
<b-tab title="Preferences">
<div class="container-fluid">
<prefs-form :prefs="prefs"></prefs-form>
<prefs-form
:prefs="prefs"
v-on:localSourceChange="localSourceChange"></prefs-form>
</div>
<div class="container-fluid">
<button class="btn btn-large btn-positive reset-to-defaults"
Expand Down Expand Up @@ -287,8 +289,21 @@ export default {
}
}
);
},
localSourceChange(ls) {
console.log("hey", this.prefs);
console.log("set local source to", ls);
var tmp = {
localSource: ls
};
this.prefs = Object.assign(this.prefs, tmp);
// this.prefs.localSource = ls;
}
}
};
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/components/PrefsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
instead.
</small>
</div>

<!-- ' -->
<div class="form-check">
<label for="auto_start" class="form-check-label">
<input type="checkbox" class="form-check-input" v-model="prefs.auto_start" />
Expand Down Expand Up @@ -121,9 +121,11 @@ export default {
this.handlePathChoice );
},
handlePathChoice(result) {
if ( result !== undefined ) {
this.prefs.localSource = result[0];
}
this.$emit("localSourceChange", result[0]);
// blah this is weird
this.prefs.localSource = result[0];
document.querySelector("[name=localSource]").value = this.prefs.localSource;
}
}
};
Expand Down
12 changes: 8 additions & 4 deletions test/lib/savers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,16 @@ describe('Savers', function() {

describe('generateScreensaver', function() {
it('works', function(done) {

// this should be the path to our __template in the main app
var src = path.join(__dirname, "..", "..", "src", "main", "__template");
savers.init(workingDir, function() {
savers.setLocalSource(saversDir);
savers.generateScreensaver({
name:"New Screensaver"
});

savers.generateScreensaver(src,
{
name:"New Screensaver"
});

savers.listAll(function(data) {
assert.equal(4, data.length);
done();
Expand Down
17 changes: 17 additions & 0 deletions test/ui/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,21 @@ describe('Prefs', function() {
}).
then(() => done());
});

it('allows setting path via dialog', function(done) {
app.fakeDialog.mock([ { method: 'showOpenDialog', value: ['/not/a/real/path'] } ]);

app.client.waitUntilWindowLoaded().click("=Preferences").
then(() => app.client.click("button.pick")).
then(() => app.client.click("button.save")).
then(() => {
app.client.getWindowCount().should.eventually.equal(1)
}).
then(() => {
assert.equal("/not/a/real/path", helpers.savedConfig(workingDir).localSource);
}).
then(() => done());
});


});
6 changes: 6 additions & 0 deletions test/ui/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const tmp = require('tmp');
const path = require('path');
const fs = require('fs-extra');
const Application = require('spectron').Application;
const fakeDialog = require('spectron-fake-dialog');

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');

Expand Down Expand Up @@ -45,6 +47,10 @@ exports.application = function(workingDir) {
}
});

fakeDialog.apply(a);

a.fakeDialog = fakeDialog;

chaiAsPromised.transferPromiseness = a.transferPromiseness;

return a;
Expand Down
11 changes: 9 additions & 2 deletions webpack.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ let mainConfig = {
]
},
node: {
__dirname: false, //process.env.NODE_ENV !== 'production',
__filename: false // process.env.NODE_ENV !== 'production'
__dirname: false,
__filename: false
},
output: {
filename: '[name].js',
Expand Down Expand Up @@ -80,6 +80,13 @@ let mainConfig = {
ignore: ['.*']
}
]),
new CopyWebpackPlugin([
{
from: path.join(__dirname, 'src', 'main', '__template'),
to: path.join(outputDir, '__template'),
ignore: ['.*']
}
]),
new webpack.DefinePlugin({
'process.env.PACKAGE_VERSION': JSON.stringify(packageJSON.version)
}),
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7191,6 +7191,10 @@ spdy@^3.4.1:
select-hose "^2.0.0"
spdy-transport "^2.0.18"

spectron-fake-dialog@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/spectron-fake-dialog/-/spectron-fake-dialog-0.0.1.tgz#ffd5cfadcac64eb957340389f047529c4a68e23a"

spectron@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/spectron/-/spectron-3.7.2.tgz#86f41306a9b70ed6ee1500f7f7d3adc389afb446"
Expand Down

0 comments on commit 1200797

Please sign in to comment.