Skip to content

Commit

Permalink
Fix image fit in settings to be saved and set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarioste committed Apr 28, 2018
1 parent e038790 commit 872642e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 25 deletions.
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
selectedMangaPath:selectedMangaPath,
currentViewMangaPage: currentViewMangaPage,
viewMangaCommand: viewMangaCommand,
imageFit: imageFit,
appCommands: appCommands
}} -->
<!-- /ko -->
Expand All @@ -102,6 +103,7 @@
<settings-page params="
isRecursive: isRecursive,
commands:appCommands,
imageFit: imageFit,
isDetectUpdatesOnStart:isDetectUpdatesOnStart">
</settings-page>
<file-drag-overlay></file-drag-overlay>
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "BaijiMangaViewer",
"name": "baiji-manga-viewer",
"version": "1.1.0",
"description": "A modern manga viewer inspired by Quivi that uses Material Design",
"main": "./main.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h4 id="header-text" class="col s12">
<div class="col s12 l3">
<div class="switch col s12">
<label id="include-subfolders">
Include subfolders
Search Include subfolders
<input type="checkbox" data-bind="switch:isRecursive">
<span class="lever"></span>
<span id="include-label" data-bind="text:isRecursiveText"></span>
Expand Down Expand Up @@ -39,10 +39,10 @@ <h4 id="header-text" class="col s12">
options:viewOptions,
optionsText: 'text',
optionsValue: 'value',
value: viewOption,
materialSelect:viewOption">
value: imageFit,
materialSelect:imageFit">
</select>
<label>Search and view options</label>
<label>Image fit</label>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SettingsPageViewmodel {
this.isRecursive = params.isRecursive;
this.commands = params.commands;
this.isDetectUpdatesOnStart = params.isDetectUpdatesOnStart;
this.viewOption = ko.observable(ViewOptions.Default)
this.imageFit = params.imageFit;
this.viewOptions = ko.observableArray([
new SelectItem("Normal size", ViewOptions.Default),
new SelectItem("Fit to width", ViewOptions.FitToWidth),
Expand Down Expand Up @@ -63,7 +63,7 @@ export class SettingsPageViewmodel {
PREVIOUS_PAGE: "Previous page",
FOCUS_SEARCH: "Focus search",
OPEN_DIRECTORY: "Open directory",

BACK_TO_LIST: "Back to list"
}
return map[key] || key;
}
Expand Down
36 changes: 27 additions & 9 deletions app/renderer-process/components/view-manga/view-manga.viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ export class ViewMangaViewmodel {
this.command = params.viewMangaCommand;
this.currentPage = params.currentViewMangaPage;
this.appCommands = params.appCommands;
this.imageFit = params.imageFit;

//class defined
this.option = ko.observable(1);
this.option = ko.observable(ko.unwrap(params.imageFit));
this.scrollTopOnClick = ko.observable(true);
this.page = ko.observable(1);
this.transformScale = ko.observable(1.0);
this.viewOptions = ko.observableArray(viewOptions);


console.log("option", this.option());
//functions
this.switchClass = this.switchClass.bind(this);
this.goNextPage = this.goNextPage.bind(this);
this.goToPreviousPage = this.goToPreviousPage.bind(this);
this.viewOption = ko.pureComputed(this.viewOption, this);
this.viewOption = ko.computed(this.viewOption, this);
this.currentImage = ko.pureComputed(this.currentImage, this).extend({ rateLimit: 50 });

this.commands = [
Expand All @@ -58,6 +59,8 @@ export class ViewMangaViewmodel {
request.then((manga) => {
manga = MangaFactory.getManga(manga);
this.selectedManga(manga);


manga.pageImages([]);
this.preloadNextPages(0, 2);
})
Expand All @@ -81,6 +84,9 @@ export class ViewMangaViewmodel {
};
}, this);
this.subscriptions.push(sub);
let viewOption = _.find(this.viewOptions(), (x) => x.value == this.imageFit());
console.log("viewOption", viewOption);
this.switchClass(viewOption);
}

dispose() {
Expand All @@ -95,6 +101,8 @@ export class ViewMangaViewmodel {
}

switchClass(viewOption) {
console.log("inside switchClass", viewOption);

let last = this.option();
this.option(viewOption.value);

Expand Down Expand Up @@ -179,21 +187,31 @@ export class ViewMangaViewmodel {
}

viewOption() {
console.log("View Manga pge: viewOption computed", this.option());
var returnValue;
switch (this.option()) {
case ViewOptions.Normal:

return "normal";
returnValue = "normal";
break;
case ViewOptions.FitToWidth:
return "fit-width";
returnValue = "fit-width";
break;
case ViewOptions.FitToHeight:
return "fit-height";
returnValue = "fit-height";
break;
case ViewOptions.ZoomIn:
return "zoom-in";
returnValue = "zoom-in";
break;
case ViewOptions.ZoomOut:
return "zoom-out";
returnValue = "zoom-out";
break;
default:
return "normal";
returnValue = "normal";
break;
}
console.log("returnValue", returnValue);
return returnValue;
}
static registerComponent() {
ko.components.register("view-manga", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ko.bindingHandlers.keybind = {
if (!_.includes([16, 17, 18, 91], event.keyCode)) {
letter = String.fromCharCode(event.keyCode);
}
if (_.includes([37, 38, 39, 40], event.keyCode)) {
if (_.includes([37, 38, 39, 40, 8], event.keyCode)) {
switch (event.keyCode) {
case 37:
letter = "LEFT ARROW";
Expand All @@ -38,6 +38,9 @@ ko.bindingHandlers.keybind = {
case 40:
letter = "DOWN ARROW";
break;
case 8:
letter = "BACKSPACE";
break;
}
}
if (letter) {
Expand Down
3 changes: 2 additions & 1 deletion app/renderer-process/models/command.viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const DefaultCommandHotkeys = {
NEXT_PAGE: "RIGHT ARROW",
PREVIOUS_PAGE: "LEFT ARROW",
FOCUS_SEARCH: "CTRL + F",
OPEN_DIRECTORY: "CTRL + O"
OPEN_DIRECTORY: "CTRL + O",
BACK_TO_LIST: "BACKSPACE"
}
10 changes: 4 additions & 6 deletions app/renderer-process/models/main.viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "path";
import api from "renderer-process/common/api.js";
import Pages from "renderer-process/common/pages.enum";
import Folder from "renderer-process/models/folder.viewmodel.js";
import { ViewOptions } from "renderer-process/components";
import { DefaultCommandHotkeys } from "renderer-process/models/command.viewmodel";
import { autoUpdater } from "renderer-process/common/auto-updater";
import logger from "electron-log";
Expand All @@ -23,6 +24,7 @@ export default class ViewModel {
this.selectedMangaPath = ko.observable(params.selectedMangaPath).extend({ notify: 'always' });
this.currentViewMangaPage = ko.observable(0);
this.viewMangaCommand = ko.observable(null).extend({ notify: 'always' });
this.imageFit = ko.observable(params.imageFit || ViewOptions.Default);
this.pagination = ko.observable(0);
this.scrollEnd = ko.observable(false).extend({ rateLimit: 500 });
this.appCommands = ko.observable(_.extend({}, DefaultCommandHotkeys, params.appCommands));
Expand All @@ -49,6 +51,7 @@ export default class ViewModel {
isRecursive: this.isRecursive(),
currentPage: this.currentPage(),
previousPage: this.previousPage(),
imageFit: this.imageFit(),
appCommands: appCommands,
selectedMangaPath: selectedMangaPath,
isDetectUpdatesOnStart: this.isDetectUpdatesOnStart()
Expand All @@ -57,11 +60,7 @@ export default class ViewModel {
rateLimit: 500
});

// let sub2 = this.selectedManga.subscribe(function (manga) {
// if (manga) {
// this.selectedDirectory(null);
// }
// }, this);

let sub3 = this.selectedMangaPath.subscribe(function (path) {
logger.debug("selectedMangaPath changed", path);
if (path) {
Expand All @@ -72,7 +71,6 @@ export default class ViewModel {
}, this);

this.subscriptions.push(sub);
// this.subscriptions.push(sub2);

if (this.isDetectUpdatesOnStart()) {
logger.info("checking for updates..");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"start": "yarn install && yarn compile && electron ./app",
"start": "electron ./app",
"build-renderer": "node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.js --progress --profile --colors --watch",
"build-renderer-prod": "node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.js",
"postinstall": "electron-builder install-app-deps",
Expand Down

0 comments on commit 872642e

Please sign in to comment.