From 4c931278b8dbf1e80e5680eca93687635e8bdce9 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Mon, 9 Dec 2019 17:38:51 +0100 Subject: [PATCH] Remove angular os-open-external directive Change-type: patch --- lib/gui/app/app.js | 5 +- .../drive-selector/drive-selector.js | 3 +- lib/gui/app/components/finish/finish.tsx | 18 +++++- .../open-external/directives/open-external.js | 61 ------------------- lib/gui/app/os/open-external/open-external.js | 46 -------------- lib/gui/app/pages/main/main.ts | 2 - lib/gui/app/scss/main.scss | 13 ---- lib/gui/css/main.css | 7 --- scripts/html-lint.js | 4 -- tests/gui/os/open-external.spec.js | 61 ------------------- 10 files changed, 18 insertions(+), 202 deletions(-) delete mode 100644 lib/gui/app/os/open-external/directives/open-external.js delete mode 100644 lib/gui/app/os/open-external/open-external.js delete mode 100644 tests/gui/os/open-external.spec.js diff --git a/lib/gui/app/app.js b/lib/gui/app/app.js index 83a97a74..6e435275 100644 --- a/lib/gui/app/app.js +++ b/lib/gui/app/app.js @@ -91,10 +91,7 @@ const app = angular.module('Etcher', [ // Pages require('./pages/main/main.ts').MODULE_NAME, - require('./components/finish/index.ts').MODULE_NAME, - - // OS - require('./os/open-external/open-external') + require('./components/finish/index.ts').MODULE_NAME ]) app.run(() => { diff --git a/lib/gui/app/components/drive-selector/drive-selector.js b/lib/gui/app/components/drive-selector/drive-selector.js index f2f0d8af..5f2d457b 100644 --- a/lib/gui/app/components/drive-selector/drive-selector.js +++ b/lib/gui/app/components/drive-selector/drive-selector.js @@ -25,8 +25,7 @@ const MODULE_NAME = 'Etcher.Components.DriveSelector' const DriveSelector = angular.module(MODULE_NAME, [ require('../modal/modal'), require('../confirm-modal/confirm-modal'), - require('../../utils/byte-size/byte-size'), - require('../../os/open-external/open-external') + require('../../utils/byte-size/byte-size') ]) DriveSelector.controller('DriveSelectorController', require('./controllers/drive-selector')) diff --git a/lib/gui/app/components/finish/finish.tsx b/lib/gui/app/components/finish/finish.tsx index e444b863..e3d2a7e4 100644 --- a/lib/gui/app/components/finish/finish.tsx +++ b/lib/gui/app/components/finish/finish.tsx @@ -17,12 +17,14 @@ import * as _ from 'lodash'; import * as React from 'react'; import * as uuidV4 from 'uuid/v4'; + import * as messages from '../../../../shared/messages'; import * as flashState from '../../models/flash-state'; import * as selectionState from '../../models/selection-state'; import * as store from '../../models/store'; import * as analytics from '../../modules/analytics'; import * as updateLock from '../../modules/update-lock'; +import { open as openExternal } from '../../os/open-external/services/open-external'; import { FlashAnother } from '../flash-another/flash-another'; import { FlashResults } from '../flash-results/flash-results'; import * as SVGIcon from '../svg-icon/svg-icon'; @@ -88,7 +90,14 @@ function FinishPage({ $state }: any) {
Thanks for using - + + openExternal( + 'https://balena.io/etcher?ref=etcher_offline_banner', + ) + } + > by - + + openExternal('https://balena.io?ref=etcher_success') + } + > Balena.io - */ -module.exports = (OSOpenExternalService) => { - return { - restrict: 'A', - scope: false, - link: (scope, element, attributes) => { - // This directive might be added to elements - // other than buttons. - element.css('cursor', 'pointer') - - element.on('click', () => { - OSOpenExternalService.open(attributes.osOpenExternal) - }) - - const ENTER_KEY = 13 - const SPACE_KEY = 32 - element.on('keypress', (event) => { - if (_.includes([ ENTER_KEY, SPACE_KEY ], event.keyCode)) { - // Don't spam the user with several tabs if the key is being held - if (!event.repeat) { - OSOpenExternalService.open(attributes.osOpenExternal) - } - } - }) - } - } -} diff --git a/lib/gui/app/os/open-external/open-external.js b/lib/gui/app/os/open-external/open-external.js deleted file mode 100644 index 99fd0107..00000000 --- a/lib/gui/app/os/open-external/open-external.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016 balena.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict' - -/** - * @module Etcher.OS.OpenExternal - */ - -const angular = require('angular') -const url = require('url') - -const MODULE_NAME = 'Etcher.OS.OpenExternal' -const OSOpenExternal = angular.module(MODULE_NAME, []) -OSOpenExternal.service('OSOpenExternalService', require('./services/open-external')) -OSOpenExternal.directive('osOpenExternal', require('./directives/open-external')) - -OSOpenExternal.run((OSOpenExternalService) => { - document.addEventListener('click', (event) => { - const target = event.target - if (target.tagName === 'A' && angular.isDefined(target.href)) { - // Electron interprets relative URLs as being relative to the - // current loaded URL (with `webContents.loadURL`) and expands - // them to the corresponding absolute URL. If it's a `file://` - // URL, we don't want it opened in an external browser. - if (url.parse(target.href).protocol !== 'file:') { - OSOpenExternalService.open(target.href) - } - } - }) -}) - -module.exports = MODULE_NAME diff --git a/lib/gui/app/pages/main/main.ts b/lib/gui/app/pages/main/main.ts index da95f1c2..eba74b3f 100644 --- a/lib/gui/app/pages/main/main.ts +++ b/lib/gui/app/pages/main/main.ts @@ -32,7 +32,6 @@ import * as driveSelector from '../../components/drive-selector'; import * as driveSelectorService from '../../components/drive-selector/drive-selector'; import { MODULE_NAME as flashAnother } from '../../components/flash-another'; import { MODULE_NAME as flashResults } from '../../components/flash-results'; -import * as openExternal from '../../os/open-external/open-external'; import * as byteSize from '../../utils/byte-size/byte-size'; export const MODULE_NAME = 'Etcher.Pages.Main'; @@ -43,7 +42,6 @@ const Main = angular.module(MODULE_NAME, [ flashAnother, flashResults, driveSelector, - openExternal, byteSize, ]); diff --git a/lib/gui/app/scss/main.scss b/lib/gui/app/scss/main.scss index a119a6eb..ebc3ebec 100644 --- a/lib/gui/app/scss/main.scss +++ b/lib/gui/app/scss/main.scss @@ -164,24 +164,11 @@ body { margin: 0 13px; } - .caption[os-open-external] { - border-bottom: 1px dashed; - padding-bottom: 2px; - - &:hover { - color: lighten($palette-theme-dark-disabled-foreground, 5%); - } - } - .footer-right { font-size: 10px; position: absolute; right: 0; } - - > span[os-open-external] { - display: flex; - } } .section-loader { diff --git a/lib/gui/css/main.css b/lib/gui/css/main.css index dbde01a6..85b5c905 100644 --- a/lib/gui/css/main.css +++ b/lib/gui/css/main.css @@ -9833,17 +9833,10 @@ body { padding: 0; } .section-footer-main .svg-icon { margin: 0 13px; } - .section-footer-main .caption[os-open-external] { - border-bottom: 1px dashed; - padding-bottom: 2px; } - .section-footer-main .caption[os-open-external]:hover { - color: #85898c; } .section-footer-main .footer-right { font-size: 10px; position: absolute; right: 0; } - .section-footer-main > span[os-open-external] { - display: flex; } .section-loader webview { flex: 0 1; diff --git a/scripts/html-lint.js b/scripts/html-lint.js index 92feb50e..946ff5de 100644 --- a/scripts/html-lint.js +++ b/scripts/html-lint.js @@ -30,10 +30,6 @@ angularValidate.validate( ], customattrs: [ - // Internal - 'os-open-external', - 'os-dropzone', - // External 'hide-if-state', 'show-if-state', diff --git a/tests/gui/os/open-external.spec.js b/tests/gui/os/open-external.spec.js deleted file mode 100644 index 1c3aebf6..00000000 --- a/tests/gui/os/open-external.spec.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2016 balena.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict' - -const m = require('mochainon') -const angular = require('angular') -const electron = require('electron') - -describe('Browser: OSOpenExternal', function () { - beforeEach(angular.mock.module( - require('../../../lib/gui/app/os/open-external/open-external') - )) - - describe('osOpenExternal', function () { - let $compile - let $rootScope - - beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) { - $compile = _$compile_ - $rootScope = _$rootScope_ - })) - - it('should set the element cursor to pointer', function () { - const element = $compile('Balena.io')($rootScope) - $rootScope.$digest() - m.chai.expect(element.css('cursor')).to.equal('pointer') - }) - - it('should call Electron shell.openExternal with the attribute value', function () { - const shellExternalStub = m.sinon.stub(electron.shell, 'openExternal') - const element = $compile('Balena.io')($rootScope) - element.triggerHandler('click') - $rootScope.$digest() - m.chai.expect(shellExternalStub).to.have.been.calledWith('https://balena.io') - shellExternalStub.restore() - }) - - it('should not call Electron shell.openExternal if the attribute value is not defined', function () { - const shellExternalStub = m.sinon.stub(electron.shell, 'openExternal') - const element = $compile('Balena.io')($rootScope) - element.triggerHandler('click') - $rootScope.$digest() - m.chai.expect(shellExternalStub).to.not.have.been.called - shellExternalStub.restore() - }) - }) -})