Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Klimas committed Jun 10, 2019
2 parents f655ec7 + 400749f commit 9da4474
Show file tree
Hide file tree
Showing 19 changed files with 334 additions and 141 deletions.
1 change: 1 addition & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"target": "zip"
},
"mac": {
"darkModeSupport": true,
"icon": "icons/app.icns",
"target": "dmg"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Twine",
"version": "2.3.1",
"version": "2.3.2",
"author": "Chris Klimas <[email protected]>",
"description": "a GUI for creating nonlinear stories",
"license": "GPL-3.0",
Expand Down
110 changes: 110 additions & 0 deletions src/common/launch-story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
In a web context, opens or re-uses a browser window/tab to display a playable
version of a story. In Electron, this publishes the content, then sends it to be
viewed in a browser using a temp file.
These are a single entrypoint so that individual UI parts don't have to worry
about which context they're in to dispatch a play or test.
*/

const {
getStoryPlayHtml,
getStoryProofingHtml,
getStoryTestHtml
} = require('./story-html');
const isElectron = require('../electron/is-electron');
const locale = require('../locale');

const windows = {};

function openWindow(url) {
if (windows[url]) {
try {
windows[url].focus();
windows[url].location.reload();
return;
} catch (e) {
/*
Fall through: try opening the window as usual. The problem probably
is that the window has since been closed by the user.
*/
}
}

windows[url] = window.open(url, url.replace(/\s/g, '_'));
}

module.exports = {
playStory(store, storyId) {
if (isElectron()) {
getStoryPlayHtml(store, storyId)
.then(html =>
window.twineElectron.ipcRenderer.send(
'open-with-temp-file',
html,
'.html'
)
)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);
});
} else {
openWindow(`#stories/${storyId}/play`);
}
},

proofStory(store, storyId) {
if (isElectron()) {
getStoryProofingHtml(store, storyId)
.then(html =>
window.twineElectron.ipcRenderer.send(
'open-with-temp-file',
html,
'.html'
)
)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);
});
} else {
openWindow(`#stories/${storyId}/proof`);
}
},

testStory(store, storyId, startPassageId) {
if (isElectron()) {
getStoryTestHtml(store, storyId, startPassageId)
.then(html =>
window.twineElectron.ipcRenderer.send(
'open-with-temp-file',
html,
'.html'
)
)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);
});
} else {
if (startPassageId) {
openWindow(`#stories/${storyId}/test/${startPassageId}`);
} else {
openWindow(`#stories/${storyId}/test`);
}
}
}
};
149 changes: 72 additions & 77 deletions src/common/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const LocaleView = require('../locale/view');
const StoryEditView = require('../story-edit-view');
const StoryListView = require('../story-list-view');
const WelcomeView = require('../welcome');
const { loadFormat } = require('../data/actions/story-format');
const { publishStoryWithFormat } = require('../data/publish');
const locale = require('../locale');
const { getStoryPlayHtml, getStoryProofingHtml, getStoryTestHtml } = require('./story-html');
const replaceUI = require('../ui/replace');
const store = require('../data/store');

Expand All @@ -33,30 +33,32 @@ TwineRouter.map({

'/stories': {
component: {
template: '<div><story-list ' +
template:
'<div><story-list ' +
':previously-editing="previouslyEditing"></story-list></div>',

components: { 'story-list': StoryListView },
components: {'story-list': StoryListView},

data() {
return {
previouslyEditing: this.$route.params ?
this.$route.params.previouslyEditing : ''
previouslyEditing: this.$route.params
? this.$route.params.previouslyEditing
: ''
};
},
}
}
},

'/stories/:id': {
component: {
template: '<div><story-edit :story-id="id"></story-edit></div>',

components: { 'story-edit': StoryEditView },
components: {'story-edit': StoryEditView},

data() {
return { id: this.$route.params.id };
return {id: this.$route.params.id};
}
},
}
},

/*
Expand All @@ -67,94 +69,87 @@ TwineRouter.map({
'/stories/:id/play': {
component: {
ready() {
const state = this.$store.state;
const story = state.story.stories.find(
story => story.id === this.$route.params.id
);

loadFormat(
this.$store,
story.storyFormat,
story.storyFormatVersion
).then(format => {
replaceUI(publishStoryWithFormat(
state.appInfo,
story,
format
));
});
getStoryPlayHtml(this.$store, this.$route.params.id)
.then(replaceUI)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);

/* Force returning to the previous view. */

throw e;
});
}
}
},

'/stories/:id/proof': {
component: {
ready() {
const state = this.$store.state;
const story = state.story.stories.find(
story => story.id === this.$route.params.id
);

loadFormat(
this.$store,
state.pref.proofingFormat.name,
state.pref.proofingFormat.version
).then(format => {
replaceUI(publishStoryWithFormat(
state.appInfo,
story,
format
));
});
getStoryProofingHtml(this.$store, this.$route.params.id)
.then(replaceUI)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);

/* Force returning to the previous view. */

throw e;
});
}
}
},

'/stories/:id/test': {
component: {
ready() {
const state = this.$store.state;
const story = state.story.stories.find(
story => story.id === this.$route.params.id
);

loadFormat(
this.$store,
story.storyFormat,
story.storyFormatVersion
).then(format => {
replaceUI(publishStoryWithFormat(
state.appInfo,
story,
format,
['debug']
));
});
getStoryTestHtml(this.$store, this.$route.params.id)
.then(replaceUI)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);

/* Force returning to the previous view. */

throw e;
});
}
}
},

'/stories/:storyId/test/:passageId': {
component: {
ready() {
const state = this.$store.state;
const story = state.story.stories.find(
story => story.id === this.$route.params.storyId
);

loadFormat(
getStoryTestHtml(
this.$store,
story.storyFormat,
story.storyFormatVersion
).then(format => {
replaceUI(publishStoryWithFormat(
state.appInfo,
story,
format,
['debug'],
this.$route.params.passageId
));
});
this.$route.params.storyId,
this.$route.params.passageId
)
.then(replaceUI)
.catch(e => {
window.alert(
locale.say(
'An error occurred while publishing your story. (%s)',
e.message
)
);

/* Force returning to the previous view. */

throw e;
});
}
}
}
Expand Down
Loading

0 comments on commit 9da4474

Please sign in to comment.