diff options
author | 2021-09-06 05:03:57 +0530 | |
---|---|---|
committer | 2021-09-06 05:03:57 +0530 | |
commit | 947a776e1ed902a218af0f634bfa9d320678ce93 (patch) | |
tree | e2389cea54c72d369aaec275a6f9e56b0cc8153a /src/stores | |
parent | chore: updated 'recipes' submodule to test 'electron/remote' issues. (diff) | |
download | ferdium-app-947a776e1ed902a218af0f634bfa9d320678ce93.tar.gz ferdium-app-947a776e1ed902a218af0f634bfa9d320678ce93.tar.zst ferdium-app-947a776e1ed902a218af0f634bfa9d320678ce93.zip |
refactor: trying to fix zoom in/out being sticky for the last active service when started up
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/ServicesStore.js | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index 8598c6234..b429c9101 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -99,6 +99,9 @@ export default class ServicesStore extends Store { | |||
99 | this.actions.service.openDevToolsForActiveService.listen( | 99 | this.actions.service.openDevToolsForActiveService.listen( |
100 | this._openDevToolsForActiveService.bind(this), | 100 | this._openDevToolsForActiveService.bind(this), |
101 | ); | 101 | ); |
102 | this.actions.service.zoomInForActiveService.listen(this._zoomInForActiveService.bind(this)); | ||
103 | this.actions.service.zoomOutForActiveService.listen(this._zoomOutForActiveService.bind(this)); | ||
104 | this.actions.service.zoomResetForActiveService.listen(this._zoomResetForActiveService.bind(this)); | ||
102 | this.actions.service.hibernate.listen(this._hibernate.bind(this)); | 105 | this.actions.service.hibernate.listen(this._hibernate.bind(this)); |
103 | this.actions.service.awake.listen(this._awake.bind(this)); | 106 | this.actions.service.awake.listen(this._awake.bind(this)); |
104 | this.actions.service.resetLastPollTimer.listen( | 107 | this.actions.service.resetLastPollTimer.listen( |
@@ -603,8 +606,12 @@ export default class ServicesStore extends Store { | |||
603 | } | 606 | } |
604 | 607 | ||
605 | @action _blurActive() { | 608 | @action _blurActive() { |
606 | if (!this.active) return; | 609 | const service = this.active; |
607 | this.active.isActive = false; | 610 | if (service) { |
611 | service.isActive = false; | ||
612 | } else { | ||
613 | debug('No service is active'); | ||
614 | } | ||
608 | } | 615 | } |
609 | 616 | ||
610 | @action _setActiveNext() { | 617 | @action _setActiveNext() { |
@@ -678,6 +685,8 @@ export default class ServicesStore extends Store { | |||
678 | const service = this.active; | 685 | const service = this.active; |
679 | if (service) { | 686 | if (service) { |
680 | this._focusService({ serviceId: service.id }); | 687 | this._focusService({ serviceId: service.id }); |
688 | } else { | ||
689 | debug('No service is active'); | ||
681 | } | 690 | } |
682 | } else { | 691 | } else { |
683 | this.allServicesRequest.invalidate(); | 692 | this.allServicesRequest.invalidate(); |
@@ -846,12 +855,13 @@ export default class ServicesStore extends Store { | |||
846 | } | 855 | } |
847 | 856 | ||
848 | @action _reloadActive() { | 857 | @action _reloadActive() { |
849 | if (this.active) { | 858 | const service = this.active; |
850 | const service = this.one(this.active.id); | 859 | if (service) { |
851 | |||
852 | this._reload({ | 860 | this._reload({ |
853 | serviceId: service.id, | 861 | serviceId: service.id, |
854 | }); | 862 | }); |
863 | } else { | ||
864 | debug('No service is active'); | ||
855 | } | 865 | } |
856 | } | 866 | } |
857 | 867 | ||
@@ -958,7 +968,6 @@ export default class ServicesStore extends Store { | |||
958 | 968 | ||
959 | @action _openDevToolsForActiveService() { | 969 | @action _openDevToolsForActiveService() { |
960 | const service = this.active; | 970 | const service = this.active; |
961 | |||
962 | if (service) { | 971 | if (service) { |
963 | this._openDevTools({ serviceId: service.id }); | 972 | this._openDevTools({ serviceId: service.id }); |
964 | } else { | 973 | } else { |
@@ -966,6 +975,43 @@ export default class ServicesStore extends Store { | |||
966 | } | 975 | } |
967 | } | 976 | } |
968 | 977 | ||
978 | @action _zoomInForActiveService() { | ||
979 | const service = this.active; | ||
980 | if (service) { | ||
981 | debug(`active service : ${service.id}`); | ||
982 | const level = service.webview.getZoomLevel(); | ||
983 | // level 9 =~ +300% and setZoomLevel wouldnt zoom in further | ||
984 | if (level < 9) { | ||
985 | service.webview.setZoomLevel(level + 1); | ||
986 | } | ||
987 | } else { | ||
988 | debug('No service is active'); | ||
989 | } | ||
990 | } | ||
991 | |||
992 | @action _zoomOutForActiveService() { | ||
993 | const service = this.active; | ||
994 | if (service) { | ||
995 | debug(`active service : ${service.id}`); | ||
996 | const level = service.webview.getZoomLevel(); | ||
997 | // level -9 =~ -50% and setZoomLevel wouldnt zoom out further | ||
998 | if (level > -9) { | ||
999 | service.webview.setZoomLevel(level - 1); | ||
1000 | } | ||
1001 | } else { | ||
1002 | debug('No service is active'); | ||
1003 | } | ||
1004 | } | ||
1005 | |||
1006 | @action _zoomResetForActiveService() { | ||
1007 | const service = this.active; | ||
1008 | if (service) { | ||
1009 | service.webview.setZoomLevel(0); | ||
1010 | } else { | ||
1011 | debug('No service is active'); | ||
1012 | } | ||
1013 | } | ||
1014 | |||
969 | @action _hibernate({ serviceId }) { | 1015 | @action _hibernate({ serviceId }) { |
970 | const service = this.one(serviceId); | 1016 | const service = this.one(serviceId); |
971 | if (!service.canHibernate) { | 1017 | if (!service.canHibernate) { |
@@ -1018,12 +1064,13 @@ export default class ServicesStore extends Store { | |||
1018 | if (service) { | 1064 | if (service) { |
1019 | this.actions.service.focusService({ serviceId: service.id }); | 1065 | this.actions.service.focusService({ serviceId: service.id }); |
1020 | document.title = `Ferdi - ${service.name}`; | 1066 | document.title = `Ferdi - ${service.name}`; |
1067 | } else { | ||
1068 | debug('No service is active'); | ||
1021 | } | 1069 | } |
1022 | } | 1070 | } |
1023 | 1071 | ||
1024 | _saveActiveService() { | 1072 | _saveActiveService() { |
1025 | const service = this.active; | 1073 | const service = this.active; |
1026 | |||
1027 | if (service) { | 1074 | if (service) { |
1028 | this.actions.settings.update({ | 1075 | this.actions.settings.update({ |
1029 | type: 'service', | 1076 | type: 'service', |
@@ -1031,6 +1078,8 @@ export default class ServicesStore extends Store { | |||
1031 | activeService: service.id, | 1078 | activeService: service.id, |
1032 | }, | 1079 | }, |
1033 | }); | 1080 | }); |
1081 | } else { | ||
1082 | debug('No service is active'); | ||
1034 | } | 1083 | } |
1035 | } | 1084 | } |
1036 | 1085 | ||