Skip to content

Commit

Permalink
Widgets: sunmoon
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Sep 17, 2022
1 parent f79fcaa commit 967aea2
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 0 deletions.
6 changes: 6 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ common:
hashtags: "Hashtags"
words: "Trend words"
queue: "Queue"
sunmoon: "Sun and moon"
dev: "Failed to create the application. Please try again."
ai-chan-kawaii: "Ai-chan kawaii!"
you: "You"
Expand Down Expand Up @@ -998,6 +999,11 @@ common/views/widgets/tips.vue:
tips-line23: "Ai-chan kawaii!"
tips-line24: "Misskey has been running since 2014."
tips-line25: "In a browser compatible with notification features, you can receive notifications in case Misskey is not open"
common/views/widgets/sunmoon.vue:
ctStart: " Civil twilight"
sunrise: "Sunrise"
sunset: "Sunset"
ctEnd: " Civil twilight"
common/views/pages/not-found.vue:
page-not-found: "The page has not been found"
common/views/pages/follow.vue:
Expand Down
7 changes: 7 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ common:
hashtags: "ハッシュタグ"
words: "トレンドワード"
queue: "キュー"
sunmoon: "太陽と月"

dev: "アプリの作成に失敗しました。再度お試しください。"
ai-chan-kawaii: "藍ちゃかわいい"
Expand Down Expand Up @@ -1079,6 +1080,12 @@ common/views/widgets/tips.vue:
tips-line24: "Misskeyは2014年にサービスを開始しました"
tips-line25: "対応ブラウザではMisskeyを開いていなくても通知を受け取れます"

common/views/widgets/sunmoon.vue:
ctStart: "市民薄明"
sunrise: "日の出"
sunset: "日の入"
ctEnd: "市民薄明"

common/views/pages/not-found.vue:
page-not-found: "ページが見つかりませんでした"

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@types/sharp": "0.30.2",
"@types/showdown": "2.0.0",
"@types/speakeasy": "2.0.7",
"@types/suncalc": "1.8.1",
"@types/tinycolor2": "1.4.3",
"@types/tmp": "0.2.3",
"@types/uuid": "8.3.4",
Expand Down Expand Up @@ -189,6 +190,7 @@
"stringz": "2.1.0",
"stylus": "0.59.0",
"stylus-loader": "6.2.0",
"suncalc": "1.8.0",
"systeminformation": "5.12.6",
"syuilo-password-strength": "0.0.1",
"terser-webpack-plugin": "4.2.3",
Expand Down
1 change: 1 addition & 0 deletions src/client/app/common/views/deck/deck.widgets-column.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<option value="queue">{{ $t('@.widgets.queue') }}</option>
<option value="nav">{{ $t('@.widgets.nav') }}</option>
<option value="tips">{{ $t('@.widgets.tips') }}</option>
<option value="sunmoon">{{ $t('@.widgets.sunmoon') }}</option>
</select>
</header>
<x-draggable
Expand Down
1 change: 1 addition & 0 deletions src/client/app/common/views/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Vue.component('mkw-words', () => import('./words.vue').then(m => m.default));
Vue.component('mkw-instance', () => import('./instance.vue').then(m => m.default));
Vue.component('mkw-post-form', () => import('./post-form.vue').then(m => m.default));
Vue.component('mkw-queue', () => import('./queue.vue').then(m => m.default));
Vue.component('mkw-sunmoon', () => import('./sunmoon.vue').then(m => m.default));
144 changes: 144 additions & 0 deletions src/client/app/common/views/widgets/sunmoon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<template>
<div class="mkw-sunmoon">
<div class="lunar-calendar">
<!-- <p class="moonface"><img :src="moonFace" height="64" :style="`transform:rotateZ(${moonAngle}rad);`"></p> -->
<p class="moonface"><img :src="moonFace" height="64"></p>
<p class="moonage">{{ moonAge }}</p>
</div>
<div class="suntime">
<div><small>{{ $t('ctStart') }}: {{ civTwiStartTime }}</small></div>
<div>{{ $t('sunrise') }}: {{ sunRiseTime }}</div>
<div>{{ $t('sunset') }}: {{ sunSetTime }}</div>
<div><small>{{ $t('ctEnd') }}: {{ civTwiEndTime }}</small></div>
</div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import moment from "moment";
import SunCalc from "suncalc";
import define from '../../../common/define-widget';
import { twemojiSvgBase } from '../../../../../misc/twemoji-base';
import i18n from '../../../i18n';
const widget = define({
name: 'sunmoon',
});
export default defineComponent({
extends: widget,
i18n: i18n('common/views/widgets/sunmoon.vue'),
data() {
return {
// 計算基準値
// 計算基準値 - 年月日は後で上書き
now: new Date(),
year: 2000,
month: 1,
day: 1,
// 計算基準値 - 緯度経度は固定
latitude: 35, // 緯度 (白夜/極夜でもない限りあまり関係ない)
longitude: 140, // 経度 (新鎌ヶ谷駅、船橋競馬場駅など)
// 表示用
civTwiStartTime: '00:00', // 市民薄明開始
sunRiseTime: '00:00', // 日の出
sunSetTime: '00:00', // 日の入
civTwiEndTime: '00:00', // 市民薄明終了
moonAge: '0.0', // 月齢
moonFace: `${twemojiSvgBase}/1f311.svg`, // 月齢画像URL
// 更新タイマー
clock: undefined as unknown as NodeJS.Timer,
};
},
created() {
this.tick();
this.clock = setInterval(this.tick, 60 * 1000);
},
beforeUnmount() {
clearInterval(this.clock);
},
methods: {
tick() {
// 年月日
const now = new Date();
this.year = now.getFullYear();
this.month = now.getMonth() + 1;
this.day = now.getDate();
// 太陽
const sunTimes = SunCalc.getTimes(now, this.latitude, this.longitude);
this.civTwiStartTime = moment(sunTimes.dawn).format('HH:mm'); // 市民薄明開始
this.sunRiseTime = moment(sunTimes.sunrise).format('HH:mm'); // 日の出
this.sunSetTime = moment(sunTimes.sunset).format('HH:mm'); // 日の入
this.civTwiEndTime = moment(sunTimes.dusk).format('HH:mm'); // 市民薄明終了
//
const moonTimes = SunCalc.getMoonIllumination(now);
// 月齢
const moonPhase = moonTimes.phase; // 0-1
this.moonAge = (29.5 * moonPhase).toFixed(1); // 0 - 29.5
// 月齢画像
const moonFaceImg = ['1', '2', '3', '4', '5', '6', '7', '8'][Math.floor(8 * moonPhase)];
this.moonFace = `${twemojiSvgBase}/1f31${moonFaceImg}.svg`;
}
}
});
</script>
<style lang="stylus" scoped>
.mkw-sunmoon {
background: var(--face);
color: var(--text);
padding: 16px 0;
display: flex;
justify-content: center;
align-items: center;
&:after {
content: "";
}
> .lunar-calendar {
float: left;
width: 40%;
text-align: center;
> p {
margin: 0;
line-height: 18px;
font-size: 0.9em;
}
> .moonface {
line-height: 72px;
font-size: 4em;
}
}
> .suntime {
display: block;
float: right;
text-align: center;
width: 60%;
padding: 0 16px 0 0;
box-sizing: border-box;
> div {
&:last-child {
margin-bottom: 0;
}
> p {
margin: 0 0 2px 0;
font-size: 1em;
line-height: 18px;
// sunrise sunset time
> b {
margin-left: 2px;
}
}
}
}
}
</style>
1 change: 1 addition & 0 deletions src/client/app/desktop/views/home/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<option value="queue">{{ $t('@.widgets.queue') }}</option>
<option value="nav">{{ $t('@.widgets.nav') }}</option>
<option value="tips">{{ $t('@.widgets.tips') }}</option>
<option value="sunmoon">{{ $t('@.widgets.sunmoon') }}</option>
</select>
<button @click="addWidget">{{ $t('add') }}</button>
<button @click="restoreDefault">{{ $t('restore-default') }}</button>
Expand Down
1 change: 1 addition & 0 deletions src/client/app/mobile/views/pages/widgets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<option value="memo">{{ $t('@.widgets.memo') }}</option>
<option value="nav">{{ $t('@.widgets.nav') }}</option>
<option value="tips">{{ $t('@.widgets.tips') }}</option>
<option value="sunmoon">{{ $t('@.widgets.sunmoon') }}</option>
</select>
<button @click="addWidget">{{ $t('add-widget') }}</button>
<p><a @click="hint">{{ $t('customization-tips') }}</a></p>
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,11 @@
dependencies:
"@types/node" "*"

"@types/suncalc@1.8.1":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@types/suncalc/-/suncalc-1.8.1.tgz#64fd7e779c03e5df16e6140b8e00d4521fa4185e"
integrity sha512-PNtzFQhdAIw3x5HEjVMxbyBwciX42C/Cg6J1foq2z/t9rucLGGu9nqQxOl005wGZR/fOxw49exwZUCmbnT/vGw==

"@types/tinycolor2@1.4.3":
version "1.4.3"
resolved "https://registry.yarnpkg.com/@types/tinycolor2/-/tinycolor2-1.4.3.tgz#ed4a0901f954b126e6a914b4839c77462d56e706"
Expand Down Expand Up @@ -8253,6 +8258,11 @@ stylus@^0.54.8:
semver "^6.3.0"
source-map "^0.7.3"

suncalc@1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/suncalc/-/suncalc-1.8.0.tgz#1d9898109563078750f4994a959e654d876acbf5"
integrity sha512-fyyqA8Az3HnYkNtiiniU0g4xZZXnZYWjuRSS0RegfbmYTbe7idmv4L2Lho/Ez+/HsrmNjuop/bL/FutjtrTT3w==

supports-color@8.1.1, supports-color@^8.0.0:
version "8.1.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
Expand Down

0 comments on commit 967aea2

Please sign in to comment.