-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (82 loc) · 3.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import Vue from 'vue';
import corkboard from './view/corkboard.vue';
import store from './state';
import { clipboard } from 'electron';
import {
A_APP_TOGGLE_GODMODE,
A_BOARD_ADD_ITEM,
A_LOAD_ALL
} from './state/action_types';
import rem_to_px from './utils/rem_to_px';
window.vm = new Vue({
el: '#corkboard',
store,
created: function() {
document.onkeydown = this.keydown;
},
mounted: function() {
this.$store.dispatch(A_LOAD_ALL);
},
methods: {
keydown: function(e) {
if(e.key == 'v' && e.ctrlKey) {
this.paste();
} else if (e.key == 'n' && e.ctrlKey) {
this.new_sticky();
} else if (e.key == 'r' && e.ctrlKey) {
location.reload();
} else if (e.key == 's' && e.ctrlKey) {
this.$store.dispatch('save_state');
} else if (e.code == 'KeyA' && e.ctrlKey && e.altKey && e.shiftKey) {
this.$store.dispatch(A_APP_TOGGLE_GODMODE);
}
},
new_sticky: function() {
this.$store.dispatch(A_BOARD_ADD_ITEM, {
x: (window.innerWidth - rem_to_px(15)) / 2,
y: (window.innerHeight - rem_to_px(15)) / 2,
z: this.$store.getters.item_max_field('z') + 1,
type: 'sticky'
});
},
paste: function() {
var clipboard_text = clipboard.readText();
if(clipboard_text) {
console.log('Pasting text ' + clipboard_text + '...');
this.$store.dispatch(A_BOARD_ADD_ITEM, {
x: (window.innerWidth - rem_to_px(15)) / 2,
y: (window.innerHeight - rem_to_px(15)) / 2,
z: this.$store.getters.item_max_field('z') + 1,
type: 'sticky',
content: clipboard_text.trim()
});
}
var clipboard_image = clipboard.readImage();
if(!clipboard_image.isEmpty()) {
var original_size = clipboard_image.getSize();
var target_image;
if(original_size.height > 500 || original_size.width > 500) {
if(original_size.height > original_size.width) {
target_image = clipboard_image.resize({ height: 500 });
} else {
target_image = clipboard_image.resize({ width: 500 });
}
} else {
target_image = clipboard_image;
}
var target_size = target_image.getSize();
var data_url = target_image.toDataURL();
console.log('Pasting ' + original_size.width + 'x' + original_size.height + ' image as '
+ target_size.width + 'x' + target_size.height + '...');
this.$store.dispatch(A_BOARD_ADD_ITEM, {
x: window.innerWidth / 2,
y: window.innerHeight / 2,
z: this.$store.getters.item_max_field('z') + 1,
type: 'picture',
content: data_url
});
}
}
},
render: h => h(corkboard),
});