@@ -6,13 +6,13 @@ import path from "path"
66import { getPort } from "@plasmohq/messaging/background"
77import { Storage } from "@plasmohq/storage"
88
9- import {
10- requestServerSelection
11- } from "~background/messages/api/select-server"
9+ import { requestServerSelection } from "~background/messages/api/select-server"
1210import { skip as pressToSkip } from "~background/messages/api/skip"
1311import { STORAGE_SETTINGS } from "~constants"
1412import { getFullUrl } from "~options/components/RemoteSettings"
1513import { defaultSettings , type Settings } from "~options/types"
14+ import type { Server } from "~types"
15+ import { getMergedSettings } from "~util/settings"
1616
1717export { }
1818
@@ -78,8 +78,8 @@ const storage = new Storage()
7878let settingsCache = defaultSettings
7979let isRunningCache = false
8080async function refreshSettings ( ) : Promise < Settings > {
81- const settings =
82- ( await storage . get < Settings > ( STORAGE_SETTINGS ) ) || defaultSettings
81+ const storedSettings = await storage . get < Settings > ( STORAGE_SETTINGS )
82+ const settings = getMergedSettings ( storedSettings )
8383 settingsCache = settings
8484 return settings
8585}
@@ -292,7 +292,10 @@ function handleRemoteDownload(
292292 settings : Settings
293293) : Function | undefined {
294294 // If only one server, no servers, or manual selection is disabled, use existing logic
295- if ( settings . remote . servers . length <= 1 || ! settings . remote . requireManualSelection ) {
295+ if (
296+ settings . remote . servers . length <= 1 ||
297+ ! settings . remote . requireManualSelection
298+ ) {
296299 const server = settings . remote . servers . find (
297300 ( server ) => getFullUrl ( server ) === settings . remote . selectedServer
298301 )
@@ -306,7 +309,10 @@ function handleRemoteDownload(
306309 return async ( ) => {
307310 try {
308311 // Show server selector overlay
309- const tabs = await chrome . tabs . query ( { active : true , currentWindow : true } )
312+ const tabs = await chrome . tabs . query ( {
313+ active : true ,
314+ currentWindow : true
315+ } )
310316 if ( tabs . length === 0 ) {
311317 // Fallback to default server if no active tab
312318 const defaultServer = settings . remote . servers . find (
@@ -355,8 +361,12 @@ function handleRemoteDownload(
355361
356362 if ( selectedServer ) {
357363 // Execute download task and get result
358- const downloadSuccess = await executeDownloadTask ( info , selectedServer , settings )
359-
364+ const downloadSuccess = await executeDownloadTask (
365+ info ,
366+ selectedServer ,
367+ settings
368+ )
369+
360370 // Send result back to content script to handle popup closure
361371 await chrome . tabs . sendMessage ( tabId , {
362372 name : "download-result" ,
@@ -392,7 +402,7 @@ async function executeDownloadTask(
392402 let notificationTitle : string
393403 let notificationMessage : string
394404 let success = false
395-
405+
396406 try {
397407 await client . createTask ( {
398408 req : await toCreateRequest ( info )
@@ -411,16 +421,17 @@ async function executeDownloadTask(
411421 )
412422 success = false
413423 }
414-
415- if ( settings . remote . notification ) {
424+
425+ // Show notification based on confirmBeforeDownload setting
426+ if ( settings . confirmBeforeDownload || ! success ) {
416427 const port = getPort ( "notify" )
417428 port . postMessage ( {
418429 type : notificationType ,
419430 title : notificationTitle ,
420431 message : notificationMessage
421432 } )
422433 }
423-
434+
424435 return success
425436}
426437
@@ -456,7 +467,9 @@ function createDownloadTask(
456467 )
457468 success = false
458469 }
459- if ( settings . remote . notification ) {
470+
471+ // Show notification based on confirmBeforeDownload setting or if there's an error
472+ if ( settings . confirmBeforeDownload || ! success ) {
460473 const port = getPort ( "notify" )
461474 port . postMessage ( {
462475 type : notificationType ,
@@ -470,6 +483,7 @@ function createDownloadTask(
470483
471484interface HostRequest < T > {
472485 method : string
486+ meta ?: Record < string , any >
473487 params ?: T
474488}
475489
@@ -496,14 +510,34 @@ function handleNativeDownload(
496510 try {
497511 await connectNativeAndPost < string > ( {
498512 method : "create" ,
513+ meta : {
514+ silent : ! settings . confirmBeforeDownload
515+ } ,
499516 params : btoa (
500517 JSON . stringify ( {
501518 req
502519 } )
503520 )
504521 } )
522+
523+ if ( ! settings . confirmBeforeDownload ) {
524+ const port = getPort ( "notify" )
525+ port . postMessage ( {
526+ type : "success" ,
527+ title : chrome . i18n . getMessage ( "notification_create_success" ) ,
528+ message : chrome . i18n . getMessage ( "notification_native_success_message" )
529+ } )
530+ }
505531 } catch ( e ) {
506532 console . error ( e )
533+ if ( ! settings . confirmBeforeDownload ) {
534+ const port = getPort ( "notify" )
535+ port . postMessage ( {
536+ type : "error" ,
537+ title : chrome . i18n . getMessage ( "notification_create_error" ) ,
538+ message : chrome . i18n . getMessage ( "notification_native_error_message" )
539+ } )
540+ }
507541 }
508542 }
509543}
0 commit comments