Skip to content

Commit d293d1f

Browse files
chore: update support notice (#148)
1 parent 92343b8 commit d293d1f

File tree

7 files changed

+58
-33
lines changed

7 files changed

+58
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ build
88
src/renderer/types/auto-imports.d.ts
99
src/renderer/types/components.d.ts
1010
*.log
11+
*.local

config/electron-builder.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
/* eslint-disable no-template-curly-in-string */
12
import type { Configuration } from 'electron-builder'
23
import path from 'path'
34

5+
const isSponsored = process.env.VITE_SPONSORED === 'true'
6+
7+
const artifactName = isSponsored
8+
? '${productName}-${version}-${arch}-sponsored.${ext}'
9+
: undefined
10+
411
export default {
512
appId: 'io.masscode.app',
13+
artifactName,
614
productName: 'massCode',
715
directories: {
816
output: path.resolve(__dirname, '../../dist')

src/main/store/module/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default new Store<AppStore>({
99
bounds: {},
1010
sidebarWidth: 180,
1111
snippetListWidth: 250,
12-
sort: 'updatedAt',
13-
notifySupport: false
12+
sort: 'updatedAt'
1413
}
1514
})

src/renderer/App.vue

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
:class="{ 'is-win': appStore.platform === 'win32' }"
55
/>
66
<RouterView />
7-
<div
8-
v-if="isUpdateAvailable"
9-
class="update"
10-
@click="onClickUpdate"
11-
>
12-
<span> Update available </span>
7+
<div class="top-notification">
8+
<span
9+
v-if="!appStore.isSponsored && !isUpdateAvailable"
10+
class="unsponsored"
11+
>
12+
Unsponsored
13+
</span>
14+
<span
15+
v-if="isUpdateAvailable"
16+
class="update"
17+
@click="onClickUpdate"
18+
>
19+
Update available
20+
</span>
1321
</div>
1422
</template>
1523

@@ -32,7 +40,7 @@ import {
3240
import { createToast, destroyAllToasts } from 'vercel-toast'
3341
import { useRoute } from 'vue-router'
3442
import type { Snippet } from '@shared/types/main/db'
35-
import { addDays, isSameDay } from 'date-fns'
43+
import { addDays, isSameDay, isYesterday } from 'date-fns'
3644
3745
// По какой то причине необходимо явно установить роут в '/'
3846
// для корректного поведения в продакшен сборке
@@ -69,7 +77,6 @@ const init = () => {
6977
7078
if (!dateInstallation) {
7179
store.app.set('dateInstallation', new Date().valueOf())
72-
store.app.set('notifySupport', false)
7380
}
7481
7582
trackAppUpdate()
@@ -96,49 +103,51 @@ const trackAppUpdate = () => {
96103
store.app.set('version', appStore.version)
97104
}
98105
106+
// Yes, this is that annoying piece of crap code.
107+
// You can delete it, but know that you hurt me.
99108
const showSupportToast = () => {
100-
if (store.app.get('notifySupport')) return
109+
if (appStore.isSponsored) return
101110
102-
const dateInstallation = store.app.get('dateInstallation')
103-
const dateToNotify = addDays(dateInstallation, 7)
104-
const isShow = isSameDay(new Date(), dateToNotify)
111+
const addNextNotice = () => {
112+
store.app.set('nextSupportNotice', addDays(new Date(), 7).valueOf())
113+
}
114+
115+
const date = store.app.get('nextSupportNotice')
116+
117+
if (!date) addNextNotice()
118+
119+
const isShow = isSameDay(new Date(), date) || isYesterday(date)
105120
106121
if (!isShow) return
107122
if (isSupportToastShow.value) return
108123
109124
const message = document.createElement('div')
110125
message.innerHTML = `Hi, Anton here 👋<br><br>
111-
I need your support. If you find this app useful, please give a star on <a class="github" href="#">github</a> or <a class="opencollective" href="#">donate</a>. It will inspire me to continue development on the project.`
126+
Thanks for using massCode. If you find this app useful, please <a id="donate" href="#">donate</a>. It will inspire me to continue development on the project.`
112127
113128
createToast(message, {
114129
action: {
115130
text: 'Close',
116131
callback (toast) {
117132
toast.destroy()
118-
store.app.set('notifySupport', true)
133+
addNextNotice()
134+
isSupportToastShow.value = false
119135
track('app/notify', 'support-close')
120136
}
121137
}
122138
})
123139
124-
isSupportToastShow.value = true
125-
126-
const g = document.querySelector('.github')
127-
const o = document.querySelector('.opencollective')
140+
const d = document.querySelector('#donate')
128141
129-
g?.addEventListener('click', () => {
130-
ipc.invoke('main:open-url', 'https://github.com/massCodeIO/massCode')
131-
store.app.set('notifySupport', true)
142+
d?.addEventListener('click', () => {
143+
ipc.invoke('main:open-url', 'https://masscode.io/donate')
132144
destroyAllToasts()
133-
track('app/notify', 'support-go-to-github')
145+
addNextNotice()
146+
isSupportToastShow.value = false
147+
track('app/notify', 'support-go-to-masscode')
134148
})
135149
136-
o?.addEventListener('click', () => {
137-
ipc.invoke('main:open-url', 'https://opencollective.com/masscode')
138-
store.app.set('notifySupport', true)
139-
destroyAllToasts()
140-
track('app/notify', 'support-go-to-opencollective')
141-
})
150+
isSupportToastShow.value = true
142151
}
143152
144153
init()
@@ -249,14 +258,18 @@ body {
249258
}
250259
}
251260
}
252-
.update {
261+
.top-notification {
253262
position: absolute;
254263
top: 5px;
255264
right: var(--spacing-sm);
256265
z-index: 1020;
257266
text-transform: uppercase;
258-
font-size: 11px;
267+
font-size: 10px;
259268
font-weight: bold;
269+
display: flex;
270+
gap: var(--spacing-sm);
271+
}
272+
.update {
260273
background: -webkit-linear-gradient(60deg, var(--color-primary), limegreen);
261274
-webkit-background-clip: text;
262275
-webkit-text-fill-color: transparent;

src/renderer/store/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ const CODE_PREVIEW_DEFAULTS: CodePreviewSettings = {
3434
darkMode: false
3535
}
3636

37+
console.log(import.meta.env.VITE_SPONSORED)
38+
3739
export const useAppStore = defineStore('app', {
3840
state: (): State => ({
3941
isInit: false,
42+
isSponsored: import.meta.env.VITE_SPONSORED === 'true',
4043
theme: 'light:chrome',
4144
showTags: true,
4245
sizes: {

src/shared/types/main/store.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { SnippetsSort } from './db'
44
export interface AppStore {
55
bounds: object
66
dateInstallation?: number
7-
notifySupport: boolean
7+
nextSupportNotice?: number
88
selectedFolderAlias?: string
99
selectedFolderId?: string
1010
selectedFolderIds?: string[]

src/shared/types/renderer/store/app.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ export interface State {
7070
screenshot: ScreenshotSettings
7171
codePreview: CodePreviewSettings
7272
isInit: boolean
73+
isSponsored: boolean
7374
}

0 commit comments

Comments
 (0)