Ejemplo n.º 1
0
    persepolis_tmp = os.path.join(str(home_address), 'AppData', 'Local',
                                  'persepolis_tmp')

# removing persepolis_tmp at persepolis startup
osCommands.removeDir(persepolis_tmp)

# persepolis_shutdown
persepolis_shutdown = os.path.join(persepolis_tmp, 'shutdown')
# shutil.rmtree(persepolis_shutdown, ignore_errors=True, onerror=None)

# creating folders
for folder in [
        config_folder, download_info_folder, persepolis_tmp, category_folder,
        queue_info_folder, persepolis_shutdown
]:
    osCommands.makeDirs(folder)

# creating files
for file in [
        queues_list, download_list_file, download_list_file_active,
        single_downloads_list_file
]:
    osCommands.touch(file)

# lock files perventing to access a file simultaneously

# removing lock files in starting persepolis
pattern_folder_list = [
    config_folder, download_info_folder, category_folder, queue_info_folder
]
Ejemplo n.º 2
0
    def okPushButtonPressed(self, button):

        self.persepolis_setting.beginGroup('settings')

        self.persepolis_setting.setValue('max-tries',
                                         self.tries_spinBox.value())
        self.persepolis_setting.setValue('retry-wait',
                                         self.wait_spinBox.value())
        self.persepolis_setting.setValue('timeout',
                                         self.time_out_spinBox.value())
        self.persepolis_setting.setValue('connections',
                                         self.connections_spinBox.value())
        self.persepolis_setting.setValue('rpc-port',
                                         self.rpc_port_spinbox.value())
        self.persepolis_setting.setValue('download_path',
                                         self.download_folder_lineEdit.text())
        self.persepolis_setting.setValue('download_path_temp',
                                         self.temp_download_lineEdit.text())
        self.persepolis_setting.setValue('sound-volume',
                                         self.volume_dial.value())
        self.persepolis_setting.setValue(
            'notification', self.notification_comboBox.currentText())

        #changing icons

        icons = self.icon_comboBox.currentText()
        self.persepolis_setting.setValue('icons', icons)

        if icons != self.current_icon:  #it means icons changed

            for list in [
                    self.parent.browser_integration_window_list,
                    self.parent.about_window_list,
                    self.parent.addlinkwindows_list,
                    self.parent.propertieswindows_list,
                    self.parent.afterdownload_list,
                    self.parent.text_queue_window_list,
                    self.parent.progress_window_list
            ]:
                for window in list:
                    window.changeIcon(icons)

            self.parent.changeIcon(icons)

#style
        style = str(self.style_comboBox.currentText())
        self.persepolis_setting.setValue('style', style)

        if style != self.grandparent.persepolis_style:  #if style changed,then set new style
            self.grandparent.setPersepolisStyle(style)

#color_scheme
        color_scheme = self.color_comboBox.currentText()
        self.persepolis_setting.setValue('color-scheme', color_scheme)

        if color_scheme != self.grandparent.persepolis_color_scheme:  #if color_scheme changed , then set new color_scheme
            self.grandparent.setPersepolisColorScheme(color_scheme)

#font and font size
        current_font = self.fontComboBox.currentFont()
        current_font = current_font.key()
        current_font = current_font.split(',')
        font = str(current_font[0])
        self.persepolis_setting.setValue('font', font)

        font_size = self.font_size_spinBox.value()
        self.persepolis_setting.setValue('font-size', font_size)

        if self.grandparent.persepolis_font != font or int(
                self.grandparent.persepolis_font_size) != int(
                    font_size
                ):  #if font or font_size changed,set new font , font_size
            self.grandparent.setPersepolisFont(font, int(font_size))
            self.grandparent.setPersepolisStyle(style)
            self.grandparent.setPersepolisColorScheme(color_scheme)

#if user select qt notification  >> enable_system_tray icon
        if self.persepolis_setting.value('notification') == 'QT notification':
            self.enable_system_tray_checkBox.setChecked(True)

#enable_system_tray_checkBox
        if self.enable_system_tray_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('tray-icon', 'yes')
            self.parent.system_tray_icon.show()
            self.parent.minimizeAction.setEnabled(True)
            self.parent.trayAction.setChecked(True)
        else:
            self.persepolis_setting.setValue('tray-icon', 'no')
            self.parent.system_tray_icon.hide()
            self.parent.minimizeAction.setEnabled(False)
            self.parent.trayAction.setChecked(False)

#after_download_checkBox
        if self.after_download_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('after-dialog', 'yes')
        else:
            self.persepolis_setting.setValue('after-dialog', 'no')

#show_menubar_checkbox
        if self.show_menubar_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show-menubar', 'yes')
            self.parent.menubar.show()
            self.parent.toolBar2.hide()

        else:
            self.persepolis_setting.setValue('show-menubar', 'no')
            self.parent.menubar.hide()
            self.parent.toolBar2.show()

#show_sidepanel_checkbox
        if self.show_sidepanel_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show_sidepanel', 'yes')
            self.parent.category_tree_qwidget.show()
        else:
            self.persepolis_setting.setValue('show_sidepanel', 'no')
            self.parent.category_tree_qwidget.hide()

#show_progress_window_checkbox
        if self.show_progress_window_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show-progress', 'yes')
        else:
            self.persepolis_setting.setValue('show-progress', 'no')

        if self.startup_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('startup', 'yes')

            if not (startup.checkstartup()
                    ):  #checking existance of Persepolis in  system's startup

                startup.addstartup()  #adding Persepolis to system's startup
        else:
            self.persepolis_setting.setValue('startup', 'no')

            if startup.checkstartup(
            ):  #checking existance of Persepolis in  system's startup

                startup.removestartup(
                )  #removing Persepolis from system's startup

#this section  creates temporary download folder and download folder and download sub folders if they did not existed.
        download_path_temp = self.persepolis_setting.value(
            'download_path_temp')
        download_path = self.persepolis_setting.value('download_path')
        folder_list = [download_path_temp]
        for folder in [
                'Audios', 'Videos', 'Others', 'Documents', 'Compressed'
        ]:
            folder_list.append(os.path.join(download_path, folder))

        for folder in folder_list:
            osCommands.makeDirs(folder)

        if self.enable_notifications_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('sound', 'yes')
        else:
            self.persepolis_setting.setValue('sound', 'no')

        #applying changes
        self.persepolis_setting.endGroup()
        self.persepolis_setting.sync()
        self.close()
Ejemplo n.º 3
0
    def okPushButtonPressed(self, button):

        self.persepolis_setting.beginGroup('settings')

        self.persepolis_setting.setValue('max-tries',
                                         self.tries_spinBox.value())
        self.persepolis_setting.setValue('retry-wait',
                                         self.wait_spinBox.value())
        self.persepolis_setting.setValue('timeout',
                                         self.time_out_spinBox.value())
        self.persepolis_setting.setValue('connections',
                                         self.connections_spinBox.value())
        self.persepolis_setting.setValue('rpc-port',
                                         self.rpc_port_spinbox.value())
        self.persepolis_setting.setValue('download_path',
                                         self.download_folder_lineEdit.text())
        self.persepolis_setting.setValue('download_path_temp',
                                         self.temp_download_lineEdit.text())
        self.persepolis_setting.setValue('sound-volume',
                                         self.volume_dial.value())
        self.persepolis_setting.setValue(
            'notification', self.notification_comboBox.currentText())

        # changing icons

        icons = self.icon_comboBox.currentText()
        self.persepolis_setting.setValue('icons', icons)

        if icons != self.current_icon:  # it means icons changed

            for list in [
                    self.parent.browser_integration_window_list,
                    self.parent.about_window_list,
                    self.parent.addlinkwindows_list,
                    self.parent.propertieswindows_list,
                    self.parent.afterdownload_list,
                    self.parent.text_queue_window_list,
                    self.parent.progress_window_list
            ]:
                for window in list:
                    window.changeIcon(icons)

            self.parent.changeIcon(icons)

# style
        style = str(self.style_comboBox.currentText())
        self.persepolis_setting.setValue('style', style)

        if style != self.grandparent.persepolis_style:  # if style changed,then set new style
            self.grandparent.setPersepolisStyle(style)

# color_scheme
        color_scheme = self.color_comboBox.currentText()
        self.persepolis_setting.setValue('color-scheme', color_scheme)

        # if color_scheme changed , then set new color_scheme
        if color_scheme != self.grandparent.persepolis_color_scheme:
            self.grandparent.setPersepolisColorScheme(color_scheme)

# font and font size

        current_font = self.fontComboBox.currentFont()
        current_font = current_font.key()
        current_font = current_font.split(',')
        font = str(current_font[0])
        self.persepolis_setting.setValue('font', font)

        font_size = self.font_size_spinBox.value()
        self.persepolis_setting.setValue('font-size', font_size)

        if self.font_checkBox.isChecked():
            custom_font = 'yes'
            # if font or font_size changed,set new font , font_size
            if self.grandparent.persepolis_font != font or int(
                    self.grandparent.persepolis_font_size) != int(font_size):
                self.grandparent.setPersepolisFont(font, int(font_size),
                                                   custom_font)
                self.grandparent.setPersepolisStyle(style)
                self.grandparent.setPersepolisColorScheme(color_scheme)
        else:
            custom_font = 'no'

        self.persepolis_setting.setValue('custom-font', custom_font)
        # if user select qt notification  >> enable_system_tray icon
        if self.persepolis_setting.value('notification') == 'QT notification':
            self.enable_system_tray_checkBox.setChecked(True)

# enable_system_tray_checkBox
        if self.enable_system_tray_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('tray-icon', 'yes')
            self.parent.system_tray_icon.show()
            self.parent.minimizeAction.setEnabled(True)
            self.parent.trayAction.setChecked(True)
        else:
            self.persepolis_setting.setValue('tray-icon', 'no')
            self.parent.system_tray_icon.hide()
            self.parent.minimizeAction.setEnabled(False)
            self.parent.trayAction.setChecked(False)

# after_download_checkBox
        if self.after_download_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('after-dialog', 'yes')
        else:
            self.persepolis_setting.setValue('after-dialog', 'no')

# show_menubar_checkbox
        if self.show_menubar_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show-menubar', 'yes')
            self.parent.menubar.show()
            self.parent.toolBar2.hide()
            self.parent.showMenuBarAction.setChecked(True)

        else:
            self.persepolis_setting.setValue('show-menubar', 'no')
            self.parent.menubar.hide()
            self.parent.toolBar2.show()
            self.parent.showMenuBarAction.setChecked(False)

# show_sidepanel_checkbox
        if self.show_sidepanel_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show_sidepanel', 'yes')
            self.parent.category_tree_qwidget.show()
        else:
            self.persepolis_setting.setValue('show_sidepanel', 'no')
            self.parent.category_tree_qwidget.hide()

# show_progress_window_checkbox
        if self.show_progress_window_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('show-progress', 'yes')
        else:
            self.persepolis_setting.setValue('show-progress', 'no')

        if self.startup_checkbox.isChecked() == True:
            self.persepolis_setting.setValue('startup', 'yes')

            if not (startup.checkstartup()
                    ):  # checking existance of Persepolis in  system's startup

                startup.addstartup()  # adding Persepolis to system's startup
        else:
            self.persepolis_setting.setValue('startup', 'no')

            if startup.checkstartup(
            ):  # checking existance of Persepolis in  system's startup

                startup.removestartup(
                )  # removing Persepolis from system's startup

# keep_awake_checkBox
        if self.keep_awake_checkBox.isChecked():
            self.persepolis_setting.setValue('awake', 'yes')
            self.parent.keep_awake_checkBox.setChecked(True)
        else:
            self.persepolis_setting.setValue('awake', 'no')
            self.parent.keep_awake_checkBox.setChecked(False)

# this section  creates temporary download folder and download folder and
# download sub folders if they did not existed.

        download_path_temp = self.persepolis_setting.value(
            'download_path_temp')
        download_path = self.persepolis_setting.value('download_path')

        folder_list = [download_path_temp, download_path]

        if self.subfolder_checkBox.isChecked():
            self.persepolis_setting.setValue('subfolder', 'yes')

            for folder in [
                    'Audios', 'Videos', 'Others', 'Documents', 'Compressed'
            ]:
                folder_list.append(os.path.join(download_path, folder))

        else:
            self.persepolis_setting.setValue('subfolder', 'no')

        for folder in folder_list:
            osCommands.makeDirs(folder)

        if self.enable_notifications_checkBox.isChecked() == True:
            self.persepolis_setting.setValue('sound', 'yes')
        else:
            self.persepolis_setting.setValue('sound', 'no')

# columns_tab
        if self.column0_checkBox.isChecked():
            self.persepolis_setting.setValue('column0', 'yes')
            self.parent.download_table.setColumnHidden(0, False)

            if self.parent.download_table.isColumnHidden(0):
                self.parent.download_table.setColumnWidth(0, 100)

        else:
            self.persepolis_setting.setValue('column0', 'no')
            self.parent.download_table.setColumnHidden(0, True)

        if self.column1_checkBox.isChecked():
            self.persepolis_setting.setValue('column1', 'yes')
            self.parent.download_table.setColumnHidden(1, False)

            if self.parent.download_table.isColumnHidden(1):
                self.parent.download_table.setColumnWidth(1, 100)

        else:
            self.persepolis_setting.setValue('column1', 'no')
            self.parent.download_table.setColumnHidden(1, True)

        if self.column2_checkBox.isChecked():
            self.persepolis_setting.setValue('column2', 'yes')
            self.parent.download_table.setColumnHidden(2, False)

            if self.parent.download_table.isColumnHidden(2):
                self.parent.download_table.setColumnWidth(2, 100)

        else:
            self.persepolis_setting.setValue('column2', 'no')
            self.parent.download_table.setColumnHidden(2, True)

        if self.column3_checkBox.isChecked():
            self.persepolis_setting.setValue('column3', 'yes')
            self.parent.download_table.setColumnHidden(3, False)

            if self.parent.download_table.isColumnHidden(3):
                self.parent.download_table.setColumnWidth(3, 100)

        else:
            self.persepolis_setting.setValue('column3', 'no')
            self.parent.download_table.setColumnHidden(3, True)

        if self.column4_checkBox.isChecked():
            self.persepolis_setting.setValue('column4', 'yes')
            self.parent.download_table.setColumnHidden(4, False)

            if self.parent.download_table.isColumnHidden(4):
                self.parent.download_table.setColumnWidth(4, 100)

        else:
            self.persepolis_setting.setValue('column4', 'no')
            self.parent.download_table.setColumnHidden(4, True)

        if self.column5_checkBox.isChecked():
            self.persepolis_setting.setValue('column5', 'yes')
            self.parent.download_table.setColumnHidden(5, False)

            if self.parent.download_table.isColumnHidden(5):
                self.parent.download_table.setColumnWidth(5, 100)

        else:
            self.persepolis_setting.setValue('column5', 'no')
            self.parent.download_table.setColumnHidden(5, True)

        if self.column6_checkBox.isChecked():
            self.persepolis_setting.setValue('column6', 'yes')
            self.parent.download_table.setColumnHidden(6, False)

            if self.parent.download_table.isColumnHidden(6):
                self.parent.download_table.setColumnWidth(6, 100)

        else:
            self.persepolis_setting.setValue('column6', 'no')
            self.parent.download_table.setColumnHidden(6, True)

        if self.column7_checkBox.isChecked():
            self.persepolis_setting.setValue('column7', 'yes')
            self.parent.download_table.setColumnHidden(7, False)

            if self.parent.download_table.isColumnHidden(7):
                self.parent.download_table.setColumnWidth(7, 100)

        else:
            self.persepolis_setting.setValue('column7', 'no')
            self.parent.download_table.setColumnHidden(7, True)

        if self.column10_checkBox.isChecked():
            self.persepolis_setting.setValue('column10', 'yes')
            self.parent.download_table.setColumnHidden(10, False)

            if self.parent.download_table.isColumnHidden(10):
                self.parent.download_table.setColumnWidth(10, 100)

        else:
            self.persepolis_setting.setValue('column10', 'no')
            self.parent.download_table.setColumnHidden(10, True)

        if self.column11_checkBox.isChecked():
            self.persepolis_setting.setValue('column11', 'yes')
            self.parent.download_table.setColumnHidden(11, False)

            if self.parent.download_table.isColumnHidden(11):
                self.parent.download_table.setColumnWidth(11, 100)

        else:
            self.persepolis_setting.setValue('column11', 'no')
            self.parent.download_table.setColumnHidden(11, True)

        if self.column12_checkBox.isChecked():
            self.persepolis_setting.setValue('column12', 'yes')
            self.parent.download_table.setColumnHidden(12, False)

            if self.parent.download_table.isColumnHidden(12):
                self.parent.download_table.setColumnWidth(12, 100)

        else:
            self.persepolis_setting.setValue('column12', 'no')
            self.parent.download_table.setColumnHidden(12, True)

        restart_messageBox = QMessageBox()
        restart_messageBox.setText(
            '<b>Some changes take effect after restarting persepolis</b>')
        restart_messageBox.setWindowTitle('Restart Persepolis!')
        restart_messageBox.exec_()

        # applying changes
        self.persepolis_setting.endGroup()
        self.persepolis_setting.sync()
        self.close()
    def chromiumPressed(self, browser):

        if os_type == 'Linux':
            exec_path = '/usr/bin/persepolis'

            if browser == 'chromium':
                native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/.config/google-chrome/NativeMessagingHosts'

        elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
            exec_path = '/usr/local/bin/persepolis'

            if browser == 'chromium':
                native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/.config/google-chrome/NativeMessagingHosts'

        elif os_type == 'Darwin':
            cwd = sys.argv[0]
            current_directory = os.path.dirname(cwd)

            exec_path = os.path.join(
                current_directory, 'Persepolis Download Manager')

            if browser == 'chromium':
                native_message_folder = home_address + \
                    '/Library/Application Support/Chromium/NativeMessagingHosts'
            elif browser == 'chrome':
                native_message_folder = home_address + \
                    '/Library/Application Support/Google/Chrome/NativeMessagingHosts'

        elif os_type == 'Windows':

            cwd = sys.argv[0]
            current_directory = os.path.dirname(cwd)

            exec_path = os.path.join(
                current_directory, 'Persepolis Download Manager.exe')

            # the execution path in jason file for Windows must in form of
            # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2
            # "\" in address
            exec_path = exec_path.replace('\\', r'\\')

            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager')

        json_file_lines = ['{', '    "name": "com.persepolis.pdmchromewrapper",', '    "description": "Integrate Persepolis with Google Chrome",', '    "path": "' +
                           str(exec_path) + '",', '    "type": "stdio",', '    "allowed_origins": [', '        "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/"', '    ]', '}']

        native_message_file = os.path.join(
            native_message_folder, 'com.persepolis.pdmchromewrapper.json')

        osCommands.makeDirs(native_message_folder)

        f = Open(native_message_file, 'w')
        for i in json_file_lines:
            f.writelines(str(i) + '\n')
        f.close()

        if os_type != 'Windows':
            os.system('chmod +x "' + str(native_message_file) + '"')
        else:
            CREATE_NO_WINDOW = 0x08000000
#             subprocess.Popen(['REG','ADD','"HKCU\\Software\\Google\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper.json"', '/ve' , '/t' , 'REG_SZ' ,'/d' , '"' + str(exec_path) + '"' , '/f'] , shell = False ,creationflags = CREATE_NO_WINDOW )
            os.system(r'REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.persepolis.pdmchromewrapper" /ve /t REG_SZ /d "' +
                      native_message_file + '" /f')

        if browser == 'chromium':
            self.chromium_label.setText('Done!')
        elif browser == 'chrome':
            self.chrome_label.setText('Done!')
Ejemplo n.º 5
0
def browserIntegration(browser):
    # for GNU/Linux
    if os_type == 'Linux':
        # persepolis execution path
        exec_path = '/usr/bin/persepolis'

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'

    # for FreeBSD and OpenBSD
    elif os_type == 'FreeBSD' or os_type == 'OpenBSD':
        # persepolis execution path
        exec_path = '/usr/local/bin/persepolis'

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + '/.config/chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/.config/google-chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/.mozilla/native-messaging-hosts'
        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/.config/vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/.config/opera/NativeMessagingHosts'



    # for Mac OSX
    elif os_type == 'Darwin':
        # finding Persepolis execution path
        cwd = sys.argv[0]
        current_directory = os.path.dirname(cwd)

        exec_path = os.path.join(
            current_directory, 'Persepolis Download Manager')

        # Native Messaging Hosts folder path for every browser
        if browser == 'chromium':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Chromium/NativeMessagingHosts'

        elif browser == 'chrome':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Google/Chrome/NativeMessagingHosts'

        elif browser == 'firefox':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Mozilla/NativeMessagingHosts'

        elif browser == 'vivaldi':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Vivaldi/NativeMessagingHosts'

        elif browser == 'opera':
            native_message_folder = home_address + \
                                    '/Library/Application Support/Opera/NativeMessagingHosts/'

    # for MicroSoft Windows os (windows 7 , ...)
    elif os_type == 'Windows':
        # finding Persepolis execution path
        cwd = sys.argv[0]
        current_directory = os.path.dirname(cwd)

        exec_path = os.path.join(
            current_directory, 'Persepolis Download Manager.exe')

        # the execution path in jason file for Windows must in form of
        # c:\\Users\\...\\Persepolis Download Manager.exe , so we need 2
        # "\" in address
        exec_path = exec_path.replace('\\', r'\\')

        if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager', 'chrome')
        else:
            native_message_folder = os.path.join(
                home_address, 'AppData\Local\persepolis_download_manager', 'firefox')
 

    # WebExtension native hosts file prototype
    webextension_json_connector = {
        "name": "com.persepolis.pdmchromewrapper",
        "type": "stdio",
        "path": str(exec_path),
        "description": "Integrate Persepolis with %s using WebExtensions" % (browser)
    }

    # Add chrom* keys
    if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
        webextension_json_connector["allowed_origins"] = [ "chrome-extension://legimlagjjoghkoedakdjhocbeomojao/" ]

    # Add firefox keys
    elif browser == 'firefox':
        webextension_json_connector["allowed_extensions"] = [
            "*****@*****.**",
            "*****@*****.**"
        ]

    # Build final path
    native_message_file = os.path.join(
        native_message_folder, 'com.persepolis.pdmchromewrapper.json')

    osCommands.makeDirs(native_message_folder)

    # Write NMH file
    f = open(native_message_file, 'w')
    f.write(str(webextension_json_connector).replace("'", "\""))
    f.close()

    if os_type != 'Windows':
        os.system('chmod +x "' + str(native_message_file) + '"')

    else:
        import winreg
        # add the key to the windows registry
        if browser == 'chrome' or browser == 'chromium' or browser == 'opera' or browser == 'vivaldi':
            try:
                # create pdmchromewrapper key under NativeMessagingHosts
                winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper")
                # open a connection to pdmchromewrapper key
                gintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(gintKey, '', 0,winreg.REG_SZ, native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(gintKey)
                return True
            except WindowsError:
                return False
        elif browser == 'firefox':
            try:
                # create pdmchromewrapper key under NativeMessagingHosts for firefox
                winreg.CreateKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper")
                # open a connection to pdmchromewrapper key for firefox
                fintKey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.persepolis.pdmchromewrapper", 0, winreg.KEY_ALL_ACCESS)
                # set native_message_file as key value
                winreg.SetValueEx(fintKey, '', 0,winreg.REG_SZ, native_message_file)
                # close connection to pdmchromewrapper
                winreg.CloseKey(fintKey)
                return True
            except WindowsError:
                return False