Skip to content

Commit 64c44c7

Browse files
committed
Review
1 parent 36fa7d8 commit 64c44c7

File tree

5 files changed

+46
-10
lines changed

5 files changed

+46
-10
lines changed

src/components/Review.vue

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="review-block" v-if="showReview">
33
<p>{{ t('enjoyAndReview.message') }}</p>
44
<img height="15" src="../assets/icons/close.svg" @click="closeBlock()" />
5-
<input type="button" :value="t('enjoyAndReview.description')" />
5+
<input type="button" :value="t('enjoyAndReview.description')" @click="openStore()" />
66
</div>
77
</template>
88

@@ -15,17 +15,52 @@ export default {
1515
<script lang="ts" setup>
1616
import { onMounted, ref } from 'vue';
1717
import { useI18n } from 'vue-i18n';
18+
import { injecStorage } from '../storage/inject-storage';
19+
import { StorageParams } from '../storage/storage-params';
20+
import { addDays, startOfToday } from 'date-fns';
21+
import { addHours } from 'date-fns/esm';
1822
1923
const { t } = useI18n();
2024
25+
const settingsStorage = injecStorage();
26+
const PROMPT_AT_TIME_OF_DAY = 12;
27+
const ADD_DAYS_FIRST = 2;
28+
const ADD_DAYS_NEXT = 5;
29+
const CHROME_STORE_URL = `https://chrome.google.com/webstore/detail/web-activity-time-tracker/${__APP_ID__}/reviews`;
30+
2131
const showReview = ref<boolean>();
2232
23-
onMounted(() => {
24-
showReview.value = true;
33+
onMounted(async () => {
34+
showReview.value = false;
35+
if (__BROWSER__ == 'chrome') {
36+
const reviewDate = await settingsStorage.getValue(StorageParams.REVIEW_DATE);
37+
38+
if (reviewDate == undefined) {
39+
let nextTime = await settingsStorage.getValue(StorageParams.REVIEW_PROMPT_AT);
40+
if (nextTime == undefined) {
41+
await settingsStorage.saveValue(
42+
StorageParams.REVIEW_PROMPT_AT,
43+
addDays(addHours(startOfToday(), PROMPT_AT_TIME_OF_DAY), ADD_DAYS_FIRST).toString(),
44+
);
45+
} else {
46+
nextTime = new Date(nextTime);
47+
if (nextTime < new Date()) showReview.value = true;
48+
}
49+
}
50+
}
2551
});
2652
27-
function closeBlock() {
53+
async function closeBlock() {
2854
showReview.value = false;
55+
await settingsStorage.saveValue(
56+
StorageParams.REVIEW_PROMPT_AT,
57+
addDays(addHours(startOfToday(), PROMPT_AT_TIME_OF_DAY), ADD_DAYS_NEXT).toString(),
58+
);
59+
}
60+
61+
async function openStore() {
62+
window.open(CHROME_STORE_URL, '_blank');
63+
await settingsStorage.saveValue(StorageParams.REVIEW_DATE, new Date().toString());
2964
}
3065
</script>
3166

src/components/TimeIntervalChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function fillData(timeIntervalList: TimeInterval[]) {
141141
142142
objects.forEach(obj => {
143143
const emptyArray: number[] = Object.assign([], tempArray);
144-
emptyArray[obj.hour] = Number((obj.summary / 60).toFixed(4));
144+
emptyArray[obj.hour] = Number(obj.summary / 60);
145145
result.push({
146146
backgroundColor: ['#5668e2'],
147147
data: emptyArray,

src/storage/storage-params.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum StorageParams {
1515
DAILY_SUMMARY_NOTIFICATION_TIME = 'daily-summary-notification-time',
1616
DAILY_NOTIFICATION = 'daily_notification',
1717
REVIEW_DATE = 'review_date',
18+
REVIEW_PROMPT_AT = 'review_prompt_at',
1819
INSTALL_DATE = 'install-date',
1920
}
2021

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
declare var __EXTENSION_MODE__: ExtensionMode;
33
declare var __DEV__: boolean;
44
declare var __PROD__: boolean;
5-
declare var __EXTENSION_VERSION__: string;
6-
declare var __REAL_APP_ID__: string;
5+
declare var __APP_ID__: string;
6+
declare var __BROWSER__: string;

vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { defineConfig } from 'vite';
22
import path from 'path';
33
import vue from '@vitejs/plugin-vue';
44
import webExtension, { readJsonFile } from 'vite-plugin-web-extension';
5-
import pkg from './package.json';
65
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
76
import copy from 'rollup-plugin-copy';
87

98
const APPID_CHROME = 'hhfnghjdeddcfegfekjeihfmbjenlomm';
9+
const browser = process.env.TARGET || 'chrome';
1010

1111
function generateManifest() {
1212
const manifest = readJsonFile('src/manifest.json');
@@ -43,8 +43,8 @@ export default defineConfig(({ mode }) => ({
4343
__EXTENSION_MODE__: JSON.stringify(mode),
4444
__DEV__: mode === 'development',
4545
__PROD__: mode === 'production',
46-
__EXTENSION_VERSION__: JSON.stringify(pkg.version),
47-
__REAL_APP_ID__: APPID_CHROME,
46+
__APP_ID__: JSON.stringify(APPID_CHROME),
47+
__BROWSER__: JSON.stringify(browser),
4848
},
4949
plugins: [
5050
vue(),

0 commit comments

Comments
 (0)