mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-02-02 02:58:13 -05:00
Use browser.downloads.download to export files if available.
This commit is contained in:
parent
8d040f9402
commit
35cdb7ed6b
@ -5,7 +5,13 @@ window.OmegaDebug =
|
||||
chrome.runtime.getManifest().version
|
||||
downloadLog: ->
|
||||
blob = new Blob [localStorage['log']], {type: "text/plain;charset=utf-8"}
|
||||
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
|
||||
filename = "OmegaLog_#{Date.now()}.txt"
|
||||
|
||||
if browser?.downloads?.download?
|
||||
url = URL.createObjectURL(blob)
|
||||
browser.downloads.download({url: url, filename: filename})
|
||||
else
|
||||
saveAs(blob, filename)
|
||||
resetOptions: ->
|
||||
localStorage.clear()
|
||||
# Prevent options loading from sync storage after reload.
|
||||
|
@ -34,6 +34,7 @@
|
||||
"alarms",
|
||||
"storage",
|
||||
"webRequest",
|
||||
"downloads",
|
||||
"webRequestBlocking",
|
||||
"contextMenus",
|
||||
|
||||
|
@ -66,12 +66,14 @@ angular.module('omega').config ($stateProvider, $urlRouterProvider,
|
||||
controller: 'AboutCtrl'
|
||||
)
|
||||
|
||||
angular.module('omega').factory 'omegaDebug', ($window, $rootScope) ->
|
||||
angular.module('omega').factory 'omegaDebug', ($window, $rootScope,
|
||||
$injector) ->
|
||||
omegaDebug = $window.OmegaDebug ? {}
|
||||
|
||||
omegaDebug.downloadLog ?= ->
|
||||
downloadFile = $injector.get('downloadFile') ? saveAs
|
||||
blob = new Blob [localStorage['log']], {type: "text/plain;charset=utf-8"}
|
||||
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
|
||||
downloadFile(blob, "OmegaLog_#{Date.now()}.txt")
|
||||
|
||||
omegaDebug.reportIssue ?= ->
|
||||
$window.open(
|
||||
@ -82,3 +84,14 @@ angular.module('omega').factory 'omegaDebug', ($window, $rootScope) ->
|
||||
$rootScope.resetOptions()
|
||||
|
||||
omegaDebug
|
||||
|
||||
angular.module('omega').factory 'downloadFile', ->
|
||||
if browser?.downloads?.download?
|
||||
return (blob, filename) ->
|
||||
url = URL.createObjectURL(blob)
|
||||
if filename
|
||||
browser.downloads.download({url: url, filename: filename})
|
||||
else
|
||||
browser.downloads.download({url: url})
|
||||
else
|
||||
return saveAs
|
||||
|
@ -1,5 +1,5 @@
|
||||
angular.module('omega').controller 'IoCtrl', ($scope, $rootScope,
|
||||
$window, $http, omegaTarget) ->
|
||||
$window, $http, omegaTarget, downloadFile) ->
|
||||
|
||||
omegaTarget.state('web.restoreOnlineUrl').then (url) ->
|
||||
if url
|
||||
@ -10,7 +10,7 @@ angular.module('omega').controller 'IoCtrl', ($scope, $rootScope,
|
||||
plainOptions = angular.fromJson(angular.toJson($rootScope.options))
|
||||
content = JSON.stringify(plainOptions)
|
||||
blob = new Blob [content], {type: "text/plain;charset=utf-8"}
|
||||
saveAs(blob, "OmegaOptions.bak")
|
||||
downloadFile(blob, "OmegaOptions.bak")
|
||||
|
||||
$scope.importSuccess = ->
|
||||
$rootScope.showAlert(
|
||||
|
@ -1,7 +1,7 @@
|
||||
angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
|
||||
$q, $modal, $state, profileColors, profileIcons, omegaTarget,
|
||||
$timeout, $location, $filter, getAttachedName, isProfileNameReserved,
|
||||
isProfileNameHidden, dispNameFilter) ->
|
||||
isProfileNameHidden, dispNameFilter, downloadFile) ->
|
||||
|
||||
tr = $filter('tr')
|
||||
|
||||
@ -42,7 +42,7 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
|
||||
pac = OmegaPac.PacGenerator.ascii(pac)
|
||||
blob = new Blob [pac], {type: "text/plain;charset=utf-8"}
|
||||
fileName = profileName.replace(/\W+/g, '_')
|
||||
saveAs(blob, "OmegaProfile_#{fileName}.pac")
|
||||
downloadFile(blob, "OmegaProfile_#{fileName}.pac")
|
||||
if missingProfile
|
||||
$timeout ->
|
||||
$rootScope.showAlert(
|
||||
|
@ -1,6 +1,6 @@
|
||||
angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
|
||||
$location, $timeout, $q, $modal, profileIcons, getAttachedName, omegaTarget,
|
||||
trFilter) ->
|
||||
trFilter, downloadFile) ->
|
||||
# == Rule list ==
|
||||
$scope.ruleListFormats = OmegaPac.Profiles.ruleListFormats
|
||||
|
||||
@ -20,7 +20,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
|
||||
|
||||
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
|
||||
fileName = $scope.profile.name.replace(/\W+/g, '_')
|
||||
saveAs(blob, "OmegaRules_#{fileName}.sorl")
|
||||
downloadFile(blob, "OmegaRules_#{fileName}.sorl")
|
||||
|
||||
exportLegacyRuleList = ->
|
||||
wildcardRules = ''
|
||||
@ -52,7 +52,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
|
||||
"""
|
||||
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
|
||||
fileName = $scope.profile.name.replace(/\W+/g, '_')
|
||||
saveAs(blob, "SwitchyRules_#{fileName}.ssrl")
|
||||
downloadFile(blob, "SwitchyRules_#{fileName}.ssrl")
|
||||
|
||||
# == Condition types ==
|
||||
$scope.conditionHelp =
|
||||
|
Loading…
Reference in New Issue
Block a user