Skip to content

Commit 017c829

Browse files
committed
Not display icons of website in Safari (#152)
1 parent 6639ed8 commit 017c829

File tree

6 files changed

+81
-20
lines changed

6 files changed

+81
-20
lines changed

src/app/components/common/host-alert.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8+
import { IS_SAFARI } from "@util/constant/environment"
89
import { ElLink } from "element-plus"
910
import { computed, ComputedRef, defineComponent, h } from "vue"
1011

@@ -39,20 +40,27 @@ const _default = defineComponent({
3940
const href: ComputedRef<string> = computed(() => props.clickable ? `http://${props.host}` : '')
4041
const target: ComputedRef<string> = computed(() => props.clickable ? '_blank' : '')
4142
const cursor: ComputedRef<string> = computed(() => props.clickable ? "cursor" : "default")
42-
return () => h('div', [
43-
h(ElLink,
44-
{
45-
href: href.value,
46-
target: target.value,
47-
underline: props.clickable,
48-
style: { cursor: cursor.value }
49-
},
50-
() => props.host
51-
), h('span',
52-
{ style: HOST_ICON_STYLE },
53-
h('img', { src: props.iconUrl, width: 12, height: 12 })
54-
)
55-
])
43+
return IS_SAFARI
44+
? () => h(ElLink, {
45+
href: href.value,
46+
target: target.value,
47+
underline: props.clickable,
48+
style: { cursor: cursor.value }
49+
}, () => props.host)
50+
: () => h('div', [
51+
h(ElLink,
52+
{
53+
href: href.value,
54+
target: target.value,
55+
underline: props.clickable,
56+
style: { cursor: cursor.value }
57+
},
58+
() => props.host
59+
), h('span',
60+
{ style: HOST_ICON_STYLE },
61+
h('img', { src: props.iconUrl, width: 12, height: 12 })
62+
)
63+
])
5664
}
5765
})
5866

src/app/components/report/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useRoute, useRouter } from "vue-router"
2727
import { groupBy, sum } from "@util/array"
2828
import { formatTime } from "@util/time"
2929
import TimerDatabase from "@db/timer-database"
30+
import { IS_SAFARI } from "@util/constant/environment"
3031

3132
const timerDatabase = new TimerDatabase(chrome.storage.local)
3233

@@ -38,7 +39,7 @@ async function queryData(
3839
) {
3940
const loading = ElLoadingService({ target: `.container-card>.el-card__body`, text: "LOADING..." })
4041
const pageInfo = { size: page.size, num: page.num }
41-
const fillFlag = { alias: true, iconUrl: true }
42+
const fillFlag = { alias: true, iconUrl: !IS_SAFARI }
4243
const param = {
4344
...queryParam.value,
4445
inclusiveRemote: readRemote.value

src/background/icon-and-alias-collector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import HostAliasDatabase from "@db/host-alias-database"
99
import IconUrlDatabase from "@db/icon-url-database"
1010
import OptionDatabase from "@db/option-database"
11-
import { IS_CHROME } from "@util/constant/environment"
11+
import { IS_CHROME, IS_SAFARI } from "@util/constant/environment"
1212
import { iconUrlOfBrowser } from "@util/constant/url"
1313
import { extractHostname, isBrowserUrl, isHomepage } from "@util/pattern"
1414
import { defaultStatistics } from "@util/constant/option"
@@ -51,7 +51,7 @@ async function processTabInfo(tab: chrome.tabs.Tab): Promise<void> {
5151
// localhost hosts with Chrome use cache, so keep the favIcon url undefined
5252
IS_CHROME && /^localhost(:.+)?/.test(host) && (favIconUrl = undefined)
5353
const iconUrl = favIconUrl || iconUrlOfBrowser(protocol, host)
54-
iconUrlDatabase.put(host, iconUrl)
54+
iconUrl && iconUrlDatabase.put(host, iconUrl)
5555
collectAliasEnabled && !isBrowserUrl(url) && isHomepage(url) && collectAlias(host, tab.title)
5656
}
5757

@@ -67,7 +67,7 @@ function handleWebNavigationCompleted(detail: chrome.webNavigation.WebNavigation
6767
}
6868

6969
function listen() {
70-
chrome.webNavigation.onCompleted.addListener(handleWebNavigationCompleted)
70+
!IS_SAFARI && chrome.webNavigation.onCompleted.addListener(handleWebNavigationCompleted)
7171
}
7272

7373
/**

src/popup/components/chart/option.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { formatPeriodCommon, formatTime } from "@util/time"
1818
import { t } from "@popup/locale"
1919
import { getPrimaryTextColor, getSecondaryTextColor } from "@util/style"
2020
import { generateSiteLabel } from "@util/site"
21+
import { IS_SAFARI } from "@util/constant/environment"
2122

2223
type EcOption = ComposeOption<
2324
| PieSeriesOption
@@ -75,7 +76,10 @@ function labelFormatter({ mergeHost }: timer.popup.QueryResult, params: any): st
7576
const format = params instanceof Array ? params[0] : params
7677
const { name } = format
7778
const data = format.data as timer.popup.Row
78-
return mergeHost || data.isOther ? name : `{${legend2LabelStyle(name)}|} {a|${name}}`
79+
// Un-supported to get favicon url in Safari
80+
return mergeHost || data.isOther || IS_SAFARI
81+
? name
82+
: `{${legend2LabelStyle(name)}|} {a|${name}}`
7983
}
8084

8185
const staticOptions: EcOption = {

src/popup/components/footer/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import { t } from "@popup/locale"
2020
import { locale } from "@util/i18n"
2121
import { getDayLenth, getMonthTime, getWeekDay, getWeekTime, MILL_PER_DAY } from "@util/time"
2222
import optionService from "@service/option-service"
23+
import { IS_SAFARI } from "@util/constant/environment"
2324

2425
type FooterParam = TimerQueryParam & {
2526
chartTitle: string
2627
}
2728

28-
const FILL_FLAG_PARAM: FillFlagParam = { iconUrl: true, alias: true }
29+
const FILL_FLAG_PARAM: FillFlagParam = { iconUrl: !IS_SAFARI, alias: true }
2930

3031
function calculateDateRange(duration: timer.popup.Duration, weekStart: timer.option.WeekStartOption): Date | Date[] {
3132
const now = new Date()

webpack/webpack.prod.safari.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import path from "path"
2+
import optionGenerator from "./webpack.common"
3+
import FileManagerWebpackPlugin from "filemanager-webpack-plugin"
4+
import webpack from "webpack"
5+
6+
const { name, version } = require(path.join(__dirname, '..', 'package.json'))
7+
8+
const outputDir = path.join(__dirname, '..', 'dist_prod_safari')
9+
const normalZipFilePath = path.resolve(__dirname, '..', 'market_packages', `${name}-${version}-safari.zip`)
10+
11+
function removeUnsupportedProperties(manifest: Partial<chrome.runtime.ManifestV2>) {
12+
// 1. permissions. 'idle' is not supported
13+
const originPermissions = manifest.permissions || []
14+
const unsupported = ['idle']
15+
const supported = []
16+
originPermissions.forEach(perm => !unsupported.includes(perm) && supported.push(perm))
17+
manifest.permissions = supported
18+
}
19+
20+
const options = optionGenerator(
21+
outputDir,
22+
baseManifest => {
23+
baseManifest.name = 'Timer'
24+
// Remove unsupported properties in Safari
25+
removeUnsupportedProperties(baseManifest)
26+
}
27+
)
28+
29+
const filemanagerWebpackPlugin = new FileManagerWebpackPlugin({
30+
events: {
31+
// Archive at the end
32+
onEnd: [
33+
{ delete: [path.join(outputDir, '*.LICENSE.txt')] },
34+
// Define plugin to archive zip for different markets
35+
{
36+
delete: [normalZipFilePath],
37+
archive: [{ source: outputDir, destination: normalZipFilePath }]
38+
}
39+
]
40+
}
41+
})
42+
43+
options.mode = 'production'
44+
options.plugins.push(filemanagerWebpackPlugin as webpack.WebpackPluginInstance)
45+
options.output.path = outputDir
46+
47+
export default options

0 commit comments

Comments
 (0)