Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/url #2

Merged
merged 5 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
369 changes: 187 additions & 182 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "easy-qr-code",
"productName": "Easy QR Code",
"version": "0.1.4",
"version": "0.2.0",
"author": "differui <[email protected]>",
"description": "QR code in easy way.",
"license": "./LICENSE",
Expand All @@ -14,7 +14,7 @@
"build:win32": "cross-env BUILD_TARGET=win32 node .electron-vue/build.js",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"release": "./scrips/release.sh",
"release": "./scripts/release.sh",
"dev": "node .electron-vue/dev-runner.js",
"lint": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter src",
"lint:fix": "eslint --ext .js,.vue -f ./node_modules/eslint-friendly-formatter --fix src",
Expand All @@ -25,7 +25,11 @@
},
"dependencies": {
"axios": "^0.16.1",
"debounce": "^1.0.2",
"get-title-at-url": "^1.1.5",
"getfavicon": "^1.1.2",
"qr-image": "^3.2.0",
"valid-url": "^1.0.9",
"vue": "^2.3.3",
"vue-electron": "^1.0.6",
"vue-router": "^2.5.3",
Expand Down
2 changes: 2 additions & 0 deletions scrips/release.sh → scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
npm run build
rm -rf ./build/*.zip
tar -zcvf ./build/Easy\ QR\ Code-darwin-x64.zip ./build/Easy\ QR\ Code-darwin-x64
tar -zcvf ./build/Easy\ QR\ Code-linux-x64.zip ./build/Easy\ QR\ Code-linux-x64
tar -zcvf ./build/Easy\ QR\ Code-mas-x64.zip ./build/Easy\ QR\ Code-mas-x64
Expand Down
55 changes: 47 additions & 8 deletions src/renderer/components/HelperModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<modal class="helper-modal" :visible="value">
<div class="helper-modal__content">
<div class="helper-modal__close" @click="handleCloseClick"></div>
<ul class="helper-modal__list" v-if="shortcutOptionActivated">
<li class="helper-modal__item">
<kbd class="helper-modal__kbd">{{ keyModifier }}</kbd>
Expand Down Expand Up @@ -81,20 +82,59 @@ export default {

<style lang="scss">
.helper-modal {
.modla__wrapper,
.modal__content,
&__content {
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
position: fixed;
}

&__content {
display: flex;
flex-direction: row;
align-items: center;
position: relative;
border-radius: 8px;
width: 300px;
min-height: 240px;
max-height: 400px;
justify-content: center;
background-color: #ffffff;
padding: 50px 32px 50px;
box-sizing: border-box;
}

&__close {
cursor: pointer;
background-color: rgba(0, 0, 0, 0.2);
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
top: 35px;
right: 45px;
position: absolute;
}

&__close::before,
&__close::after {
content: '';
display: block;
width: 1px;
height: 70%;
background-color: #fff;
top: 1px;
position: relative;
}

&__close::before {
transform: rotate(45deg);
}

&__close::after {
transform: rotate(-45deg);
}

&__about,
&__tab {
width: 100%;
Expand All @@ -106,7 +146,6 @@ export default {
}

&__tab {
border-top: solid 1px #e0e5e6;
flex-direction: row;
list-style: none;
display: flex;
Expand All @@ -119,7 +158,7 @@ export default {
&__option {
cursor: pointer;
color: #e8e8e8;
font-size: 12px;
font-size: 24px;
padding: 2px 0;
text-align: center;
flex: 1;
Expand Down
111 changes: 93 additions & 18 deletions src/renderer/components/QrCodeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ul class="qr-code-list">
<li v-for="code in allCodes" :key="code.id" :id="code.id" class="qr-code-list__item" :class="code.selected ? 'qr-code-list__item_selected' : ''" @click="handleItemClick(code)">
<a class="qr-code-list__anchor" href="javascript: void(0);" tabindex="-1">
<p class="qr-code-list__title" :title="code.title">{{ code.title }}</p>
<p class="qr-code-list__title" :title="code.title" @dblclick="handleTitleDoubleClick" @blur="handleTitleBlur(arguments[0], code)" @keydown="handleTitleKeyDown">{{ code.title }}</p>
<p class="qr-code-list__content" :title="code.content">{{ code.content }}</p>
</a>
</li>
Expand All @@ -11,6 +11,7 @@

<script>
import { mapGetters } from 'vuex';
import * as cfg from '@/configs';

export default {
computed: {
Expand All @@ -23,6 +24,58 @@ export default {
handleItemClick(code) {
this.$store.dispatch('selectCode', code.id);
},
handleTitleDoubleClick(ev) {
const body = document.querySelector('body');
const element = ev.currentTarget;

element.contentEditable = true;
element.parentElement.parentElement.classList.add('qr-code-list__item_edit');
if (body.createTextRange) {
const range = body.createTextRange();

range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
const selection = window.getSelection();
const range = document.createRange();

range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
},
handleTitleKeyDown(ev) {
if (ev.keyCode === cfg.KEY_ENTER) {
ev.preventDefault();
ev.currentTarget.blur();
}
},
handleTitleBlur(ev, code) {
const element = ev.currentTarget;
const title = element.textContent.replace(/\n|\r/g, '');

element.contentEditable = false;
element.innerHTML = title;
element.parentElement.parentElement.classList.remove('qr-code-list__item_edit');
if (!title) {
element.innerHTML = code.title;
return;
}
if (title === code.title) {
return;
}
if (this.allCodes.some(c => c.title === title)) {
this.$store.dispatch('showToast', 'Duplicate record title');
element.innerHTML = code.title;
return;
}
if (title !== code.title) {
this.$store.dispatch('updateCode', {
id: code.id,
title,
});
}
},
},
};
</script>
Expand All @@ -40,22 +93,6 @@ export default {
position: relative;
}

&__item:active,
&__item_selected {
background-color: #efefef;
border-bottom-color: #e0e5e6;

&:after {
content: '';
width: 100%;
height: 1px;
background-color: #e0e5e6;
top: -1px;
left: 0;
position: absolute;
}
}

&__anchor {
color: inherit;
text-decoration: none;
Expand All @@ -68,18 +105,56 @@ export default {
margin-bottom: 0;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
position: relative;
}

&__title::after,
&__content::after {
content: '';
width: 20px;
top: 0;
right: 0;
bottom: 0;
position: absolute;
background-image: linear-gradient(to left, #f6f8f8 20%, transparent);
}

&__title {
outline: none;
margin-bottom: 5px;
}

&__content {
color: #cccccc;
font-size: 14px;
}

// state
// ====
&__item_selected {
background-color: #efefef;
border-bottom-color: #e0e5e6;
}

&__item_selected::after {
content: '';
width: 100%;
height: 1px;
background-color: #e0e5e6;
top: -1px;
left: 0;
position: absolute;
}

&__item_selected &__title::after,
&__item_selected &__content::after {
background-image: linear-gradient(to left, #efefef 20%, transparent);
}

&__item_edit &__title::after {
background-image: none;
}
}
</style>

2 changes: 1 addition & 1 deletion src/renderer/components/Toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
&__wrapper {
text-align: center;
border-radius: 500px;
background-color: rgba(0, 0, 0, 0.5);
background-color: rgba(0, 0, 0, 0.75);
min-width: 100px;
max-width: 250px;
padding: 12px;
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/configs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const MAX_AVALIABLE_CODE_COUNT = 20;
export const MAX_CONTENT_LENGTH = 150 * 3;
export const TOAST_DURATION = 3000;
export const GET_TITLE_TIMEOUT = 8 * 1000;
export const SAVE_CHECKPOINT_DURATION = 1000;

export * from './keycode';
1 change: 1 addition & 0 deletions src/renderer/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './is';
export * from './svg';
export * from './storage';
export * from './title';
17 changes: 17 additions & 0 deletions src/renderer/helpers/title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import getTitleAtUrl from 'get-title-at-url';
import * as cfg from '@/configs';

/* eslint-disable import/prefer-default-export */
export function getTitle(url) {
return Promise.race([
new Promise((resolve, reject) => {
setTimeout(reject, cfg.GET_TITLE_TIMEOUT);
}),
new Promise((resolve, reject) => {
getTitleAtUrl(url, (title, err) => {
if (err) reject(err);
else resolve(title);
});
}),
]);
}
5 changes: 5 additions & 0 deletions src/renderer/store/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Vue from 'vue';
import Vuex from 'vuex';
import debounce from 'debounce';
import toast from '@/store/modules/toast';
import qrCodeList from '@/store/modules/qr-code-list';
import qrCodeImage from '@/store/modules/qr-code-image';
import * as helpers from '@/helpers';
import * as cfg from '@/configs';

Vue.use(Vuex);

Expand All @@ -22,4 +24,7 @@ store.replaceState({
},
qrCodeImage: qrCodeImage.state,
});
store.subscribe(debounce((mutation, state) => {
helpers.setItem('codes', state.qrCodeList.codes);
}, cfg.SAVE_CHECKPOINT_DURATION));
export default store;
24 changes: 18 additions & 6 deletions src/renderer/webviews/Workspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<script>
import { mapGetters } from 'vuex';
import { parse as parseUrl } from 'url';
import { isWebUri } from 'valid-url';
import Toast from '@/components/Toast';
import Scroller from '@/components/Scroller';
import QrCodeImage from '@/components/QrCodeImage';
Expand Down Expand Up @@ -59,9 +59,6 @@ export default {
this.$electron.ipcRenderer.send('encode-text', newSelectedCode.content);
}
},
allCodes(newAllCodes) {
helpers.setItem('codes', newAllCodes);
},
},
methods: {
handleInputKeyDown(ev) {
Expand All @@ -86,15 +83,30 @@ export default {
return;
}
if (content) {
const urlOpts = parseUrl(content);
let previousCodeId;

if (isWebUri(content)) {
helpers.getTitle(content)
.then((urlTitle) => {
if (urlTitle) {
this.$store.dispatch('updateCode', {
id: previousCodeId,
title: urlTitle,
});
}
})
.catch(() => {
// do nothing
});
}
this.$store.dispatch('addCode', {
title: urlOpts.hostname || content,
title: content,
content,
selected: true,
});
this.$electron.ipcRenderer.send('encode-text', content);
this.$store.dispatch('selectCode', this.allCodes[0].id);
previousCodeId = this.selectedCode.id;
}
targetNode.value = '';
},
Expand Down